chicken-users
[Top][All Lists]
Advanced

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

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


From: John Lenz
Subject: Re: about DISOWN (Re: [Chicken-users] non-finalized object in SWIG
Date: Fri, 30 Jun 2006 01:01:47 -0500
User-agent: Thunderbird 1.5.0.4 (X11/20060615)

Daishi Kato wrote:
> Hi,
> 
> Sorry that I can't help much with the compilation errors.
> 
> I have another question.
> Is it possible to specify a DISOWN typemap
> outside of the class definition.
> 
> The following works:
> class Foo{
> %apply SWIGTYPE *DISOWN {Bar bar};
>   void Foo(Bar bar);
> %clear Bar bar;
> };
> 
> What I would like to do is like this:
> %apply SWIGTYPE *DISOWN {Foo::Foo(Bar bar)};
> class Foo{
>   void Foo(Bar bar);
> };
> 

For the details on how typemaps are matched, see
http://www.swig.org/Doc1.3/Typemaps.html
mainly the section "Pattern matching rules"

No.  Typemaps are just that... they are defined and stored and whatever
based on types.  As such, the DISOWN typemap is slightly different than
most typemaps in that you want it to "encode" a property of the
parameter instead of the type itself.  There are several possible
solutions...

1) Since typemaps encode properties of types and not parameters, change
the type of the parameter to reflect this.  For example:

typedef Bar BarDisown;
%apply SWIGTYPE *DISOWN { BarDisown * };

and then everywhere in the .i file you use BarDisown instead of Bar.

2) SWIG provides a very basic way to match on the parameter, but only
based on name.  So instead of applying all those things, you can just
write code like

class Foo {
  void Foo(Bar DISOWN);
};

where the name of the parameter is DISOWN.  SWIG will use the DISOWN
typemap for this, no need to add any apply or clear or anything.  If you
don't like the name, you can do something like

%apply SWIGTYPE *DISOWN { SWIGTYPE *hey };

and just use hey everywhere.

3) Could encode DISOWN as a %feature instead of as a typemap.  Features
encode properties of parameters (and classes) instead of types, and so
you have to specify the feature for every function or class (just like
you want).  So you could do something like

%delobject Foo::Foo();
%delobject *::add_container();

The %feature (which is what %delobject is) is very powerful at applying
marks to specific functions and such.

This was recently added in SWIG version 1.3.28, but has not yet been
implemented for Chicken (it works for python).  See the section:
http://www.swig.org/Doc1.3/Customization.html#ownership
and that whole chapter on how %feature works.  I might look into
supporting this for chicken, If you would like to use it...

John




reply via email to

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