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: Unwanted hook names (was Re: interface reductions)


On 26 May 2000, Keisuke Nishida wrote:

> How about the following set of functions and a macro?
> 
> SCM scm_c_make_hook (int n_args);
> void scm_c_set_object_name (SCM obj, const char *name);
> void scm_c_environment_define (SCM env, const char *name, SCM obj);

That's (almost) what I was thinking of.  Remembering also Greg's and
Marius' point about the nice debugging features if objects get a name by
default, we could think of a debugging option SCM_DEBUG_OBJECT_NAMES,
which in debugging mode gives all objects created by snarf macros the
corresponding names (just an idea:  it's either stupid or could even be 
improved on...).  The functions for creating bindings in some
environment are, however, already defined and implemented by Jost.  But,
the separation of object creation and binding might be helpful in
combination with the new environments and with any future work on the
environment and module system:  a) Different concepts are no longer
intermingled.  b) if there are new options and parameters necessary to
create a binding, we don't have to change all object-creating interfaces,
since these don't have anything to do with it any more.

> #define SCM_DEFINE_HOOK(CNAME, ENV, SNAME, NARGS, DOCS) \
> SCM_SNARF_DECL(                                         \
>   SCM CNAME                                             \
> )                                                       \
> SCM_SNARF_INIT(                                         \
>   CNAME = scm_c_make_hook (NARGS);                      \
>   scm_c_set_object_name (CNAME, SNAME);                 \
>   scm_c_environment_define (ENV, SNAME, CNAME);         \
> )                                                       \
> SCM_SNARF_DOCS(...)
> 
> scm_c_environment_define will call scm_protect_object if necessary.

Actually, I wouldn't want scm_c_environment_define (I don't know how this
will be called with the new environments) to protect the object:  You 
only need to protect objects that are referenced by C variables that are
not visible to the gc.  However, the function scm_c_environment_define may
also be called if there is no global C variable binding created.  Thus, it
should be the responsibility of SCM_DEFINE_HOOK to do this.  My suggestion
thus is: 


extern SCM scm_symbol_name;   /* holds 'name */

#define SCM_SET_OBJECT_NAME(object, name) \
  do { \
    if (SCM_DEBUG_OBJECT_NAMES) \
      scm_set_object_property_x (object, scm_symbol_name, name); \
  } while (0)

#define SCM_DEFINE_HOOK(CNAME, ENV, SNAME, NARGS, DOCS) \
SCM_SNARF_DECL(                                         \
  SCM CNAME                                             \
)                                                       \
SCM_SNARF_INIT(                                         \
  CNAME = scm_c_make_hook (NARGS);                      \
  SCM_SET_OBJECT_NAME (CNAME, SNAME);                   \
  scm_c_environment_define (ENV, SNAME, CNAME);         \
  scm_protect_object (CNAME);                           \
)                                                       \
SCM_SNARF_DOCS(...)


Just a couple of probably not well thought out ideas.

Best regards
Dirk Herrmann


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