lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GC question


From: Erik Sandberg
Subject: Re: GC question
Date: Thu, 18 Aug 2005 10:03:22 +0200
User-agent: KMail/1.8.1

On Wednesday 17 August 2005 16.08, Han-Wen Nienhuys wrote:
> Erik Sandberg wrote:
> > Hi,
> >
> > Does anyone know if it is safe to call scm_gc_unprotect_object inside the
> > destructor of a smob? I know it sounds a bit weird to do so, but it's the
> > cleanest solution I can find to a problem.
>
> it will generate an error in GUILE 1.7 CVS. This should never be
> necessary anyway.

It's related to mixing smobs and non-smobs.

A non-smob class A has a reference to a smob B. A makes sure to gc_protect B, 
and in A's destructor, B is gc_unprotected. (I don't see another way of 
saving B from GC.)

class A {
  SCM b_;
  A() { b_ = get_b (); scm_gc_protect_object (b_); }
  ~A() { scm_gc_unprotect_object (b_); }
  ...
};

Now if a third smob C contains an A object, as in

class C {
  A a_;
  ...
  DECLARE_SMOBS (C);
};

.. then A's gc_unprotect will be called during the gc sweep.

Is my problem related to the smob macros in Lilypond? (if not, I should ask on 
guile-user instead).

-- 
Erik




reply via email to

[Prev in Thread] Current Thread [Next in Thread]