Not sure if it went through the first time, so just gonna send this again.
diff --git a/mypaint-brush.c b/mypaint-brush.c
index 3354280..48ffe77 100644
--- a/mypaint-brush.c
+++ b/mypaint-brush.c
@@ -91,9 +91,6 @@ struct _MyPaintBrush {
float speed_mapping_q[2];
gboolean reset_requested;
-#ifdef HAVE_JSON_C
- json_object *brush_json;
-#endif
int refcount;
};
@@ -130,10 +127,6 @@ mypaint_brush_new(void)
self->reset_requested = TRUE;
-#ifdef HAVE_JSON_C
- self->brush_json = json_object_new_object();
-#endif
-
return self;
}
@@ -146,10 +139,6 @@ brush_free(MyPaintBrush *self)
rng_double_free (self->rng);
self->rng = NULL;
-#ifdef HAVE_JSON_C
- json_object_put(self->brush_json);
-#endif
-
free(self);
}
@@ -1078,20 +1067,24 @@ smallest_angular_difference(float a, float b)
return FALSE;
}
-#ifdef HAVE_JSON_C
+
gboolean
-update_settings_from_json_object(MyPaintBrush *self)
+mypaint_brush_from_string(MyPaintBrush *self, const char *string)
{
+#ifdef HAVE_JSON_C
+ json_object *brush_json = json_tokener_parse(string);
+
// Check version
- json_object *version_object = json_object_object_get(self->brush_json, "version");
+ json_object *version_object = json_object_object_get(brush_json, "version");
const int version = json_object_get_int(version_object);
if (version != 3) {
fprintf(stderr, "Error: Unsupported brush setting version: %d\n", version);
+ json_object_put(brush_json);
return FALSE;
}
// Set settings
- json_object *settings = json_object_object_get(self->brush_json, "settings");
+ json_object *settings = json_object_object_get(brush_json, "settings");
json_object_object_foreach(settings, setting_name, setting_obj) {
@@ -1099,6 +1092,7 @@ update_settings_from_json_object(MyPaintBrush *self)
if (!json_object_is_type(setting_obj, json_type_object)) {
fprintf(stderr, "Error: Wrong type for setting: %s\n", setting_name);
+ json_object_put(brush_json);
return FALSE;
}
@@ -1114,6 +1108,7 @@ update_settings_from_json_object(MyPaintBrush *self)
if (!json_object_is_type(input_obj, json_type_array)) {
fprintf(stderr, "Error: Wrong inputs type for setting: %s\n", setting_name);
+ json_object_put(brush_json);
return FALSE;
}
@@ -1134,20 +1129,9 @@ update_settings_from_json_object(MyPaintBrush *self)
}
}
- return TRUE;
-}
-#endif // HAVE_JSON_C
-gboolean
-mypaint_brush_from_string(MyPaintBrush *self, const char *string)
-{
-#ifdef HAVE_JSON_C
- if (self->brush_json) {
- // Free
- json_object_put(self->brush_json);
- }
- self->brush_json = json_tokener_parse(string);
- return update_settings_from_json_object(self);
+ json_object_put(brush_json);
+ return TRUE;
#else
return FALSE;
#endif
_______________________________________________
Mypaint-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/mypaint-discuss