After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 61228 - Fatal warnings env variable
Fatal warnings env variable
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
1.3.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2001-09-26 15:44 UTC by Havoc Pennington
Modified: 2011-02-18 15:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
the patch (5.35 KB, patch)
2002-02-09 19:59 UTC, Matthias Clasen
none Details | Review

Description Havoc Pennington 2001-09-26 15:44:16 UTC
I want to add an environment variable to GLib which sets 
fatal warnings, then set this in the session manager for the entire 
GNOME 2 development cycle, so all apps crash noticeably on warning.

(This bug is a reminder to myself to do it.)
Comment 1 Owen Taylor 2001-09-26 19:26:25 UTC
Please assign this to a milestone.
Comment 2 Matthias Clasen 2002-01-17 13:11:58 UTC
Wouldn't it be nicer to have one GLIB_DEBUG envvar, similar
to GTK_DEBUG/GDK_DEBUG/GRUNTIME_DEBUG instead of scattering
debug envvars throughout the code ? The win32 port already
has some obscure debugging envvars which should be cleaned
up as well if we go for GLIB_DEBUG.
Comment 3 Owen Taylor 2002-01-23 21:05:16 UTC
A debug var makes sense, but would be more expensive than 
it is for GTK+, etc, since "G_NOTE()" would have to:

 - Lock a global lock
 - Check to see if we've parsed the debug var before
 - If not, parse it
 - Unlock the global lock

As long as we don't use this in any fast path code (GHashTable,
g_malloc()) the penalty for --enable-debug shouldn't be bad,
however, and without --enable-debug it wouldn't matter.

The main disadvantage of the "debug environment variable" setup
is that it would only be availalble for --enable-debug builds,
though I suppose we could parse the debug vars unconditionally
and only make G_NOTE conditional.

Putting on 2.0.1, since it's only convenience functionality,
and not entirely trivial.



Comment 4 Matthias Clasen 2002-01-24 15:49:17 UTC
Wouldn't this be faster and still correct ?

Check to see if we've parsed the debug var before
If not,
   Lock a global lock
   Check to see if we've parsed the debug var before
   If not, parse it
   Unlock the global lock
Use the parsed value

The "parsed value" is written only once, so this should be ok.
Comment 5 Owen Taylor 2002-01-24 16:27:38 UTC
Consider the case where you have processor B hitting the
code while processor A initializing. There is no guarantee
that processor B won't see the "initialized flag" written
to memory _before_ the value of the debug flags is written
to memory, even if A writes them in the correct order.

But there is actually an easy thing to do... just make
sure that g_thread_init() always causes the debug
envvar to be parsed; we _do_ have an init function in the
threaded case, just not in the non-threaded case.
Comment 6 Matthias Clasen 2002-01-24 16:34:11 UTC
I was kind of assuming that the "parsed value" and the 
"initialized flag" could be the same thing and could be written
atomically. But of course, doing the thing in g_thread_init()
sounds like a clever way out.
Comment 7 Sebastian Wilhelmi 2002-01-24 16:37:27 UTC
We had this discussion before.

Whenever there is cache coherency guaranteed, then you can rely on
that. I don't think, GLib will be ported to a non-cache-coherency
platform any time soon. 

The best solution probably is to introduce GOnce, which does something
along the lines of pthread_once_t and works optimized for the current
platform (i.e. for a set of known platforms uses the method of avoid
locking in the common poth) and falls back to full locking in case of
an unknown platform.

Sounds like 2.2 stuff.

BTW: Of course the pragmatic solution to parse it at g_thread_init
time (preferably from within g_messages_init to increase the locality)
is fine for the time being.
Comment 8 Owen Taylor 2002-01-24 17:53:41 UTC
This isn't quite the discussion we had before; it's case that
is somewhat more likely to break because we aren't talking
about:

 pointer A => newly allocated structure B

But rather:

 integer A
 integer B

I believe the second case _will_ break on a number of
currently available reasonably common architectures.
Anyways, pretty irrelevant to this bug.
Comment 9 Sebastian Wilhelmi 2002-01-25 14:49:14 UTC
The case

 pointer A => newly allocated structure B

might seem different, than

 integer A
 integer B

but if you cross a memory barrier between setting B to a new value and
setting A to "B is written", it is essentially the same, I'd say.

But as you pointed out, this quite irrelevant to this bug. 

I'll however add a wishlist future bug to add GOnce to nicly do things.





Comment 10 Matthias Clasen 2002-01-26 20:10:51 UTC
Speaking about g_messages_init, shouldn't the parsing of
G_MESSAGES_PREFIXED be done in there as well, so that the lock
can be removed from g_log_write_prefix ?
Comment 11 Havoc Pennington 2002-01-26 20:53:11 UTC
Moving the G_MESSAGES_PREFIXED parsing sounds fine to me.
Comment 12 Matthias Clasen 2002-02-09 19:58:32 UTC
Here's a patch which does the lock-removing for the message prefix
stuff and adds generic support for a GLIB_DEBUG envvar. Currently
the only recognized debug flag is "fatal_warnings" with the same
meaning as --g-fatal-warnings and with the extra twist that it
is effective even if compiled without G_DEBUG (the G_NOTE macro
in the new header gdebug.h, however, is vacuous in that case).
Comment 13 Matthias Clasen 2002-02-09 19:59:28 UTC
Created attachment 6669 [details] [review]
the patch
Comment 14 Owen Taylor 2002-02-21 19:31:49 UTC
Looks good to commit. Except that 

 - gdebug.h should not be installed (put it in SOURCES
   rather than HEADERS)
 - g_debug_init(), g_debug_initialized(), g_debug_flags()
   should all be _g_debug_* and not exported.
 - Need to add gdebug.h to IGNORE_HFILES in the docs

And would be better to avoid adding the trailing new
lines on files.
Comment 15 Matthias Clasen 2002-02-21 23:11:42 UTC
Committed with your corrections and with documentation. I ended
up naming the envvar G_DEBUG instead of GLIB_DEBUG for consistency
with the other G_ prefixed envvars.