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]

Re: thanks


On Sun, 5 Dec 1999, Han-Wen Nienhuys wrote:

> as an aside, as the gh_ interface is more high-level, I expected it to
> do more typechecking, but was disappointed. Are there any thoughts on
> providing an interface that doesn't dump core when you pass it the
> wrong type of argument?

The problem with this is, that if you have to use a different interface,
you will have to change your code after debugging in order to get the best
possible performance.  On the other hand, providing extensive type
checking as a default within libguile (independent of whether this is done 
in the gh_ or the scm_ part of the library) will also not be desired by
many users.


To address the problem that Han-Wen has pointed out, in the following I
suggest two (of probably millions) of possible approaches.


One possible solution might be something like:

fscm_car(...)  /* fscm = fast scm */
{
    don't do any type checking at all
}

sscm_car(...)  /* sscm = secure scm */
{
    perform extensive type checking on the parameters and then call
    fscm_car(...);
}

#ifdef GUILE_RUN_TIME_TYPE_CHECKING_MODE
#define scm_car sscm_car
#else
#define scm_car fscm_car
#endif

Some advantages of this approach:
* transparent for user code
* type checking can be switched on / off for a whole application as well
  as for single files / functions only.
* a single library is used 
* within guile, fscm or sscm can be called explicitly.

Some disadvantages:
* don't know about how this works with SCM_PROC
* it doubles the number of functions in the library:  for each function
  there will be a fscm and a sscm version
* it triples the number of functions in the interface, since for each
  function there is the scm, fscm and sscm version.
* You have to recompile your code to activate run time type checking.



An alternative solution is to provide a libguile with extensive type
checking compiled in, and another one without.  The library with type
checking enabled will only be used by developers, thus for guile users
there will only have to be one single library installed.

scm_car(...)
{
#ifdef GUILE_RUN_TIME_TYPE_CHECKING_MODE
    perform extensive type checking on the parameters
#endif
    perform the function without doing any type checking.
}

Some advantages:
* transparent for user code
* no recompilation necessary
* one single interface

Some disadvantages:
* Type checking is enabled / disabled for the whole application
* Developers will have to provide two libraries
* No explicit distinction between type safe and non type safe functions is
  possible.  This could be a disadvantage for guile internals, because
  guile itself should never be allowed to segfault.  Thus, certain type
  checks will have to be done explicitly at some points within guile.


Dirk Herrmann


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