Re: patch for g_nullify_pointer() and friends
- From: Owen Taylor <otaylor redhat com>
- To: Sven Neumann <sven gimp org>
- Cc: Tim Janik <timj gtk org>, Gtk+ Developers <gtk-devel-list gnome org>
- Subject: Re: patch for g_nullify_pointer() and friends
- Date: 04 Aug 2001 09:22:08 -0400
Sven Neumann <sven gimp org> writes:
> 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?
* By agreed upon convention g_nullify_pointer should
be g_nullify_pointer_handler().
* Is it really generally useful beyond add/remove_weak_ref()?
* Your macros are missing a cast to GWeakNotify.
* The advantages of making g_object_add/remove_weak_ref() macros
are:
- One less function call. (But this function call, in the
event it turned out to be a performance problem,
could be optimized away inside gobject.c as well.)
- Slightly decreased code size in the library
The distandvantages are:
- Can't use inline docs (if you go with macros, you _must_
add an entry to docs/reference/gobject-overrides.txt
and then fill in the docs in docs/refererence
- Worse error messages from the compiler.
- Worse g_return_if_fail() messages.
- Slightly increased code size and startup time in
the app (the compiler needs to do a load-time lookup of
g_nullify_pointer)
It's not a big deal either way - I'd certainly go
with the functions myself. (I _did_ go with the functions
myself in the earlier patch I submitetd...)
Regards,
Owen
> 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__ */
>
>
>
>
>
>
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]