provide marshaller specific value_set_*_take_ownership() variants.

Sun Feb 16 22:08:48 2002  Tim Janik  <timj@gtk.org>

        * gobject.[hc]:
        * gparam.[hc]: provide marshaller specific value_set_*_take_ownership()
        variants.

        * gvalue.h: shrink GValue's data contents to 2 unions.

        * glib-genmarshal.c: fix release and realeas_check hackage by always
        using _take_ownership() variants. directly access value contents if
        G_ENABLE_DEBUG is not defined.

        * gobject.h: add padding pointers to the class struct.
This commit is contained in:
Tim Janik 2002-02-19 17:38:45 +00:00 committed by Tim Janik
parent f2620633c1
commit a0f5e304b2
8 changed files with 157 additions and 63 deletions

View File

@ -1,3 +1,17 @@
Sun Feb 16 22:08:48 2002 Tim Janik <timj@gtk.org>
* gobject.[hc]:
* gparam.[hc]: provide marshaller specific value_set_*_take_ownership()
variants.
* gvalue.h: shrink GValue's data contents to 2 unions.
* glib-genmarshal.c: fix release and realeas_check hackage by always
using _take_ownership() variants. directly access value contents if
G_ENABLE_DEBUG is not defined.
* gobject.h: add padding pointers to the class struct.
Wed Feb 13 17:22:37 2002 Tim Janik <timj@gtk.org>
* gtype.c (g_type_value_table_peek): fixed a check for node not being NULL.

View File

@ -376,8 +376,7 @@ g_boxed_copy (GType boxed_type,
/* double check and grouse if things went wrong */
if (dest_value.data[1].v_ulong ||
dest_value.data[2].v_ulong ||
dest_value.data[3].v_ulong)
dest_value.data[2].v_ulong)
g_warning ("the copy_value() implementation of type `%s' seems to make use of reserved GValue fields",
g_type_name (boxed_type));

View File

