Hi all,

 

A colleague and I have run into an issue with generating Python wrappers for C++ code when we make use of the global namespace operator. The problem occurs using the latest code from SVN (as well as the last 2.0.x release) and can be reproduced very simply. Given the following C++ code:

 

class Foo {};

 

::Foo* CreateFoo1() { return new Foo; }

Foo* CreateFoo2() { return new Foo; }

 

And the following .i file:

 

%module test

 

%{

#include "test.h"

%}

 

%include "test.h"

 

Running swig with the command “swig -python -c++ -O test.i” generates wrapper code without incident. This code then compiles against Python 2.7 using g++, again without incident. We then use the code from a Python script as follows:

 

import test

print "CreateFoo1:", test.CreateFoo1()

print "CreateFoo2:", test.CreateFoo2()

 

This gives the following output:

 

CreateFoo1: <Swig Object of type '::Foo *' at 0x7fed7860>

CreateFoo2: <test.Foo; proxy of <Swig Object of type 'Foo *' at 0x7fed7860> >

 

You can see that CreateFoo1 has returned a raw pointer wrapper instead of the proxy class as we would have expected. The correct behavior is recovered by removing the global namespace operator (as demonstrated by CreateFoo2). We cannot remove the global namespace operator from our C++ code due to potential name conflicts, but we also need the wrapper to correctly return the proxy class.

 

Any help would be greatly appreciated,

Ben