This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Suggestion for debugging options.


Hello everybody.

I'd like to suggest the following idea:

* Debugging options in guile are macros prefixed with SCM_DEBUG_
* They are always defined and have to be either 0 or 1
* By default, they are 0.

Currently, these options are prefixed with GUILE_, which is in contrast to
our claim to only use the SCM_ namespace.  Further, the fact that a
debugging option is enabled is encoded by the distinction between whether
the corresponding macro is defined or not forces us to use a lot of #ifdef 
#endif nestings, which makes some code very hard understandable.  Also,
within macros such information can not be used.

In contrast, instead of:

#ifdef GUILE_DEBUG_MALLOC
  some_code();
#else
  some_other_code();
#endif

with the above proposal we could write:

  if (SCM_DEBUG_MALLOC)
    some_code();
  else
    some_other_code();

which is easier to read, can even be part of a macro and will compile to
the same code, since the compiler will eliminate the dead 
branch.  Especially the fact that macros then can contain references to
debug options will allow for more flexibility.

For example, the current way interrupts are tested is

#ifdef SCM_CAREFUL_INTS
#define SCM_CHECK_NOT_DISABLED \
  if (scm_ints_disabled) \
    fputs("ints already disabled\n", stderr); \
#else
#define SCM_CHECK_NOT_DISABLED
#endif

#define SCM_DEFER_INTS \
do { \
  SCM_FENCE; \
  SCM_CHECK_NOT_DISABLED; \
  SCM_THREAD_DEFER; \
  SCM_FENCE; \
  scm_ints_disabled = 1; \
  SCM_FENCE; \
} while (0)

Then it would be:

#define SCM_CHECK_NOT_DISABLED \
  if (scm_ints_disabled) \
    fputs("ints already disabled\n", stderr); \

#define SCM_DEFER_INTS \
do { \
  SCM_FENCE; \
  if (SCM_DEBUG_CRITICAL_SECTIONS) \
    SCM_CHECK_NOT_DISABLED; \
  SCM_THREAD_DEFER; \
  SCM_FENCE; \
  scm_ints_disabled = 1; \
  SCM_FENCE; \
} while (0)

which I personally find easier to read.  And, since the nature of
SCM_DEBUG_ macros is clearly defined, it is easier to see when checks are
actually performed by looking at SCM_DEFER_INTS.

Best regards
Dirk Herrmann


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]