@ -56,8 +56,6 @@ typedef struct
const gchar *sig_name; /* signature name [STRING] */
const gchar *ctype; /* C type name [gchar*] */
const gchar *setter; /* value setter function [g_value_set_string] */
const gchar *release; /* value release function [g_free] */
const gchar *release_check; /* checks if release function is safe to call */
} OutArgument;
typedef struct
{
@ -126,33 +124,83 @@ static gboolean std_includes = TRUE;
/* --- functions --- */
static void
put_marshal_value_getters (void)
{
fputs ("\n", fout);
fputs ("#ifdef G_ENABLE_DEBUG\n", fout);
fputs ("#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)\n", fout);
fputs ("#define g_marshal_value_peek_char(v) g_value_get_char (v)\n", fout);
fputs ("#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)\n", fout);
fputs ("#define g_marshal_value_peek_int(v) g_value_get_int (v)\n", fout);
fputs ("#define g_marshal_value_peek_uint(v) g_value_get_uint (v)\n", fout);
fputs ("#define g_marshal_value_peek_long(v) g_value_get_long (v)\n", fout);
fputs ("#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)\n", fout);
fputs ("#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)\n", fout);
fputs ("#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)\n", fout);
fputs ("#define g_marshal_value_peek_enum(v) g_value_get_enum (v)\n", fout);
fputs ("#define g_marshal_value_peek_flags(v) g_value_get_flags (v)\n", fout);
fputs ("#define g_marshal_value_peek_float(v) g_value_get_float (v)\n", fout);
fputs ("#define g_marshal_value_peek_double(v) g_value_get_double (v)\n", fout);
fputs ("#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)\n", fout);
fputs ("#define g_marshal_value_peek_param(v) g_value_get_param (v)\n", fout);
fputs ("#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)\n", fout);
fputs ("#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)\n", fout);
fputs ("#define g_marshal_value_peek_object(v) g_value_get_object (v)\n", fout);
fputs ("#else /* !G_ENABLE_DEBUG */\n", fout);
fputs ("/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.\n", fout);
fputs (" * Do not access GValues directly in your code. Instead, use the\n", fout);
fputs (" * g_value_get_*() functions\n", fout);
fputs (" */\n", fout);
fputs ("#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int\n", fout);
fputs ("#define g_marshal_value_peek_char(v) (v)->data[0].v_int\n", fout);
fputs ("#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint\n", fout);
fputs ("#define g_marshal_value_peek_int(v) (v)->data[0].v_int\n", fout);
fputs ("#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint\n", fout);
fputs ("#define g_marshal_value_peek_long(v) (v)->data[0].v_long\n", fout);
fputs ("#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong\n", fout);
fputs ("#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64\n", fout);
fputs ("#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64\n", fout);
fputs ("#define g_marshal_value_peek_enum(v) (v)->data[0].v_int\n", fout);
fputs ("#define g_marshal_value_peek_flags(v) (v)->data[0].v_uint\n", fout);
fputs ("#define g_marshal_value_peek_float(v) (v)->data[0].v_float\n", fout);
fputs ("#define g_marshal_value_peek_double(v) (v)->data[0].v_double\n", fout);
fputs ("#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer\n", fout);
fputs ("#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer\n", fout);
fputs ("#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer\n", fout);
fputs ("#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer\n", fout);
fputs ("#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer\n", fout);
fputs ("#endif /* !G_ENABLE_DEBUG */\n", fout);
fputs ("\n", fout);
}
static gboolean
complete_in_arg (InArgument *iarg)
{
static const InArgument args[] = {
/* keyword sig_name ctype getter */
{ "VOID", "VOID", "void", NULL, },
{ "BOOLEAN", "BOOLEAN", "gboolean", "g_value_get_boolean", },
{ "CHAR", "CHAR", "gchar", "g_value_get_char", },
{ "UCHAR", "UCHAR", "guchar", "g_value_get_uchar", },
{ "INT", "INT", "gint", "g_value_get_int", },
{ "UINT", "UINT", "guint", "g_value_get_uint", },
{ "LONG", "LONG", "glong", "g_value_get_long", },
{ "ULONG", "ULONG", "gulong", "g_value_get_ulong", },
{ "INT64", "INT64", "gint64", "g_value_get_int64", },
{ "UINT64", "UINT64", "guint64", "g_value_get_uint64", },
{ "ENUM", "ENUM", "gint", "g_value_get_enum", },
{ "FLAGS", "FLAGS", "guint", "g_value_get_flags", },
{ "FLOAT", "FLOAT", "gfloat", "g_value_get_float", },
{ "DOUBLE", "DOUBLE", "gdouble", "g_value_get_double", },
{ "STRING", "STRING", "gpointer", "(char*) g_value_get_string", },
{ "PARAM", "PARAM", "gpointer", "g_value_get_param", },
{ "BOXED", "BOXED", "gpointer", "g_value_get_boxed", },
{ "POINTER", "POINTER", "gpointer", "g_value_get_pointer", },
{ "OBJECT", "OBJECT", "gpointer", "g_value_get_object", },
{ "BOOLEAN", "BOOLEAN", "gboolean", "g_marshal_value_peek_boolean", },
{ "CHAR", "CHAR", "gchar", "g_marshal_value_peek_char", },
{ "UCHAR", "UCHAR", "guchar", "g_marshal_value_peek_uchar", },
{ "INT", "INT", "gint", "g_marshal_value_peek_int", },
{ "UINT", "UINT", "guint", "g_marshal_value_peek_uint", },
{ "LONG", "LONG", "glong", "g_marshal_value_peek_long", },
{ "ULONG", "ULONG", "gulong", "g_marshal_value_peek_ulong", },
{ "INT64", "INT64", "gint64", "g_marshal_value_peek_int64", },
{ "UINT64", "UINT64", "guint64", "g_marshal_value_peek_uint64", },
{ "ENUM", "ENUM", "gint", "g_marshal_value_peek_enum", },
{ "FLAGS", "FLAGS", "guint", "g_marshal_value_peek_flags", },
{ "FLOAT", "FLOAT", "gfloat", "g_marshal_value_peek_float", },
{ "DOUBLE", "DOUBLE", "gdouble", "g_marshal_value_peek_double", },
{ "STRING", "STRING", "gpointer", "g_marshal_value_peek_string", },
{ "PARAM", "PARAM", "gpointer", "g_marshal_value_peek_param", },
{ "BOXED", "BOXED", "gpointer", "g_marshal_value_peek_boxed", },
{ "POINTER", "POINTER", "gpointer", "g_marshal_value_peek_pointer", },
{ "OBJECT", "OBJECT", "gpointer", "g_marshal_value_peek_object", },
/* deprecated: */
{ "NONE", "VOID", "void", NULL, },
{ "BOOL", "BOOLEAN", "gboolean", "g_value_get_boolean", },
{ "BOOL", "BOOLEAN", "gboolean", "g_marshal_value_peek_boolean", },
};
const guint n_args = sizeof (args) / sizeof (args[0]);
guint i;
@ -175,29 +223,29 @@ static gboolean
complete_out_arg (OutArgument *oarg)
{
static const OutArgument args[] = {
/* keyword sig_name ctype setter release release_check */
{ "VOID", "VOID", "void", NULL, NULL, NULL },
{ "BOOLEAN", "BOOLEAN", "gboolean", "g_value_set_boolean", NULL, NULL },
{ "CHAR", "CHAR", "gchar", "g_value_set_char", NULL, NULL },
{ "UCHAR", "UCHAR", "guchar", "g_value_set_uchar", NULL, NULL },
{ "INT", "INT", "gint", "g_value_set_int", NULL, NULL },
{ "UINT", "UINT", "guint", "g_value_set_uint", NULL, NULL },
{ "LONG", "LONG", "glong", "g_value_set_long", NULL, NULL },
{ "ULONG", "ULONG", "gulong", "g_value_set_ulong", NULL, NULL },
{ "INT64", "INT64", "gint64", "g_value_set_int64", NULL, NULL },
{ "UINT64", "UINT64", "guint64", "g_value_set_uint64", NULL, NULL },
{ "ENUM", "ENUM", "gint", "g_value_set_enum", NULL, NULL },
{ "FLAGS", "FLAGS", "guint", "g_value_set_flags", NULL, NULL },
{ "FLOAT", "FLOAT", "gfloat", "g_value_set_float", NULL, NULL },
{ "DOUBLE", "DOUBLE", "gdouble", "g_value_set_double", NULL, NULL },
{ "STRING", "STRING", "gchar*", "g_value_set_string_take_ownership", NULL, NULL },
{ "PARAM", "PARAM", "GParamSpec*", "g_value_set_param", "g_param_spec_unref", NULL },
{ "BOXED", "BOXED", "gpointer", "g_value_set_boxed_take_ownership", NULL, NULL },
{ "POINTER", "POINTER", "gpointer", "g_value_set_pointer", NULL, NULL },
{ "OBJECT", "OBJECT", "GObject*", "g_value_set_object", "g_object_unref", "NULL !=" },
/* keyword sig_name ctype setter */
{ "VOID", "VOID", "void", NULL, },
{ "BOOLEAN", "BOOLEAN", "gboolean", "g_value_set_boolean", },
{ "CHAR", "CHAR", "gchar", "g_value_set_char", },
{ "UCHAR", "UCHAR", "guchar", "g_value_set_uchar", },
{ "INT", "INT", "gint", "g_value_set_int", },
{ "UINT", "UINT", "guint", "g_value_set_uint", },
{ "LONG", "LONG", "glong", "g_value_set_long", },
{ "ULONG", "ULONG", "gulong", "g_value_set_ulong", },
{ "INT64", "INT64", "gint64", "g_value_set_int64", },
{ "UINT64", "UINT64", "guint64", "g_value_set_uint64", },
{ "ENUM", "ENUM", "gint", "g_value_set_enum", },
{ "FLAGS", "FLAGS", "guint", "g_value_set_flags", },
{ "FLOAT", "FLOAT", "gfloat", "g_value_set_float", },
{ "DOUBLE", "DOUBLE", "gdouble", "g_value_set_double", },
{ "STRING", "STRING", "gchar*", "g_value_set_string_take_ownership", },
{ "PARAM", "PARAM", "GParamSpec*", "g_value_set_param_take_ownership", },
{ "BOXED", "BOXED", "gpointer", "g_value_set_boxed_take_ownership", },
{ "POINTER", "POINTER", "gpointer", "g_value_set_pointer", },
{ "OBJECT", "OBJECT", "GObject*", "g_value_set_object_take_ownership", },
/* deprecated: */
{ "NONE", "VOID", "void", NULL, NULL, NULL },
{ "BOOL", "BOOLEAN", "gboolean", "g_value_set_boolean", NULL, NULL }
{ "NONE", "VOID", "void", NULL, },
{ "BOOL", "BOOLEAN", "gboolean", "g_value_set_boolean", },
};
const guint n_args = sizeof (args) / sizeof (args[0]);
guint i;
@ -210,8 +258,6 @@ complete_out_arg (OutArgument *oarg)
oarg->sig_name = args[i].sig_name;
oarg->ctype = args[i].ctype;
oarg->setter = args[i].setter;
oarg->release = args[i].release;
oarg->release_check = args[i].release_check;
return TRUE;
}
@ -398,19 +444,6 @@ generate_marshal (const gchar *signame,
{
fprintf (fout, "\n");
fprintf (fout, " %s (return_value, v_return);\n", sig->rarg->setter);
if (sig->rarg->release)
{
if (sig->rarg->release_check)
{
fprintf (fout, " if (%s (v_return))\n", sig->rarg->release_check);
fprintf (fout, " %s (v_return);\n", sig->rarg->release);
}
else
{
fprintf (fout, " %s (v_return);\n", sig->rarg->release);
}
}
}
/* cfile marshal footer */
@ -610,6 +643,10 @@ main (int argc,
if (gen_cheader)
fprintf (fout, "G_BEGIN_DECLS\n");
/* generate necessary preprocessor directives */
if (gen_cbody)
put_marshal_value_getters ();
/* process input files */
for (slist = files; slist; slist = slist->next)
{

View File

@ -1526,6 +1526,27 @@ g_value_set_object (GValue *value,
}
}
void
g_value_set_object_take_ownership (GValue *value,
gpointer v_object)
{
g_return_if_fail (G_VALUE_HOLDS_OBJECT (value));
if (value->data[0].v_pointer)
{
g_object_unref (value->data[0].v_pointer);
value->data[0].v_pointer = NULL;
}
if (v_object)
{
g_return_if_fail (G_IS_OBJECT (v_object));
g_return_if_fail (g_value_type_compatible (G_OBJECT_TYPE (v_object), G_VALUE_TYPE (value)));
value->data[0].v_pointer = v_object; /* we take over the reference count */
}
}
gpointer
g_value_get_object (const GValue *value)
{

View File

@ -99,6 +99,8 @@ struct _GObjectClass
/* signals */
void (*notify) (GObject *object,
GParamSpec *pspec);
/* padding */
gpointer pdummy[8];
};
struct _GObjectConstructParam
{
@ -209,6 +211,11 @@ gulong g_signal_connect_object (gpointer instance,
void g_object_run_dispose (GObject *object);
/* --- marshaller specific --- */
void g_value_set_object_take_ownership (GValue *value,
gpointer v_object);
/* --- implementation macros --- */
#define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \
G_STMT_START { \

View File

@ -962,6 +962,19 @@ g_value_set_param (GValue *value,
g_param_spec_ref (value->data[0].v_pointer);
}
void
g_value_set_param_take_ownership (GValue *value,
GParamSpec *param)
{
g_return_if_fail (G_VALUE_HOLDS_PARAM (value));
if (param)
g_return_if_fail (G_IS_PARAM_SPEC (param));
if (value->data[0].v_pointer)
g_param_spec_unref (value->data[0].v_pointer);
value->data[0].v_pointer = param; /* we take over the reference count */
}
GParamSpec*
g_value_get_param (const GValue *value)
{

View File

@ -143,6 +143,11 @@ GParamSpec* g_value_get_param (const GValue *value);
GParamSpec* g_value_dup_param (const GValue *value);
/* --- marshaller specific --- */
void g_value_set_param_take_ownership (GValue *value,
GParamSpec *param);
/* --- convenience functions --- */
typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
struct _GParamSpecTypeInfo

View File

@ -38,8 +38,6 @@ G_BEGIN_DECLS
/* --- typedefs & structures --- */
typedef void (*GValueExchange) (GValue *value1,
GValue *value2);
typedef void (*GValueTransform) (const GValue *src_value,
GValue *dest_value);
struct _GValue
@ -58,7 +56,7 @@ struct _GValue
gfloat v_float;
gdouble v_double;
gpointer v_pointer;
} data[4];
} data[2];
};