mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-26 02:48:54 +02:00
added newly added gobject/ headers.
Tue Oct 24 22:09:14 2000 Tim Janik <timj@gtk.org> * glib-object.h: added newly added gobject/ headers. * gmesage.c: print g_message() output to stderr instead of stdout. Wed Oct 25 20:27:02 2000 Tim Janik <timj@gtk.org> * gtype.c (g_type_free_instance): for the moment, freeing object structures will fill their memory portion with 0xAA. there's a FIXME there, remove this line at a later point. Tue Oct 24 23:10:26 2000 Tim Janik <timj@gtk.org> * glib-genmarshal.1: * glib-genmarshal.c: added publically installed marshaller generator. * gtype.h: added G_TYPE_INSTANCE_GET_INTERFACE() to retrive a certain interface VTable from instances. Mon Oct 23 08:28:15 2000 Tim Janik <timj@gtk.org> * gobject.[hc]: new functions for closure maintenance: (g_object_watch_closure): maintain validity of the object and the closure for objects that are used as data part of a closure. (g_cclosure_new_object): convenience function to create C closures that have an object as data argument. (g_closure_new_object): convenience function to create closures that have an object as data argument. * gclosure.[hc]: implementation of GClosure mechanism. a closure is basically an encapsulation of a callback function and its environment. ideally, most places supporting callback functions will simply take a GClosure* pointer and thus unify callback environments wrg destroy notification etc. GClosure provides destroy notifiers for arbitrary data pointers, reference counting, invalidation notification (it can be invalidated which is merely a deactivate state) and a marshallinbg abstraction. GCClosure is also provided in these files, they present a specialized GClosure implementation for C language callbacks. * genum.c: macro cleanups. * gboxed.[hc]: new files, for boxed type abstraction. (g_boxed_copy): copy a boxed structure (g_boxed_free): free a boxed structure (g_value_set_boxed): (g_value_get_boxed): standard GValue functions for boxed types (g_boxed_type_register_static): convenience function for easy introduction of new G_TYPE_BOXED derivatives. * gparam.[hc]: introduced g_param_type_register_static(), a short hand for creation of new GParamSpec derived types. * gtype.[hc]: many fixes, introduced ability to flag individual type nodes as ABSTRACT upon registration, added value_peek_pointer() to the value table to peek at GValue contents as a pointer for types that support this. fixed up GValue checks. * gvalue.[hc]: added g_value_fits_pointer() and g_value_get_as_pointer() to peek at the value contents as pointer. * *.[hc]: adaptions to type macro fixes and changes in the type registration API. * many const corrections over the place. Sat Oct 21 02:49:56 2000 Tim Janik <timj@gtk.org> * gtype.c (g_type_conforms_to): this function basically behaves like and is_a check, except that it _additionally_ features interfaces for instantiatable types. enforce this in the second branch as well (`type' conforms_to `type') even if `type' is not an interface type. Fri Oct 20 15:31:04 2000 Tim Janik <timj@gtk.org> * gvaluetypes.[hc]: added G_TYPE_POINTER implementation from jrb. * gtype.[hc]: * gobject.c: * gvaluetypes.c: added GTypeValueTable.value_peek_pointer and suitable implementations of this for G_TYPE_STRING, G_TYPE_OBJECT and G_TYPE_POINTER. Mon Aug 21 04:13:37 2000 Tim Janik <timj@gtk.org> * gbsearcharray.[hc]: long standing needed generic implementation of a binary searchable, sorted and dynamically sized array.
This commit is contained in:
@@ -46,6 +46,7 @@ static void g_value_object_init (GValue *value);
|
||||
static void g_value_object_free_value (GValue *value);
|
||||
static void g_value_object_copy_value (const GValue *src_value,
|
||||
GValue *dest_value);
|
||||
static gpointer g_value_object_peek_pointer (const GValue *value);
|
||||
static gchar* g_value_object_collect_value (GValue *value,
|
||||
guint nth_value,
|
||||
GType *collect_type,
|
||||
@@ -59,6 +60,7 @@ static gchar* g_value_object_lcopy_value (const GValue *value,
|
||||
/* --- variables --- */
|
||||
static GQuark quark_param_id = 0;
|
||||
static GQuark quark_param_changed_queue = 0;
|
||||
static GQuark quark_closure_array = 0;
|
||||
static GHashTable *param_spec_hash_table = NULL;
|
||||
|
||||
|
||||
@@ -122,6 +124,7 @@ g_object_type_init (void) /* sync with gtype.c */
|
||||
g_value_object_init, /* value_init */
|
||||
g_value_object_free_value, /* value_free */
|
||||
g_value_object_copy_value, /* value_copy */
|
||||
g_value_object_peek_pointer, /* value_peek_pointer */
|
||||
G_VALUE_COLLECT_POINTER, /* collect_type */
|
||||
g_value_object_collect_value, /* collect_value */
|
||||
G_VALUE_COLLECT_POINTER, /* lcopy_type */
|
||||
@@ -135,7 +138,7 @@ g_object_type_init (void) /* sync with gtype.c */
|
||||
/* G_TYPE_OBJECT
|
||||
*/
|
||||
info.value_table = &value_table;
|
||||
type = g_type_register_fundamental (G_TYPE_OBJECT, "GObject", &info, &finfo);
|
||||
type = g_type_register_fundamental (G_TYPE_OBJECT, "GObject", &info, &finfo, 0);
|
||||
g_assert (type == G_TYPE_OBJECT);
|
||||
|
||||
#ifdef DEBUG_OBJECTS
|
||||
@@ -178,6 +181,7 @@ g_object_do_class_init (GObjectClass *class)
|
||||
{
|
||||
quark_param_id = g_quark_from_static_string ("glib-object-param-id");
|
||||
quark_param_changed_queue = g_quark_from_static_string ("glib-object-param-changed-queue");
|
||||
quark_closure_array = g_quark_from_static_string ("GObject-closure-array");
|
||||
param_spec_hash_table = g_param_spec_hash_table_new ();
|
||||
|
||||
class->queue_param_changed = g_object_do_queue_param_changed;
|
||||
@@ -810,6 +814,12 @@ g_value_object_copy_value (const GValue *src_value,
|
||||
dest_value->data[0].v_pointer = NULL;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
g_value_object_peek_pointer (const GValue *value)
|
||||
{
|
||||
return value->data[0].v_pointer;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
g_value_object_collect_value (GValue *value,
|
||||
guint nth_value,
|
||||
@@ -874,7 +884,7 @@ g_value_set_object (GValue *value,
|
||||
}
|
||||
|
||||
GObject*
|
||||
g_value_get_object (GValue *value)
|
||||
g_value_get_object (const GValue *value)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_VALUE_OBJECT (value), NULL);
|
||||
|
||||
@@ -882,9 +892,137 @@ g_value_get_object (GValue *value)
|
||||
}
|
||||
|
||||
GObject*
|
||||
g_value_dup_object (GValue *value)
|
||||
g_value_dup_object (const GValue *value)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_VALUE_OBJECT (value), NULL);
|
||||
|
||||
return value->data[0].v_pointer ? g_object_ref (value->data[0].v_pointer) : NULL;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GObject *object;
|
||||
guint n_closures;
|
||||
GClosure *closures[1]; /* flexible array */
|
||||
} CArray;
|
||||
|
||||
static void
|
||||
object_remove_closure (gpointer data,
|
||||
GClosure *closure)
|
||||
{
|
||||
GObject *object = data;
|
||||
CArray *carray = g_object_get_qdata (object, quark_closure_array);
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < carray->n_closures; i++)
|
||||
if (carray->closures[i] == closure)
|
||||
{
|
||||
carray->n_closures--;
|
||||
if (i < carray->n_closures)
|
||||
carray->closures[i] = carray->closures[carray->n_closures];
|
||||
return;
|
||||
}
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_closure_array (gpointer data)
|
||||
{
|
||||
CArray *carray = data;
|
||||
GObject *object = carray->object;
|
||||
guint i, n = carray->n_closures;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
GClosure *closure = carray->closures[i];
|
||||
|
||||
/* removing object_remove_closure() upfront is probably faster than
|
||||
* letting it fiddle with quark_closure_array which is empty anyways
|
||||
*/
|
||||
g_closure_remove_inotify (closure, object, object_remove_closure);
|
||||
g_closure_invalidate (closure);
|
||||
}
|
||||
g_free (carray);
|
||||
}
|
||||
|
||||
void
|
||||
g_object_watch_closure (GObject *object,
|
||||
GClosure *closure)
|
||||
{
|
||||
CArray *carray;
|
||||
|
||||
g_return_if_fail (G_IS_OBJECT (object));
|
||||
g_return_if_fail (closure != NULL);
|
||||
g_return_if_fail (closure->is_invalid == FALSE);
|
||||
g_return_if_fail (closure->in_marshal == FALSE);
|
||||
g_return_if_fail (object->ref_count > 0); /* this doesn't work on finalizing objects */
|
||||
|
||||
g_closure_add_inotify (closure, object, object_remove_closure);
|
||||
g_closure_add_marshal_guards (closure,
|
||||
object, (GClosureNotify) g_object_ref,
|
||||
object, (GClosureNotify) g_object_unref);
|
||||
carray = g_object_get_qdata (object, quark_closure_array);
|
||||
if (!carray)
|
||||
{
|
||||
carray = g_renew (CArray, NULL, 1);
|
||||
carray->object = object;
|
||||
carray->n_closures = 1;
|
||||
carray->closures[0] = closure;
|
||||
g_object_set_qdata_full (object, quark_closure_array, carray, destroy_closure_array);
|
||||
}
|
||||
else
|
||||
{
|
||||
guint i = carray->n_closures++;
|
||||
|
||||
carray = g_realloc (carray, sizeof (*carray) + sizeof (carray->closures[0]) * i);
|
||||
carray->closures[i] = closure;
|
||||
}
|
||||
}
|
||||
|
||||
GClosure*
|
||||
g_closure_new_object (guint sizeof_closure,
|
||||
GObject *object)
|
||||
{
|
||||
GClosure *closure;
|
||||
|
||||
g_return_val_if_fail (G_IS_OBJECT (object), NULL);
|
||||
g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
|
||||
|
||||
closure = g_closure_new_simple (sizeof_closure, object);
|
||||
g_object_watch_closure (object, closure);
|
||||
|
||||
return closure;
|
||||
}
|
||||
|
||||
GClosure*
|
||||
g_cclosure_new_object (gpointer _object,
|
||||
GCallback callback_func)
|
||||
{
|
||||
GObject *object = _object;
|
||||
GClosure *closure;
|
||||
|
||||
g_return_val_if_fail (G_IS_OBJECT (object), NULL);
|
||||
g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
|
||||
g_return_val_if_fail (callback_func != NULL, NULL);
|
||||
|
||||
closure = g_cclosure_new (callback_func, object, NULL);
|
||||
g_object_watch_closure (object, closure);
|
||||
|
||||
return closure;
|
||||
}
|
||||
|
||||
GClosure*
|
||||
g_cclosure_new_object_swap (gpointer _object,
|
||||
GCallback callback_func)
|
||||
{
|
||||
GObject *object = _object;
|
||||
GClosure *closure;
|
||||
|
||||
g_return_val_if_fail (G_IS_OBJECT (object), NULL);
|
||||
g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
|
||||
g_return_val_if_fail (callback_func != NULL, NULL);
|
||||
|
||||
closure = g_cclosure_new_swap (callback_func, object, NULL);
|
||||
g_object_watch_closure (object, closure);
|
||||
|
||||
return closure;
|
||||
}
|
||||
|
Reference in New Issue
Block a user