From: Sven Neumann Date: Mon, 6 Aug 2001 20:55:11 +0000 (+0000) Subject: added new function g_nullify_pointer(). X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=d1d623b072c64302669e5f579fe4a63fcbab7021;p=dana%2Fcg-glib.git added new function g_nullify_pointer(). 2001-08-06 Sven Neumann * glib/gutils.[ch]: added new function g_nullify_pointer(). * gobject/gobject.[ch]: added new functions g_object_[add|remove]_weak_pointer(). --- diff --git a/ChangeLog b/ChangeLog index 81fa4dcc..a0320528 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-08-06 Sven Neumann + + * glib/gutils.[ch]: added new function g_nullify_pointer(). + + * gobject/gobject.[ch]: + added new functions g_object_[add|remove]_weak_pointer(). + 2001-08-05 Ron Steinke * glib/giochannel.c glib/giochannel.c glib/glib.def diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 81fa4dcc..a0320528 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,10 @@ +2001-08-06 Sven Neumann + + * glib/gutils.[ch]: added new function g_nullify_pointer(). + + * gobject/gobject.[ch]: + added new functions g_object_[add|remove]_weak_pointer(). + 2001-08-05 Ron Steinke * glib/giochannel.c glib/giochannel.c glib/glib.def diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 81fa4dcc..a0320528 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +2001-08-06 Sven Neumann + + * glib/gutils.[ch]: added new function g_nullify_pointer(). + + * gobject/gobject.[ch]: + added new functions g_object_[add|remove]_weak_pointer(). + 2001-08-05 Ron Steinke * glib/giochannel.c glib/giochannel.c glib/glib.def diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 81fa4dcc..a0320528 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,10 @@ +2001-08-06 Sven Neumann + + * glib/gutils.[ch]: added new function g_nullify_pointer(). + + * gobject/gobject.[ch]: + added new functions g_object_[add|remove]_weak_pointer(). + 2001-08-05 Ron Steinke * glib/giochannel.c glib/giochannel.c glib/glib.def diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 81fa4dcc..a0320528 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,10 @@ +2001-08-06 Sven Neumann + + * glib/gutils.[ch]: added new function g_nullify_pointer(). + + * gobject/gobject.[ch]: + added new functions g_object_[add|remove]_weak_pointer(). + 2001-08-05 Ron Steinke * glib/giochannel.c glib/giochannel.c glib/glib.def diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 81fa4dcc..a0320528 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +2001-08-06 Sven Neumann + + * glib/gutils.[ch]: added new function g_nullify_pointer(). + + * gobject/gobject.[ch]: + added new functions g_object_[add|remove]_weak_pointer(). + 2001-08-05 Ron Steinke * glib/giochannel.c glib/giochannel.c glib/glib.def diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 81fa4dcc..a0320528 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +2001-08-06 Sven Neumann + + * glib/gutils.[ch]: added new function g_nullify_pointer(). + + * gobject/gobject.[ch]: + added new functions g_object_[add|remove]_weak_pointer(). + 2001-08-05 Ron Steinke * glib/giochannel.c glib/giochannel.c glib/glib.def diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 81fa4dcc..a0320528 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +2001-08-06 Sven Neumann + + * glib/gutils.[ch]: added new function g_nullify_pointer(). + + * gobject/gobject.[ch]: + added new functions g_object_[add|remove]_weak_pointer(). + 2001-08-05 Ron Steinke * glib/giochannel.c glib/giochannel.c glib/glib.def diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 63f55039..5e2a5704 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,9 @@ +2001-08-06 Sven Neumann + + * docs/reference/gobject/gobject-sections.txt + * docs/reference/gobject/tmpl/objects.sgml: added documentation for + g_object_[add|remove]_weak_pointer(). + 2001-07-19 Darin Adler reviewed by: diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt index 9d43e4b0..43a70b5b 100644 --- a/docs/reference/gobject/gobject-sections.txt +++ b/docs/reference/gobject/gobject-sections.txt @@ -157,6 +157,10 @@ g_object_class_find_property g_object_new g_object_ref g_object_unref +g_object_weak_ref +g_object_weak_unref +g_object_add_weak_pointer +g_object_remove_weak_pointer g_object_connect g_object_disconnect g_object_set diff --git a/docs/reference/gobject/tmpl/objects.sgml b/docs/reference/gobject/tmpl/objects.sgml index 2e69507e..cc3c2be0 100644 --- a/docs/reference/gobject/tmpl/objects.sgml +++ b/docs/reference/gobject/tmpl/objects.sgml @@ -207,6 +207,49 @@ The Base Object Type @object: + + + + + +@object: +@notify: +@data: + + + + + + + +@object: +@notify: +@data: + + + + +Adds a weak reference from weak_pointer to @object to indicate that +the pointer located at @weak_pointer_location is only valid during the +lifetime of @object. When the @object is finalized, @weak_pointer will +be set to %NULL. + + +@object: the object that should be weak referenced. +@weak_pointer_location: the memory address of a pointer. + + + + +Removes a weak reference from @object that was previously added +using g_object_add_weak_pointer(). The @weak_pointer_location has +to match the one used with g_object_add_weak_pointer(). + + +@object: the object that is weak referenced. +@weak_pointer_location: the memory address of a pointer. + + diff --git a/glib/gutils.c b/glib/gutils.c index 24d7ad91..17e15147 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -1045,6 +1045,20 @@ g_int_hash (gconstpointer v) return *(const gint*) v; } +/** + * g_nullify_pointer: + * @nullify_location: the memory address of the pointer. + * + * Set the pointer at the specified location to %NULL. + **/ +void +g_nullify_pointer (gpointer *nullify_location) +{ + g_return_if_fail (nullify_location != NULL); + + *nullify_location = NULL; +} + /** * g_get_codeset: * diff --git a/glib/gutils.h b/glib/gutils.h index f4c9098e..f4494838 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -165,6 +165,10 @@ gchar* g_get_current_dir (void); gchar* g_path_get_basename (const gchar *file_name); gchar* g_path_get_dirname (const gchar *file_name); + +/* Set the pointer at the specified location to NULL */ +void g_nullify_pointer (gpointer *nullify_location); + /* Get the codeset for the current locale */ /* gchar * g_get_codeset (void); */ diff --git a/gobject/gobject.c b/gobject/gobject.c index 7e680871..e1855e17 100644 --- a/gobject/gobject.c +++ b/gobject/gobject.c @@ -1262,6 +1262,30 @@ g_object_weak_unref (GObject *object, g_warning (G_STRLOC ": couldn't find weak ref %p(%p)", notify, data); } +void +g_object_add_weak_pointer (GObject *object, + gpointer *weak_pointer_location) +{ + g_return_if_fail (G_IS_OBJECT (object)); + g_return_if_fail (weak_pointer_location != NULL); + + g_object_weak_ref (object, + (GWeakNotify) g_nullify_pointer, + weak_pointer_location); +} + +void +g_object_remove_weak_pointer (GObject *object, + gpointer *weak_pointer_location) +{ + g_return_if_fail (G_IS_OBJECT (object)); + g_return_if_fail (weak_pointer_location != NULL); + + g_object_weak_unref (object, + (GWeakNotify) g_nullify_pointer, + weak_pointer_location); +} + gpointer g_object_ref (gpointer _object) { diff --git a/gobject/gobject.h b/gobject/gobject.h index 43740f0e..582f81cf 100644 --- a/gobject/gobject.h +++ b/gobject/gobject.h @@ -154,6 +154,10 @@ void g_object_weak_ref (GObject *object, void g_object_weak_unref (GObject *object, GWeakNotify notify, gpointer data); +void g_object_add_weak_pointer (GObject *object, + gpointer *weak_pointer_location); +void g_object_remove_weak_pointer (GObject *object, + gpointer *weak_pointer_location); gpointer g_object_get_qdata (GObject *object, GQuark quark); void g_object_set_qdata (GObject *object,