Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## swig-user

 [Swig-user] invalid pointers(?) when using two wrapped modules From: Sébastien Barthélémy - 2012-02-23 17:18:24 ```Dear all, we have two python wrapped modules: almath and almathinternal. The latter extends the former with a few functions related to convex hull computation. You've already heard about the first in my yesterday email. We noticed some strange behaviour while using both modules at the same time: the values of some basic wrapped type from almath (Position2D, a strct with x and y float members) change from themselves. Here is an example (alas, the real example which triggers this problem is more complicated, and my attempts to simplify it always make the problem vanish). def someComputation(in): tmp = in[1:] out = [] for p in tmp: out.append(p) out[0] = almath.Position2D(1,2) # this element will have thisown == True myprint(out) # print the good values return out a = almathinternal.vectorFloat(...); b = almathinternal.getConvexHullGraham(a) # b's type is almathinternal.vectorFloat. Its elements have thisown == False c = someComputation(b) myprint(c) # print wrong values The elements whose thisown attribute is false will see their values change between two print (myprint(out) and myprint(c)). For instance for an element, I'll get on the first print:: x=-4.97260951996, y=-0.522642314434 thisown=False this=_9084b30200000000_p_std__vectorT_AL__Math__Position2D_std__allocatorT_AL__Math__Position2D_t_t__value_type on the second print: x=2.33959356674e-37, y=0.0 thisown=False this=_9084b30200000000_p_std__vectorT_AL__Math__Position2D_std__allocatorT_AL__Math__Position2D_t_t__value_type I guess to pointer to the underlying C++ object get invalidated in the meantime. Any other possibility ? That seems odd yet, since, from my understanding of the swig documentation, swig would not try to free objects it does not own. I checked the .i files, and noticed the two modules are wrapped independently: almathinternal.i does not %import almath.i I fixed that and also removed some std::vector instantiations which were wrapped twice, and the problem vanished. Here is the patch to almathinternal.i %module almathinternal +%import "almath.i" %feature("autodoc", "1"); %{ #include "almathinternal/collisions/convexhull.h" #include "almathinternal/collisions/convexhullgraham.h" %} %include "almathinternal/collisions/convexhull.h" %include "almathinternal/collisions/convexhullgraham.h" -%include "std_vector.i" -namespace std { - %template(vectorFloat) vector; - %template(vectorPosition2D) vector; -} - So, my problem is apparently solved, but I'd like to understand the matter a little more, just to be reassured it won't resurface latter. Especially since I have not succeeded yet in creating a simple test case. Also, the return type of getConvexHullGraham changed, it was a vectorPosition2D, it now a tuple of Position2D. Maybe we're just circumventing the problem now. How could I investigate this further? Where should I look? I'd gladly welcome any hint! Cheers -- Sébastien ```
 Re: [Swig-user] invalid pointers(?) when using two wrapped modules From: Sébastien Barthélémy - 2012-02-23 18:01:21 ```2012/2/23 Sébastien Barthélémy : > Also, the return type of getConvexHullGraham changed, it was a > vectorPosition2D, it now a tuple of Position2D. > Maybe we're just circumventing the problem now. Well, I just checked that point. If I convert the tuple to a vectorPosition2D and then run the computations as before, the corruption happens again. Sounds like nothing was fixed ;( I'll keep you posted. -- Sébastien ```