[glib] unGObjectify GSettingsSchema
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] unGObjectify GSettingsSchema
- Date: Thu, 17 Nov 2011 14:04:04 +0000 (UTC)
commit 577faeae5bcdff8431c298c9275bf7703d8b6a22
Author: Ryan Lortie <desrt desrt ca>
Date: Sun Nov 13 21:38:31 2011 +0100
unGObjectify GSettingsSchema
gio/gsettings.c | 2 +-
gio/gsettingsschema.c | 82 ++++++++++++++++++++++---------------------------
gio/gsettingsschema.h | 34 +++-----------------
3 files changed, 43 insertions(+), 75 deletions(-)
---
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 4f6b2f4..95a5c1a 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -533,7 +533,7 @@ g_settings_finalize (GObject *object)
settings->priv->path);
g_main_context_unref (settings->priv->main_context);
g_object_unref (settings->priv->backend);
- g_object_unref (settings->priv->schema);
+ g_settings_schema_unref (settings->priv->schema);
g_free (settings->priv->schema_name);
g_free (settings->priv->path);
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index bf3243b..9c79482 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -26,9 +26,7 @@
#include <glibintl.h>
-G_DEFINE_TYPE (GSettingsSchema, g_settings_schema, G_TYPE_OBJECT)
-
-struct _GSettingsSchemaPrivate
+struct _GSettingsSchema
{
const gchar *gettext_domain;
const gchar *path;
@@ -36,6 +34,8 @@ struct _GSettingsSchemaPrivate
gint n_items;
GvdbTable *table;
gchar *name;
+
+ gint ref_count;
};
static GSList *schema_sources;
@@ -216,34 +216,25 @@ g_settings_list_relocatable_schemas (void)
return relocatable_schema_list;
}
-static void
-g_settings_schema_finalize (GObject *object)
+GSettingsSchema *
+g_settings_schema_ref (GSettingsSchema *schema)
{
- GSettingsSchema *schema = G_SETTINGS_SCHEMA (object);
-
- gvdb_table_unref (schema->priv->table);
- g_free (schema->priv->items);
- g_free (schema->priv->name);
-
- G_OBJECT_CLASS (g_settings_schema_parent_class)
- ->finalize (object);
-}
+ g_atomic_int_inc (&schema->ref_count);
-static void
-g_settings_schema_init (GSettingsSchema *schema)
-{
- schema->priv = G_TYPE_INSTANCE_GET_PRIVATE (schema, G_TYPE_SETTINGS_SCHEMA,
- GSettingsSchemaPrivate);
+ return schema;
}
-static void
-g_settings_schema_class_init (GSettingsSchemaClass *class)
+void
+g_settings_schema_unref (GSettingsSchema *schema)
{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
-
- object_class->finalize = g_settings_schema_finalize;
+ if (g_atomic_int_dec_and_test (&schema->ref_count))
+ {
+ gvdb_table_unref (schema->table);
+ g_free (schema->items);
+ g_free (schema->name);
- g_type_class_add_private (class, sizeof (GSettingsSchemaPrivate));
+ g_slice_free (GSettingsSchema, schema);
+ }
}
const gchar *
@@ -253,7 +244,7 @@ g_settings_schema_get_string (GSettingsSchema *schema,
const gchar *result = NULL;
GVariant *value;
- if ((value = gvdb_table_get_raw_value (schema->priv->table, key)))
+ if ((value = gvdb_table_get_raw_value (schema->table, key)))
{
result = g_variant_get_string (value, NULL);
g_variant_unref (value);
@@ -284,16 +275,17 @@ g_settings_schema_new (const gchar *name)
if (table == NULL)
g_error ("Settings schema '%s' is not installed\n", name);
- schema = g_object_new (G_TYPE_SETTINGS_SCHEMA, NULL);
- schema->priv->name = g_strdup (name);
- schema->priv->table = table;
- schema->priv->path =
+ schema = g_slice_new0 (GSettingsSchema);
+ schema->ref_count = 1;
+ schema->name = g_strdup (name);
+ schema->table = table;
+ schema->path =
g_settings_schema_get_string (schema, ".path");
- schema->priv->gettext_domain =
+ schema->gettext_domain =
g_settings_schema_get_string (schema, ".gettext-domain");
- if (schema->priv->gettext_domain)
- bind_textdomain_codeset (schema->priv->gettext_domain, "UTF-8");
+ if (schema->gettext_domain)
+ bind_textdomain_codeset (schema->gettext_domain, "UTF-8");
return schema;
}
@@ -305,11 +297,11 @@ g_settings_schema_get_value (GSettingsSchema *schema,
GVariantIter *iter;
GVariant *value;
- value = gvdb_table_get_raw_value (schema->priv->table, key);
+ value = gvdb_table_get_raw_value (schema->table, key);
if G_UNLIKELY (value == NULL)
g_error ("Settings schema '%s' does not contain a key named '%s'",
- schema->priv->name, key);
+ schema->name, key);
iter = g_variant_iter_new (value);
g_variant_unref (value);
@@ -320,20 +312,20 @@ g_settings_schema_get_value (GSettingsSchema *schema,
const gchar *
g_settings_schema_get_path (GSettingsSchema *schema)
{
- return schema->priv->path;
+ return schema->path;
}
const gchar *
g_settings_schema_get_gettext_domain (GSettingsSchema *schema)
{
- return schema->priv->gettext_domain;
+ return schema->gettext_domain;
}
gboolean
g_settings_schema_has_key (GSettingsSchema *schema,
const gchar *key)
{
- return gvdb_table_has_value (schema->priv->table, key);
+ return gvdb_table_has_value (schema->table, key);
}
const GQuark *
@@ -342,25 +334,25 @@ g_settings_schema_list (GSettingsSchema *schema,
{
gint i, j;
- if (schema->priv->items == NULL)
+ if (schema->items == NULL)
{
gchar **list;
gint len;
- list = gvdb_table_list (schema->priv->table, "");
+ list = gvdb_table_list (schema->table, "");
len = list ? g_strv_length (list) : 0;
- schema->priv->items = g_new (GQuark, len);
+ schema->items = g_new (GQuark, len);
j = 0;
for (i = 0; i < len; i++)
if (list[i][0] != '.')
- schema->priv->items[j++] = g_quark_from_string (list[i]);
- schema->priv->n_items = j;
+ schema->items[j++] = g_quark_from_string (list[i]);
+ schema->n_items = j;
g_strfreev (list);
}
- *n_items = schema->priv->n_items;
- return schema->priv->items;
+ *n_items = schema->n_items;
+ return schema->items;
}
diff --git a/gio/gsettingsschema.h b/gio/gsettingsschema.h
index 31ba1f4..af0f8bd 100644
--- a/gio/gsettingsschema.h
+++ b/gio/gsettingsschema.h
@@ -20,43 +20,19 @@
#ifndef __G_SETTINGS_SCHEMA_H__
#define __G_SETTINGS_SCHEMA_H__
-#include <glib-object.h>
+#include <glib.h>
G_BEGIN_DECLS
-#define G_TYPE_SETTINGS_SCHEMA (g_settings_schema_get_type ())
-#define G_SETTINGS_SCHEMA(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
- G_TYPE_SETTINGS_SCHEMA, GSettingsSchema))
-#define G_SETTINGS_SCHEMA_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
- G_TYPE_SETTINGS_SCHEMA, GSettingsSchemaClass))
-#define G_IS_SETTINGS_SCHEMA(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
- G_TYPE_SETTINGS_SCHEMA))
-#define G_IS_SETTINGS_SCHEMA_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \
- G_TYPE_SETTINGS_SCHEMA))
-#define G_SETTINGS_SCHEMA_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
- G_TYPE_SETTINGS_SCHEMA, GSettingsSchemaClass))
-
-typedef struct _GSettingsSchemaPrivate GSettingsSchemaPrivate;
-typedef struct _GSettingsSchemaClass GSettingsSchemaClass;
typedef struct _GSettingsSchema GSettingsSchema;
-struct _GSettingsSchemaClass
-{
- GObjectClass parent_class;
-};
-
-struct _GSettingsSchema
-{
- GObject parent_instance;
-
- GSettingsSchemaPrivate *priv;
-};
-
-G_GNUC_INTERNAL
-GType g_settings_schema_get_type (void);
G_GNUC_INTERNAL
GSettingsSchema * g_settings_schema_new (const gchar *name);
G_GNUC_INTERNAL
+GSettingsSchema * g_settings_schema_ref (GSettingsSchema *schema);
+G_GNUC_INTERNAL
+void g_settings_schema_unref (GSettingsSchema *schema);
+G_GNUC_INTERNAL
const gchar * g_settings_schema_get_path (GSettingsSchema *schema);
G_GNUC_INTERNAL
const gchar * g_settings_schema_get_gettext_domain (GSettingsSchema *schema);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]