« Return to Thread: Recognizing the same objects

Re: Recognizing the same objects

by Daniel K. O.-2 :: Rate this Message:

Reply to Author | View in Thread

2008/5/15 Dustin J. Mitchell <dustin@...>:
> I had similar difficulties with Perl bindings.
>
> The basic answer is, "no."  SWIG's bindings will create a new Python
> object every time they are handed a pointer from the C/C++ layer.
>
> You can work around this by writing typemaps that will keep some kind
> of (weak-ref) dictionary of extant wrapped objects, and look up any
> new pointer values in that dictionary.  SWIG doesn't implement this
> itself as it's really fairly domain-specific.


I was hoping for something along these lines:

struct Foo {
    void *data;
    ...
};

And make the [SWIG] Foo constructor store a pointer to the SWIG object
in the [C++] Foo object. So the getFoo() function would be overwritten
as:

SwigFoo* getFooSwig()
{
    Foo *f = getFoo();
    swigobj = f->data;
    return swigobj;
}

Could this be done with the help of typemaps?


--
Daniel K. O.
"The only way to succeed is to build success yourself"

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: Recognizing the same objects

LightInTheBox - Buy quality products at wholesale price