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
_______________________________________________
Chicken-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-users