From: Carlos Lopez Date: Sun, 28 Nov 2010 11:25:22 +0000 (+0100) Subject: Prevent unsafe thread change of local settings using synfig::ChangeLocale class X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=477fd4ea9c6133e098572554a9eadbf503e27fab;p=synfig.git Prevent unsafe thread change of local settings using synfig::ChangeLocale class --- diff --git a/synfig-studio/src/gui/app.cpp b/synfig-studio/src/gui/app.cpp index 076b49e..0f8d3bd 100644 --- a/synfig-studio/src/gui/app.cpp +++ b/synfig-studio/src/gui/app.cpp @@ -500,7 +500,7 @@ public: { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); if(key=="gamma") { value=strprintf("%f %f %f %f", @@ -588,7 +588,6 @@ public: value=strprintf("%s",App::predefined_fps.c_str()); return true; } - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -601,7 +600,7 @@ public: { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); if(key=="gamma") { float r,g,b,blk; @@ -704,7 +703,6 @@ public: App::predefined_fps=value; return true; } - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -1618,7 +1616,7 @@ App::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); { std::string filename=get_config_file("accelrc"); Gtk::AccelMap::save(filename); @@ -1658,7 +1656,7 @@ App::save_settings() }while(0); std::string filename=get_config_file("settings"); synfigapp::Main::settings().save_to_file(filename); - SETTINGS_LOCALE_RESTORE + } catch(...) { @@ -1671,7 +1669,7 @@ App::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); { std::string filename=get_config_file("accelrc"); Gtk::AccelMap::load(filename); @@ -1727,7 +1725,7 @@ App::load_settings() reset_initial_window_configuration(); } } - SETTINGS_LOCALE_RESTORE + } catch(...) { diff --git a/synfig-studio/src/gui/states/state_bline.cpp b/synfig-studio/src/gui/states/state_bline.cpp index 9d0a10c..935e682 100644 --- a/synfig-studio/src/gui/states/state_bline.cpp +++ b/synfig-studio/src/gui/states/state_bline.cpp @@ -238,7 +238,7 @@ StateBLine_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; if(settings.get_value("bline.layer_region",value) && value=="0") @@ -281,9 +281,7 @@ StateBLine_Context::load_settings() Real n = atof(value.c_str()); set_feather(n); } - sanity_check(); - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -296,7 +294,7 @@ StateBLine_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); sanity_check(); settings.set_value("bline.layer_outline",get_layer_outline_flag()?"1":"0"); settings.set_value("bline.layer_region",get_layer_region_flag()?"1":"0"); @@ -306,7 +304,6 @@ StateBLine_Context::save_settings() settings.set_value("bline.auto_export",get_auto_export_flag()?"1":"0"); settings.set_value("bline.id",get_id().c_str()); settings.set_value("bline.feather",strprintf("%f",get_feather())); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_circle.cpp b/synfig-studio/src/gui/states/state_circle.cpp index ff9e2ca..6e81a6b 100644 --- a/synfig-studio/src/gui/states/state_circle.cpp +++ b/synfig-studio/src/gui/states/state_circle.cpp @@ -241,7 +241,7 @@ StateCircle_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; //parse the arguments yargh! @@ -316,7 +316,6 @@ StateCircle_Context::load_settings() set_layer_origins_at_center_flag(false); else set_layer_origins_at_center_flag(true); - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -329,7 +328,7 @@ StateCircle_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("circle.id",get_id()); settings.set_value("circle.fallofftype",strprintf("%d",get_falloff())); #ifdef BLEND_METHOD_IN_TOOL_OPTIONS @@ -346,7 +345,6 @@ StateCircle_Context::save_settings() settings.set_value("circle.layer_plant",get_layer_plant_flag()?"1":"0"); settings.set_value("circle.layer_link_origins",get_layer_link_origins_flag()?"1":"0"); settings.set_value("circle.layer_origins_at_center",get_layer_origins_at_center_flag()?"1":"0"); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_draw.cpp b/synfig-studio/src/gui/states/state_draw.cpp index 0a3b101..1a793f2 100644 --- a/synfig-studio/src/gui/states/state_draw.cpp +++ b/synfig-studio/src/gui/states/state_draw.cpp @@ -259,7 +259,7 @@ StateDraw_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; if(settings.get_value("draw.id",value)) @@ -337,7 +337,6 @@ StateDraw_Context::load_settings() set_local_error_flag(true); else set_local_error_flag(false); - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -350,7 +349,7 @@ StateDraw_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("draw.id",get_id().c_str()); settings.set_value("draw.pressure_width",get_pressure_width_flag()?"1":"0"); settings.set_value("draw.auto_loop",get_auto_loop_flag()?"1":"0"); @@ -365,7 +364,6 @@ StateDraw_Context::save_settings() settings.set_value("draw.gthreshold",strprintf("%f",get_gthres())); settings.set_value("draw.lthreshold",strprintf("%f",get_lthres())); settings.set_value("draw.localize",get_local_error_flag()?"1":"0"); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_gradient.cpp b/synfig-studio/src/gui/states/state_gradient.cpp index 4b0250e..c8dd5cd 100644 --- a/synfig-studio/src/gui/states/state_gradient.cpp +++ b/synfig-studio/src/gui/states/state_gradient.cpp @@ -176,7 +176,7 @@ StateGradient_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; if(settings.get_value("gradient.id",value)) @@ -195,7 +195,6 @@ StateGradient_Context::load_settings() else set_blend(Color::BLEND_COMPOSITE); #endif // BLEND_METHOD_IN_TOOL_OPTIONS - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -208,13 +207,12 @@ StateGradient_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("gradient.id",get_id().c_str()); settings.set_value("gradient.type",strprintf("%d",get_type())); #ifdef BLEND_METHOD_IN_TOOL_OPTIONS settings.set_value("gradient.blend",strprintf("%d",get_blend())); #endif // BLEND_METHOD_IN_TOOL_OPTIONS - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_polygon.cpp b/synfig-studio/src/gui/states/state_polygon.cpp index b721e10..4f48e33 100644 --- a/synfig-studio/src/gui/states/state_polygon.cpp +++ b/synfig-studio/src/gui/states/state_polygon.cpp @@ -201,7 +201,7 @@ StatePolygon_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; if(settings.get_value("polygon.id",value)) @@ -249,7 +249,6 @@ StatePolygon_Context::load_settings() Real n = atof(value.c_str()); set_feather(n); } - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -262,7 +261,7 @@ StatePolygon_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("polygon.id",get_id().c_str()); settings.set_value("polygon.invert",get_invert()?"1":"0"); settings.set_value("polygon.layer_polygon",get_layer_polygon_flag()?"1":"0"); @@ -272,7 +271,6 @@ StatePolygon_Context::save_settings() settings.set_value("polygon.layer_plant",get_layer_plant_flag()?"1":"0"); settings.set_value("polygon.layer_link_origins",get_layer_link_origins_flag()?"1":"0"); settings.set_value("polygon.feather",strprintf("%f",get_feather())); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_rectangle.cpp b/synfig-studio/src/gui/states/state_rectangle.cpp index 5858cc0..6160199 100644 --- a/synfig-studio/src/gui/states/state_rectangle.cpp +++ b/synfig-studio/src/gui/states/state_rectangle.cpp @@ -209,7 +209,7 @@ StateRectangle_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; //parse the arguments yargh! @@ -262,7 +262,6 @@ StateRectangle_Context::load_settings() set_layer_link_origins_flag(false); else set_layer_link_origins_flag(true); - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -275,7 +274,7 @@ StateRectangle_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("rectangle.id",get_id().c_str()); settings.set_value("rectangle.expand",strprintf("%f",get_expand())); settings.set_value("rectangle.feather",strprintf("%f",(float)get_feather())); @@ -286,7 +285,6 @@ StateRectangle_Context::save_settings() settings.set_value("rectangle.layer_curve_gradient",get_layer_curve_gradient_flag()?"1":"0"); settings.set_value("rectangle.layer_plant",get_layer_plant_flag()?"1":"0"); settings.set_value("rectangle.layer_link_origins",get_layer_link_origins_flag()?"1":"0"); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_rotate.cpp b/synfig-studio/src/gui/states/state_rotate.cpp index e582835..074a758 100644 --- a/synfig-studio/src/gui/states/state_rotate.cpp +++ b/synfig-studio/src/gui/states/state_rotate.cpp @@ -160,14 +160,13 @@ StateRotate_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; if(settings.get_value("rotate.scale",value) && value=="0") set_scale_flag(false); else set_scale_flag(true); - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -180,9 +179,8 @@ StateRotate_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("rotate.scale",get_scale_flag()?"1":"0"); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_scale.cpp b/synfig-studio/src/gui/states/state_scale.cpp index 5b723fc..7ec874f 100644 --- a/synfig-studio/src/gui/states/state_scale.cpp +++ b/synfig-studio/src/gui/states/state_scale.cpp @@ -149,14 +149,13 @@ StateScale_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; if(settings.get_value("scale.lock_aspect",value) && value=="0") set_aspect_lock_flag(false); else set_aspect_lock_flag(true); - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -169,9 +168,8 @@ StateScale_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("scale.lock_aspect",get_aspect_lock_flag()?"1":"0"); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_smoothmove.cpp b/synfig-studio/src/gui/states/state_smoothmove.cpp index 3b4f36c..36bfecd 100644 --- a/synfig-studio/src/gui/states/state_smoothmove.cpp +++ b/synfig-studio/src/gui/states/state_smoothmove.cpp @@ -157,14 +157,13 @@ StateSmoothMove_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; if(settings.get_value("smooth_move.radius",value)) set_radius(atof(value.c_str())); else set_radius(1.0f); - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -177,9 +176,8 @@ StateSmoothMove_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("smooth_move.radius",strprintf("%f",get_radius())); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_star.cpp b/synfig-studio/src/gui/states/state_star.cpp index 6033baf..ec5ae50 100644 --- a/synfig-studio/src/gui/states/state_star.cpp +++ b/synfig-studio/src/gui/states/state_star.cpp @@ -248,7 +248,7 @@ StateStar_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; //parse the arguments yargh! @@ -341,7 +341,6 @@ StateStar_Context::load_settings() set_layer_origins_at_center_flag(false); else set_layer_origins_at_center_flag(true); - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -354,7 +353,7 @@ StateStar_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("star.id",get_id()); settings.set_value("star.feather",strprintf("%f",(float)get_feather())); settings.set_value("star.number_of_points",strprintf("%d",(int)(get_number_of_points() + 0.5))); @@ -373,7 +372,6 @@ StateStar_Context::save_settings() settings.set_value("star.layer_plant",get_layer_plant_flag()?"1":"0"); settings.set_value("star.layer_link_origins",get_layer_link_origins_flag()?"1":"0"); settings.set_value("star.layer_origins_at_center",get_layer_origins_at_center_flag()?"1":"0"); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_text.cpp b/synfig-studio/src/gui/states/state_text.cpp index 6a752d2..c5ac2b6 100644 --- a/synfig-studio/src/gui/states/state_text.cpp +++ b/synfig-studio/src/gui/states/state_text.cpp @@ -165,7 +165,7 @@ StateText_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; Vector v; @@ -204,7 +204,6 @@ StateText_Context::load_settings() set_family(value); else set_family("Sans Serif"); - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -217,7 +216,7 @@ StateText_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("text.id",get_id()); settings.set_value("text.paragraph",get_paragraph_flag()?"1":"0"); settings.set_value("text.size_x",strprintf("%f",(float)get_size()[0])); @@ -225,7 +224,6 @@ StateText_Context::save_settings() settings.set_value("text.orient_x",strprintf("%f",(float)get_orientation()[0])); settings.set_value("text.orient_y",strprintf("%f",(float)get_orientation()[1])); settings.set_value("text.family",get_family()); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/gui/states/state_width.cpp b/synfig-studio/src/gui/states/state_width.cpp index 6e212ea..4226f7f 100644 --- a/synfig-studio/src/gui/states/state_width.cpp +++ b/synfig-studio/src/gui/states/state_width.cpp @@ -175,7 +175,7 @@ StateWidth_Context::load_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); String value; //parse the arguments yargh! @@ -194,7 +194,6 @@ StateWidth_Context::load_settings() set_relative(true); else set_relative(false); - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -207,11 +206,10 @@ StateWidth_Context::save_settings() { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); settings.set_value("width.delta",strprintf("%f",get_delta())); settings.set_value("width.radius",strprintf("%f",get_radius())); settings.set_value("width.relative",get_relative()?"1":"0"); - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/synfigapp/inputdevice.cpp b/synfig-studio/src/synfigapp/inputdevice.cpp index aea4e62..1e10d15 100644 --- a/synfig-studio/src/synfigapp/inputdevice.cpp +++ b/synfig-studio/src/synfigapp/inputdevice.cpp @@ -62,7 +62,7 @@ public: { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); if(key=="state") { value=input_device->get_state(); @@ -112,7 +112,6 @@ public: get_keys_value(value); return true; } - SETTINGS_LOCALE_RESTORE } catch(...) { @@ -153,7 +152,7 @@ public: { try { - SETTINGS_LOCALE_SAFE_AND_BACKUP + synfig::ChangeLocale change_locale(LC_NUMERIC, "C"); if(key=="state") { input_device->set_state(value); @@ -205,7 +204,6 @@ public: set_keys_value(value); return true; } - SETTINGS_LOCALE_RESTORE } catch(...) { diff --git a/synfig-studio/src/synfigapp/settings.h b/synfig-studio/src/synfigapp/settings.h index 1bf9227..e48f125 100644 --- a/synfig-studio/src/synfigapp/settings.h +++ b/synfig-studio/src/synfigapp/settings.h @@ -35,14 +35,6 @@ /* === M A C R O S ========================================================= */ -#define SETTINGS_LOCALE_SAFE_AND_BACKUP \ - char * old_locale; \ - old_locale=strdup(setlocale(LC_NUMERIC, NULL)); \ - setlocale(LC_NUMERIC, "C"); - -#define SETTINGS_LOCALE_RESTORE \ - setlocale(LC_NUMERIC,old_locale); - /* === T Y P E D E F S ===================================================== */ /* === C L A S S E S & S T R U C T S ======================================= */