patch for g_nullify_pointer() and friends



Hi,

here's a small patch that adds g_nullify_pointer() to glib and 
g_object_[add|remove]_weak_pointer() to gobject. OK to commit?


Salut, Sven

Index: glib/gutils.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gutils.c,v
retrieving revision 1.97
diff -u -r1.97 gutils.c
--- glib/gutils.c	2001/06/30 16:54:32	1.97
+++ glib/gutils.c	2001/08/03 15:50:03
@@ -1046,6 +1046,18 @@
 }
 
 /**
+ * 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)
+{
+  *nullify_location = NULL;
+}
+
+/**
  * g_get_codeset:
  * 
  * Get the codeset for the current locale.
Index: glib/gutils.h
===================================================================
RCS file: /cvs/gnome/glib/glib/gutils.h,v
retrieving revision 1.10
diff -u -r1.10 gutils.h
--- glib/gutils.h	2001/07/10 22:37:07	1.10
+++ glib/gutils.h	2001/08/03 15:50:03
@@ -165,6 +165,10 @@
 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); */
 
Index: gobject/gobject.h
===================================================================
RCS file: /cvs/gnome/glib/gobject/gobject.h,v
retrieving revision 1.16
diff -u -r1.16 gobject.h
--- gobject/gobject.h	2001/07/02 05:02:13	1.16
+++ gobject/gobject.h	2001/08/03 15:50:03
@@ -216,6 +216,11 @@
 #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
     G_OBJECT_WARN_INVALID_PSPEC ((object), "property id", (property_id), (pspec))
 
+#define g_object_add_weak_pointer(object,weak_pointer) \
+    g_object_weak_ref ((object), g_nullify_pointer, (weak_pointer))
+#define g_object_remove_weak_pointer(object,weak_pointer) \
+    g_object_weak_unref ((object), g_nullify_pointer, (weak_pointer))
+
 G_END_DECLS
 
 #endif /* __G_OBJECT_H__ */









[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]