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 544026 - environment variable based assertion checking
environment variable based assertion checking
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-07-21 16:26 UTC by Allison Karlitskaya (desrt)
Modified: 2018-05-24 11:29 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Allison Karlitskaya (desrt) 2008-07-21 16:26:40 UTC
we have this G_DISABLE_CHECKS business and it's all well and good except that you need to decide at compile time -of the library- if you want the checking.

i want to be able to decide to have no checking when using my system normally and lots of checking when developing.

maybe you think you can push its use out to header files something like this:

.h:

#ifdef G_DISABLE_CHECKS
#define g_something _g_something_unchecked
#else
#define g_something _g_something_checked
#endif

void _g_something_unchecked (void);
void _g_something_checked (void);

.c:
void _g_something_checked (void)
{
  g_assert (...);
  _g_something_unchecked ();
}

void _g_something_unchecked (void)
{
  ...
}

but this is insane and doesn't completely solve the problem anyway: if you have a library stack then the debugging is decided by what flags the library was compiled with.




far better, i think, would be a mechanism to base this all on an environment variable.  maybe something like G_DEBUG=expensive-checks to set some global variable g_debug_perform_expensive_checks.  we could then go like:


.c:

void
g_something (void)
{
  if (G_UNLIKELY (g_debug_perform_expensive_checks))
    {
      g_assert (...);
      g_assert (...);
    }

  ...
}


maybe we can even have some macro support for this:

void
g_something (void)
{
  G_BEGIN_EXPENSIVE_CHECKS
    g_assert (...);
    g_assert (...);
  G_END_EXPENSIVE_CHECKS;

  ...
}

the only problem with this is that there is no glib init function, so who sets up the global variable?  we could replace the variable with a function or with a macro like

#define G_EXPENSIVE_CHECKS_ENABLED \
  G_STMT_START {
    if (G_UNLIKELY (g_debug_perform_expensive_checks_checked == FALSE))
      {
        g_debug_perform_expensive_checks_checked = TRUE;
        g_debug_perform_expensive_checks = do_the_check();
      }
  } G_STMT_END

the problem with this, of course, is that you get this machinary embedded in every single function that wants to do expensive checks......

maybe it's low enough overhead just to have a simple function call........

feedback?
Comment 1 GNOME Infrastructure Team 2018-05-24 11:29:11 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/150.