summaryrefslogtreecommitdiff
path: root/src/glibext
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2021-01-01 23:20:42 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2021-01-01 23:20:42 (GMT)
commitdcd5e0b104143b110997029aa0728731f4087ad8 (patch)
tree141a79ade5eae6e469ba9e5255882039e9c29a3e /src/glibext
parent7b320516abf871eefe009ff6fe4fb86ed921fed9 (diff)
Managed GObject references each time a configuration parameter is accessed.
Diffstat (limited to 'src/glibext')
-rw-r--r--src/glibext/configuration.c78
-rw-r--r--src/glibext/configuration.h44
2 files changed, 85 insertions, 37 deletions
diff --git a/src/glibext/configuration.c b/src/glibext/configuration.c
index b4eb784..5bc94a7 100644
--- a/src/glibext/configuration.c
+++ b/src/glibext/configuration.c
@@ -942,7 +942,7 @@ void g_config_param_set_value(GCfgParam *param, ...)
* *
******************************************************************************/
-void g_config_param_get_value(GCfgParam *param, ...)
+void g_config_param_get_value(const GCfgParam *param, ...)
{
va_list ap; /* Liste d'arguments */
@@ -1135,6 +1135,7 @@ static void g_config_group_load(GCfgGroup *group, GGenConfig *config, xmlXPathCo
param = g_config_param_new_empty(key, group->type);
_g_generic_config_add_param(config, param, false);
+ g_object_unref(G_OBJECT(param));
free(key);
@@ -1358,7 +1359,11 @@ void g_generic_config_build(GGenConfig *config, const char *name)
const char *g_generic_config_get_filename(const GGenConfig *config)
{
- return config->filename;
+ char *result; /* Chemin à retourner */
+
+ result = config->filename;
+
+ return result;
}
@@ -1463,24 +1468,33 @@ bool g_generic_config_write(GGenConfig *config)
xmlXPathContextPtr context; /* Contexte de recherche XPath */
GList *iter; /* Boucle de parcours */
- if (!create_new_xml_file(&xdoc, &context))
- return false;
-
- g_generic_config_rlock(config);
+ if (config->filename == NULL)
+ result = false;
- for (result = true, iter = g_list_first(config->params);
- result && iter != NULL;
- iter = g_list_next(iter))
+ else
{
- result = g_config_param_write(G_CFG_PARAM(iter->data), xdoc, context);
- }
+ result = create_new_xml_file(&xdoc, &context);
+ if (!result) goto exit;
- g_generic_config_runlock(config);
+ g_generic_config_rlock(config);
- if (result)
- result = save_xml_file(xdoc, config->filename);
+ for (iter = g_list_first(config->params);
+ result && iter != NULL;
+ iter = g_list_next(iter))
+ {
+ result = g_config_param_write(G_CFG_PARAM(iter->data), xdoc, context);
+ }
- close_xml_file(xdoc, context);
+ g_generic_config_runlock(config);
+
+ if (result)
+ result = save_xml_file(xdoc, config->filename);
+
+ close_xml_file(xdoc, context);
+
+ }
+
+ exit:
return result;
@@ -1504,6 +1518,8 @@ void g_generic_config_add_group(GGenConfig *config, GCfgGroup *group)
{
g_generic_config_wlock(config);
+ g_object_ref(G_OBJECT(group));
+
config->groups = g_list_append(config->groups, group);
g_generic_config_wunlock(config);
@@ -1527,6 +1543,7 @@ void g_generic_config_add_group(GGenConfig *config, GCfgGroup *group)
GCfgParam *_g_generic_config_search(GGenConfig *config, const char *path, bool lock)
{
+ GCfgParam *result; /* Instance à retourner */
GList *item; /* Elément générique de liste */
GCfgParam fake; /* Faux élément partiel */
@@ -1538,10 +1555,15 @@ GCfgParam *_g_generic_config_search(GGenConfig *config, const char *path, bool l
item = g_list_find_custom(config->params, &fake, (GCompareFunc)g_config_param_compare);
+ result = item ? item->data : NULL;
+
+ if (result != NULL)
+ g_object_ref(G_OBJECT(result));
+
if (lock)
g_generic_config_runlock(config);
- return item ? item->data : NULL;
+ return result;
}
@@ -1554,14 +1576,15 @@ GCfgParam *_g_generic_config_search(GGenConfig *config, const char *path, bool l
* *
* Description : Ajoute un paramètre à une configuration. *
* *
-* Retour : Elément mis en place ou NULL en cas d'erreur. *
+* Retour : Validation de l'ajout : true ou false. *
* *
* Remarques : - *
* *
******************************************************************************/
-GCfgParam *_g_generic_config_add_param(GGenConfig *config, GCfgParam *param, bool lock)
+bool _g_generic_config_add_param(GGenConfig *config, GCfgParam *param, bool lock)
{
+ bool result; /* Bilan à retourner */
const char *path; /* Chemin d'accès unique */
GCfgParam *old; /* Test de présence */
@@ -1573,20 +1596,25 @@ GCfgParam *_g_generic_config_add_param(GGenConfig *config, GCfgParam *param, boo
old = _g_generic_config_search(config, path, false);
if (old != NULL)
{
- g_clear_object(&param);
+ g_object_unref(G_OBJECT(old));
+ result = false;
goto exit;
}
+ g_object_ref(G_OBJECT(param));
+
config->params = g_list_append(config->params, param);
g_signal_connect(param, "modified", G_CALLBACK(on_config_param_modified), config);
+ result = true;
+
exit:
if (lock)
g_generic_config_wunlock(config);
- return param;
+ return result;
}
@@ -1632,12 +1660,16 @@ void g_generic_config_delete_param(GGenConfig *config, const char *path)
old = _g_generic_config_search(config, path, false);
- g_signal_handlers_disconnect_by_func(old, G_CALLBACK(on_config_param_modified), config);
-
if (old != NULL)
+ {
+ g_signal_handlers_disconnect_by_func(old, G_CALLBACK(on_config_param_modified), config);
+
config->params = g_list_remove(config->params, old);
- g_object_unref(G_OBJECT(old));
+ g_object_unref(G_OBJECT(old));
+ g_object_unref(G_OBJECT(old));
+
+ }
g_generic_config_wunlock(config);
diff --git a/src/glibext/configuration.h b/src/glibext/configuration.h
index afefed1..aac6dc7 100644
--- a/src/glibext/configuration.h
+++ b/src/glibext/configuration.h
@@ -105,7 +105,7 @@ void g_config_param_reset(GCfgParam *);
void g_config_param_set_value(GCfgParam *, ...);
/* Indique la valeur courante d'un paramètre de configuration. */
-void g_config_param_get_value(GCfgParam *, ...);
+void g_config_param_get_value(const GCfgParam *, ...);
@@ -191,6 +191,7 @@ void g_generic_config_add_group(GGenConfig *, GCfgGroup *);
GCfgGroup *__group; \
__group = g_config_group_new(p, t); \
g_generic_config_add_group(c, __group); \
+ g_object_unref(G_OBJECT(__group)); \
})
@@ -205,7 +206,10 @@ GCfgParam *_g_generic_config_search(GGenConfig *, const char *, bool);
GCfgParam *__param; \
__param = g_generic_config_search(c, p); \
if (__param != NULL) \
+ { \
g_config_param_set_value(__param, v); \
+ g_object_unref(G_OBJECT(__param)); \
+ } \
__param != NULL ? true : false; \
})
@@ -214,51 +218,63 @@ GCfgParam *_g_generic_config_search(GGenConfig *, const char *, bool);
GCfgParam *__param; \
__param = g_generic_config_search(c, p); \
if (__param != NULL) \
+ { \
g_config_param_get_value(__param, v); \
+ g_object_unref(G_OBJECT(__param)); \
+ } \
__param != NULL ? true : false; \
})
/* Ajoute un paramètre à une configuration. */
-GCfgParam *_g_generic_config_add_param(GGenConfig *, GCfgParam *, bool);
+bool _g_generic_config_add_param(GGenConfig *, GCfgParam *, bool);
#define g_generic_config_add_param(c, p) _g_generic_config_add_param(c, p, true)
#define g_generic_config_create_param(c, p, t, d) \
({ \
- GCfgParam *__result; \
- __result = g_config_param_new(p, t, d); \
- __result = g_generic_config_add_param(c, __result); \
+ bool __result; \
+ GCfgParam *__param; \
+ __param = g_config_param_new(p, t, d); \
+ __result = g_generic_config_add_param(c, __param); \
+ g_object_unref(G_OBJECT(__param)); \
__result; \
})
#define g_generic_config_create_param_if_not_exist(c, p, t, d) \
({ \
- GCfgParam *__result; \
- __result = g_generic_config_search(c, p); \
- if (__result == NULL) \
+ bool __result; \
+ GCfgParam *__param; \
+ __param = g_generic_config_search(c, p); \
+ if (__param == NULL) \
{ \
- __result = g_config_param_new(p, t, d); \
- __result = g_generic_config_add_param(c, __result); \
+ __param = g_config_param_new(p, t, d); \
+ __result = g_generic_config_add_param(c, __param); \
} \
+ else \
+ __result = true; \
+ g_object_unref(G_OBJECT(__param)); \
__result; \
})
#define g_generic_config_create_or_udpdate_param(c, p, t, d, v) \
({ \
+ bool __result; \
GCfgParam *__param; \
__param = g_generic_config_search(c, p); \
if (__param == NULL) \
{ \
__param = g_config_param_new(p, t, d); \
- __param = g_generic_config_add_param(c, __param); \
+ __result = g_generic_config_add_param(c, __param); \
} \
- if (__param != NULL) \
- g_config_param_set_value(__param, v); \
- __param != NULL ? true : false; \
+ else \
+ __result = true; \
+ g_config_param_set_value(__param, v); \
+ g_object_unref(G_OBJECT(__param)); \
+ __result; \
})