Problems with shared_ptr and Python

View: New views
5 Messages — Rating Filter:   Alert me  

Problems with shared_ptr and Python

by andreas.held :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

I am trying to wrap shared_ptr code and I have run into some problems.
Running the following code through swig gives an exception:

%module example

%include <boost_shared_ptr.i>
SWIG_SHARED_PTR(Foo, Foo)

%inline %{
#include <boost/shared_ptr.hpp>
using boost::shared_ptr;
struct Foo {};
void test1(shared_ptr<Foo> f) {}
//void test2(boost::shared_ptr<Foo> f) {}
%}

My command line looks like:
swig -IC:/boost_1_40_0 -python example.i

and I am using swigwin-1.3.40 and boost-1.40.0

The exception I get looks like this:

$ swig -IC:/boost_1_40_0 -python example.i
example.i(5): Error: Syntax error in input(1).

Obviously I am doing something wrong but cannot figure out what the problem is. Does anybody have a minimum example that should work? Incidentally, trying the example fro the test suite (li_boost_shared_ptr.i) gives the same exception.

Best regards

Andreas

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Problems with shared_ptr and Python

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

andreas.held@... wrote:

> Hi
>
> I am trying to wrap shared_ptr code and I have run into some problems.
> Running the following code through swig gives an exception:
>
> %module example
>
> %include <boost_shared_ptr.i>
> SWIG_SHARED_PTR(Foo, Foo)
>
> %inline %{
> #include <boost/shared_ptr.hpp>
> using boost::shared_ptr;
> struct Foo {};
> void test1(shared_ptr<Foo> f) {}
> //void test2(boost::shared_ptr<Foo> f) {}
> %}
>
> My command line looks like:
> swig -IC:/boost_1_40_0 -python example.i
Should be:
swig -c++ -python example.i

>
> and I am using swigwin-1.3.40 and boost-1.40.0
>
> The exception I get looks like this:
>
> $ swig -IC:/boost_1_40_0 -python example.i
> example.i(5): Error: Syntax error in input(1).
>
> Obviously I am doing something wrong but cannot figure out what the problem is. Does anybody have a minimum example that should work? Incidentally, trying the example fro the test suite (li_boost_shared_ptr.i) gives the same exception.
>

I can't replicate that error using swig-1.3.40, try the correct command
line options given above.

William

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Parent Message unknown Re: Problems with shared_ptr and Python

by andreas.held :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi William

Thank you for your quick reply. Sorry for my mistake in the command line. As you pointed out, the correct command line should be:
swig -c++ -python example.i

Still, even with that command line I do get the same error. I now stronly suspect that something is wrong with my boost installation. Anyway, I have now found a way around my problem by using
%template

This works fine and swig rocks again for me.

Best regards

Andreas

---- William S Fulton <wsf@...> schrieb:

> andreas.held@... wrote:
> > Hi
> >
> > I am trying to wrap shared_ptr code and I have run into some problems.
> > Running the following code through swig gives an exception:
> >
> > %module example
> >
> > %include <boost_shared_ptr.i>
> > SWIG_SHARED_PTR(Foo, Foo)
> >
> > %inline %{
> > #include <boost/shared_ptr.hpp>
> > using boost::shared_ptr;
> > struct Foo {};
> > void test1(shared_ptr<Foo> f) {}
> > //void test2(boost::shared_ptr<Foo> f) {}
> > %}
> >
> > My command line looks like:
> > swig -IC:/boost_1_40_0 -python example.i
> Should be:
> swig -c++ -python example.i
>
> >
> > and I am using swigwin-1.3.40 and boost-1.40.0
> >
> > The exception I get looks like this:
> >
> > $ swig -IC:/boost_1_40_0 -python example.i
> > example.i(5): Error: Syntax error in input(1).
> >
> > Obviously I am doing something wrong but cannot figure out what the problem is. Does anybody have a minimum example that should work? Incidentally, trying the example fro the test suite (li_boost_shared_ptr.i) gives the same exception.
> >
>
> I can't replicate that error using swig-1.3.40, try the correct command
> line options given above.
>
> William


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Problems with shared_ptr and Python

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

andreas.held@... wrote:
> Hi William
>
> Thank you for your quick reply. Sorry for my mistake in the command line. As you pointed out, the correct command line should be:
> swig -c++ -python example.i
>
> Still, even with that command line I do get the same error. I now stronly suspect that something is wrong with my boost installation.
It is impossible for SWIG to be affected by your boost installation
unless you tell it to via an include path (the -I option). However,
there might be a problem when your c++ compiler compiles the generated
code, as that will then use your boost installation.

> Anyway, I have now found a way around my problem by using
> %template
>
I don't know what you are doing wrong, but the SWIG_SHARED_PTR macro
invokes the %template directive for you. I think you need to post your
non-working example again.

William

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Parent Message unknown Re: Problems with shared_ptr and Python

by andreas.held :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi William

This is my interface file boost_example.i:
%module example
 
// For plain classes, do not use for derived classes
%include "boost_shared_ptr.i"
MY_SWIG_SHARED_PTR(Foo, Foo)

struct Foo {};
void test1(shared_ptr<Foo> f) {}
void test2(boost::shared_ptr<Foo> f) {}

-----------------------------------------------------------

My command line:

$ swig -c++ -python boost_example.i
boost_example.i(6): Error: Syntax error in input(1).

I do get the same results whether I run the command from a MSYS shell or from the Windows Power Shell, obviously, both on Windows (XP to be accurate).

Finally, the version I am using:
$ swig -version

SWIG Version 1.3.40

Compiled with i586-mingw32msvc-g++ [i686-pc-linux-gnu]
Please see http://www.swig.org for reporting bugs and further information


Best regards and thanks for your help.

Andreas
---- William S Fulton <wsf@...> schrieb:

> andreas.held@... wrote:
> > Hi William
> >
> > Thank you for your quick reply. Sorry for my mistake in the command line. As you pointed out, the correct command line should be:
> > swig -c++ -python example.i
> >
> > Still, even with that command line I do get the same error. I now stronly suspect that something is wrong with my boost installation.
> It is impossible for SWIG to be affected by your boost installation
> unless you tell it to via an include path (the -I option). However,
> there might be a problem when your c++ compiler compiles the generated
> code, as that will then use your boost installation.
>
> > Anyway, I have now found a way around my problem by using
> > %template
> >
> I don't know what you are doing wrong, but the SWIG_SHARED_PTR macro
> invokes the %template directive for you. I think you need to post your
> non-working example again.
>
> William


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user