This is the mail archive of the guile@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: Guile, C, and Garbage Collection


>>>>> "Mikael" == Mikael Djurfeldt <mdj@nada.kth.se> writes:

    Mikael> Include a "handle" pointing back to the Scheme level
    Mikael> object in every C struct.  This way, C level objects can
    Mikael> refer to each other directly by C pointers, but the
    Mikael> garbage collector can still find the corresponding Scheme
    Mikael> level wrapper objects (the smobs):

And to give complete guile independence for the poor saps who want it,
you could go so far as to:

struct foo {
#ifdef HAVE_GUILE
  SCM handle;
#endif
  ...
  struct bar *bar;
  ...
};

struct bar {
#ifdef HAVE_GUILE
  SCM handle;
#endif
  ...
};


As Marius pointed out, reference counting can have some problems if
there is the possibility of circular reference loops, and in the
particular application that I'm thinking about (sewn parametric
surfaces) circular references are almost unavoidable.  So the design
suggested by Mikael above is quite compelling.

Daniel