Re: PROPOSAL: revise GLib message system
- From: Owen Taylor <otaylor redhat com>
- To: Tim Janik <timj gtk org>
- Cc: Gtk+ Developers <gtk-devel-list redhat com>, Hacking Gnomes <Gnome-Hackers athena nuclecu unam mx>
- Subject: Re: PROPOSAL: revise GLib message system
- Date: 07 Aug 1998 09:38:05 -0400
Tim Janik <timj@gtk.org> writes:
[...]
> to have warning, error and message handlers be implemented on a
> per-library basis, i'd like to propose to rename
> g_error to _g_error
> g_warning to _g_warning
> g_message to _g_message
>
> and additionally have
> void g_glib_error (const gchar *format, ...);
> void g_glib_warning (const gchar *format, ...);
> void g_glib_message (const gchar *format, ...);
> GErrorFunc g_set_glib_error_handler (GErrorFunc func);
> GWarningFunc g_set_glib_warning_handler (GWarningFunc func);
> GPrintFunc g_set_glib_message_handler (GPrintFunc func);
>
> and then have this in glib.h:
>
> #ifdef GLIB_INTERNAL
> #define g_error g_glib_error
> #define g_warning g_glib_warning
> #define g_message g_glib_message
> #endif /* GLIB_INTERNAL */
>
> #ifndef g_error
> #define g_error _g_error
> #endif /* g_error */
> #ifndef g_warning
> #define g_warning _g_warning
> #endif /* g_warning */
> #ifndef g_message
> #define g_message _g_message
> #endif /* g_message */
>
> if we then compile the glib *.c files with -DGLIB_INTERNAL, all the warnings
> and errors from within glib will be routed through the g_glib_* functions,
> while the current behaviour is still provided on the application level.
> to get specialized warning, error and message handlers for gtk, we just need
> to trade the
> #include <gdk/gdk.h>
> in the header files with something like
> #include <gtk/gtkbase.h>
> and have this in gtkbase.h:
>
> #ifdef GTK_INTERNAL
> #define g_error _gtk_error
> #define g_warning _gtk_warning
> #define g_message _gtk_message
> #endif /* GTK_INTERNAL */
>
> #include <gdk/gdk.h>
>
> /* the following functions should most probably go into gtkmain.h */
> void _gtk_error (const gchar *format, ...);
> void _gtk_warning (const gchar *format, ...);
> void _gtk_message (const gchar *format, ...);
> GErrorFunc gtk_set_error_handler (GErrorFunc func);
> GWarningFunc gtk_set_warning_handler (GWarningFunc func);
> GPrintFunc gtk_set_message_handler (GPrintFunc func);
>
> of course all gtk*.c files need to be compiled with -DGTK_INTERNAL.
>
> the same scheme can be applied to gdk and -especially- gnome, which
> introduces a bunch of different libraries. keep in mind, that nothing
> will change on the application level with the new scheme, programmers
> have just to explicitely overload the message handlers of underlying
> libraries if they really intend to catch those as well.
>
> on a related note, i think the current g_return_val_if_fail (1 == 2, 0);
> >
> > ** WARNING **: file gwarn.c: line 6 (main): assertion "1 == 2" failed.
> should better produce
> >
> > ** WARNING **: file gwarn.c: line 6 (main): assertion failed: "1 == 2"
>
> also, people should refrain from using g_print() inside of libraries and
> better go for g_message() for informational purposes, since g_print()
> is of actuall use on the application side to print into a special
> purpose messaging window or something the like, which is not supposed
> to contain debugging information of the underlying libraries.
> since g_print() is usually used for debugging statements, it might be a
> good idea to implement an additional g_debug() call, similar to the
> current g_message() function.
>
> g_debug() could even be combined with existing debug keys, such as
> gdk_debug_flags, so code portions like
>
> #ifdef G_ENABLE_DEBUG
> if (gdk_debug_flags & (GDK_DEBUG_EVENTS | GDK_DEBUG_DND))
> g_print ("GDK_DROP_LEAVE\n");
> #endif
>
> could be written as (inside gdk):
>
> g_debug (GDK_DEBUG_EVENTS | GDK_DEBUG_DND, "GDK_DROP_LEAVE");
>
> and would produce:
>
> > Gdk-Message: GDK_DROP_LEAVE
>
>
> i'm curious to hear peoples comments on this isuue, and will most probably
> go for the implementation of this in gtk, gdk and glib after a few days if
> no one stands up and objects ;)
Objection, your honor!
I think defining g_warning (etc.) to do different things in different
places, is evil preprocessor magic, and should be avoided. All
the unprefixed g_* should be left to behave as is. (On the surface).
Then, add:
g_info (GQuark who, GSeverity severity, message, ...)
g_infov (GQuark who, GSeverity severity, message, va_list args)
g_info_set_handler (GQuark who, GSeverity severity, GInfoHandler handler);
[ Maybe make GSeverity a flags field so the same handler could
handle a set of warning? ]
On GCC, we can #define gtk_warning appropriately on systems without
varargs macros, it needs to be a wrapper function (or we can make it
an inline function) - in any case, we write:
gtk_warning ("unable to register error handler")
and even
gtk_return_if_fail (x != 0);
(The biggest CVS commit ever?)
Even if people decide they _really_ want to have g_warning magically
do different things in different source files, I do think we should do
something like the g_info() scheme internally, so every library and
every application doesn't have to duplicate all the handlers.
[
Automagical macros really need to be in uppercase - to at least
let the user know something odd is going on.
#ifndef G_MODULE
#define G_MODULE G
#endif
#define G_WARNING G_MODULE##_warning
gcc -DG_MODULE=gtk foo.c
would be better. (Though sprinkling the source code with
G_RETURN_VAL_IF_FAIL (x != NULL, FALSE);
will make the source code much less pretty.
]
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]