Re: PROPOSAL: revise GLib message system
- From: Tim Janik <timj gtk org>
- To: Owen Taylor <otaylor redhat com>
- cc: Gtk+ Developers <gtk-devel-list redhat com>, Hacking Gnomes <Gnome-Hackers athena nuclecu unam mx>
- Subject: Re: PROPOSAL: revise GLib message system
- Date: Sat, 8 Aug 1998 08:19:31 +0200 (CEST)
On 7 Aug 1998, Owen Taylor wrote:
> 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? ]
you could just use multiple calls for such cases, e.g.
typedef enum
{
G_SEVERITY_FATAL,
G_SEVERITY_WARNING,
G_SEVERITY_INFO,
G_SEVERITY_DEBUG
} GSeverityType;
g_info_set_handler (gtk_quark, G_SEVERITY_FATAL, gtk_info_handler_abort);
g_info_set_handler (gtk_quark, G_SEVERITY_CRITICAL, gtk_info_handler_continue);
g_info_set_handler (gtk_quark, G_SEVERITY_WARNING, gtk_info_handler_continue);
g_info_set_handler (gtk_quark, G_SEVERITY_INFO, gtk_info_handler_continue);
g_info_set_handler (gtk_quark, G_SEVERITY_DEBUG, gtk_info_handler_continue);
but i'd prefer to use g_logger instead of g_info. g_info could be needed
as a fucntion name later on, and g_logger does express the purpose better.
it wouldn't for instance be unreasonable if we later feature a comandline
option, that's going to let the default message handlers log into a
file or somesuch.
> 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?)
hm, i really like the idea of having the same function/macro name for each
library, so that gtk, gdk, gnome *and* the application all use
G_WARNING and G_RETURN_IF_FAIL (or g_warning and g_return_if_fail).
but for the sake of incresed readability i think we should really supply
lower case variants of those macros, even if that means we need to make
an exeption to the macros-are-in-upper-case rule.
we already didn't follow that for the existing g_return_* macros.
e.g. if we have:
void g_logger (GQuark who_quark,
GSeverityType severity,
const gchar *format,
...);
#define G_ERROR(fmt, args...) g_logger (G_LOGGER_QUARK, G_SEVERITY_FATAL, fmt, ##args)
#define G_WARNING(fmt, args...) g_logger (G_LOGGER_QUARK, G_SEVERITY_WARNING, fmt, ##args)
#define G_MESSAGE(fmt, args...) g_logger (G_LOGGER_QUARK, G_SEVERITY_INFO, fmt, ##args)
#ifndef G_LOGGER_QUARK
#define G_LOGGER_QUARK (0)
#endif /* G_LOGGER_QUARK */
and compile gtk files with -DG_LOGGER_QUARK=gtk_quark, the exception would
be a few additional defines in glib.h:
#define g_warning G_WARNING
#define g_error G_ERROR
#define g_message G_MESSAGE
with the sole purpose of increased readability.
on non-gcc systems, G_WARNING, G_ERROR and G_MESSAGE are even going
to be *real* functions (inlined), so we could just give them lower
case names in the first place...
extern GQuark gtk_quark; would need to be initialized at the beginning of
gtk_init(), but do we really want quarks in this place? we can just as well
export const gchar *gtk_logger_domain = "Gtk", and use
-DG_LOGGER_DOMAIN=gtk_logger_domain. (this comes pretty close to the usual
-DPRG_NAME= or -DLIBRARY_NAME= that is used in many projects).
basically, g_warning and friends stay the same for the application programmer,
but for libraries like gtk or gdk, their specific behaviour can be tweaked
through a -DG_LOGGER_QUARK=something switch, i don't consider that inherently
evil...
> 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
>
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]