chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] non-finalized object in SWIG


From: John Lenz
Subject: Re: [Chicken-users] non-finalized object in SWIG
Date: Tue, 06 Jun 2006 09:15:13 -0500
User-agent: Thunderbird 1.5.0.2 (X11/20060521)

Daishi Kato wrote:
> To SWIG experts,
> 
> My question is if it is possible to create
> an object that is not garbage collected.
> DISOWN can be specified to input typemaps,
> but can an object that is created by a constructor
> be DISOWNed?

Yes, if you pass an object that was originally created by a constructor
(and is marked for garbage collection), the DISOWN typemap will remove
it from the garbage collector.  The typemap basically just calls
C_do_unregister_finalizer(s)

> 
> I would like to have sort of output typemaps with DISOWN.
> 
> Note that I'm not yet used to SWIG, but it looks pretty nice.
> Daishi
> 
>

Perhaps the easiest way would be to create a helper function:  something
like

%inline %{
Foo *makeFoo(...) {
  return new Foo(...);
}
%}

SWIG assumes by default that pointers that are returned from functions
are not added for garbage collection.  You have to specifically add a
%newobject tag to functions when you want the return value to be
collected.  (Note that from SWIGs point of view, a constructor is just
another function, except that SWIG automatically adds the %newobject tag
to constructors)

You could play some games with the definition of this function on the
chicken/scheme side too, so the helper looks like the real constructor.
(define old-new-Foo new-Foo) (set! new-Foo makeFoo)

John





reply via email to

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