Haoyu Bai | 1 Mar 2009 09:16
Picon

Re: SWIG Tutorial: Python access to My_variable

On Thu, Feb 26, 2009 at 4:31 AM, Carl Schumann <schumann <at> fnal.gov> wrote:
> Hi,
>
> I am looking at the SWIG Tutorial (http://www.swig.org/tutorial.html).
> My interest is Python.   The Python example shows how to access the 3
> functions in the example but not the variable, My_variable.   (The perl
> and Java examples show how to access both the functions and variable.)
> How does one access the variable in the case of Python.   The obvious
> example.My_variable does not seem to be the answer:
>> Python 2.3.4 (#1, Dec 10 2007, 15:05:56)
>> [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> import example
>> >>> example.fact(6)
>> 720
>> >>> example.My_variable
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>> AttributeError: 'module' object has no attribute 'My_variable'
>> >>>
> Any guidance would be appreciated please.
>
> Thanks,
> Carl Schumann
>

Hi,

By default global variables will be put into an object called cvar. In
your case, you should access example.cvar.My_variable. For more
(Continue reading)

Kosta Krauth | 1 Mar 2009 20:02
Picon
Gravatar

JAVA performance tweaking, 2D arrays (matrices) and typemaps

As a part of my final year project in college, I am creating several
test-cases to assess the feasibility of running high performance gpgpu
algorithms from java (wrapped using swig). The question that poses
itself is - does the swig performance hit diminish the benefits of
using the GPU. As a disclaimer, I am a beginner when it comes to swig
so my attempts at writing interface files are very basic :)

The first test I created for sorting does not fare too well with my
(probably naive) swig interface config. On average, it takes roughly
350ms to execute the call to the native method. Due to this, the
benefits only start to show themselves with datasets that exceed 10
million elements. I would like to think that there is a way to improve
this.

I have tried searching for performance tips on the swig documentation
site and the only thing I could find was to use

%typemap(javafinalize) SWIGTYPE ""

when manipulating huge arrays of complex objects. Using this directive
didn't change anything in my particular case. Considering I don't do
any manipulation, but rather send the array pointer and then wait for
the native method to perform the manipulation, this should be a rather
simple thing to do.

In a hope to simplify the whole process I looked at the
INPUT/OUTPUT/INOUT directives to use with my parameters. However, this
didn't introduce any performance benefits either. Here are the
interfaces I tried:

(Continue reading)

Lubomir Konstantinov | 1 Mar 2009 20:54
Picon

Re: JAVA performance tweaking, 2D arrays (matrices) and typemaps

350ms is *alot* to execute a JNI call. I guess that the problem is
with accessing the array elements from the C++ code. Try allocating a
direct ByteBuffer, stick the data in it and then pull it out on the
C++ side.

Cheers,
Lubo

On Sun, Mar 1, 2009 at 9:02 PM, Kosta Krauth <kosta.krauth <at> gmail.com> wrote:
> As a part of my final year project in college, I am creating several
> test-cases to assess the feasibility of running high performance gpgpu
> algorithms from java (wrapped using swig). The question that poses
> itself is - does the swig performance hit diminish the benefits of
> using the GPU. As a disclaimer, I am a beginner when it comes to swig
> so my attempts at writing interface files are very basic :)
>
> The first test I created for sorting does not fare too well with my
> (probably naive) swig interface config. On average, it takes roughly
> 350ms to execute the call to the native method. Due to this, the
> benefits only start to show themselves with datasets that exceed 10
> million elements. I would like to think that there is a way to improve
> this.
>
> I have tried searching for performance tips on the swig documentation
> site and the only thing I could find was to use
>
> %typemap(javafinalize) SWIGTYPE ""
>
> when manipulating huge arrays of complex objects. Using this directive
> didn't change anything in my particular case. Considering I don't do
(Continue reading)

Justin Holewinski | 1 Mar 2009 22:41
Picon

Python 3.0.1 Error

I am trying to use SWIG with Python 3.0.1, but the generated wrapper code is not compiling against the Python 3.0.1 API.  GCC gives the following errors:

MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigObject_type()’:
MyClass_wrap.cxx:1747: error: invalid conversion from ‘PyObject* (*)(PyObject*)’ to ‘void*’
MyClass_wrap.cxx:1772: error: ‘cmpfunc’ was not declared in this scope
MyClass_wrap.cxx:1772: error: expected `}' before ‘SwigPyObject_compare’
MyClass_wrap.cxx:1772: error: expected ‘,’ or ‘;’ before ‘SwigPyObject_compare’
MyClass_wrap.cxx:1818: error: ‘tmp’ was not declared in this scope
MyClass_wrap.cxx: At global scope:
MyClass_wrap.cxx:1825: error: expected unqualified-id before ‘return’
MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigPacked_type()’:
MyClass_wrap.cxx:1943: error: ‘cmpfunc’ was not declared in this scope
MyClass_wrap.cxx:1943: error: expected `}' before ‘SwigPyPacked_compare’
MyClass_wrap.cxx:1943: error: expected ‘,’ or ‘;’ before ‘SwigPyPacked_compare’
MyClass_wrap.cxx:1989: error: ‘tmp’ was not declared in this scope
MyClass_wrap.cxx: At global scope:
MyClass_wrap.cxx:1996: error: expected unqualified-id before ‘return’
MyClass_wrap.cxx:1997: error: expected declaration before ‘}’ token


Visual Studio 2008 gives similar errors.  I am invoking Swig as follows:

$ /path/to/swig -c++ -python -py3 -Wall MyClass.i


I have tried this with Swig 1.3.38 and the SVN trunk (revision 11141), and Python 3.0.1 and Stackless Python 3.0.1.

Any ideas?  Am I passing the wrong arguments to Swig?


Thanks!

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Brian Cole | 1 Mar 2009 23:10
Favicon

Re: JAVA performance tweaking, 2D arrays (matrices) and typemaps

Are you sure SWIG is causing the overhead? Pushing computation off to the GPU is not free, you need to take into account the time to transfer the memory to and from the device, as well as other GPU kernel launch overheads. That being said, 350ms is the largest GPU overhead I’ve heard of.

Profile the code to make sure the bottleneck is really in the SWIG interface.

-Brian

On 3/1/09 12:02 PM, "Kosta Krauth" <kosta.krauth <at> gmail.com> wrote:

As a part of my final year project in college, I am creating several
test-cases to assess the feasibility of running high performance gpgpu
algorithms from java (wrapped using swig). The question that poses
itself is - does the swig performance hit diminish the benefits of
using the GPU. As a disclaimer, I am a beginner when it comes to swig
so my attempts at writing interface files are very basic :)

The first test I created for sorting does not fare too well with my
(probably naive) swig interface config. On average, it takes roughly
350ms to execute the call to the native method. Due to this, the
benefits only start to show themselves with datasets that exceed 10
million elements. I would like to think that there is a way to improve
this.

I have tried searching for performance tips on the swig documentation
site and the only thing I could find was to use

%typemap(javafinalize) SWIGTYPE ""

when manipulating huge arrays of complex objects. Using this directive
didn't change anything in my particular case. Considering I don't do
any manipulation, but rather send the array pointer and then wait for
the native method to perform the manipulation, this should be a rather
simple thing to do.

In a hope to simplify the whole process I looked at the
INPUT/OUTPUT/INOUT directives to use with my parameters. However, this
didn't introduce any performance benefits either. Here are the
interfaces I tried:

%module parallel_sort
%include "typemaps.i"
%{
extern void sort(float *array, int num_elements);
%}
extern void sort(float *INOUT, int num_elements);

and

%module parallel_sort
%include <arrays_java.i>
%apply float[] {float *array}
%{
       #include "parallel_sort.h"
%}

%include "parallel_sort.h"

The header file simply contained: void sort(float *array, int num_elements);

Both resulting libraries had equivalent performance. At this point I'm
running out of ideas. Would having 2 array pointers (one pointing to
input array and one to resulting array) improve things? The fact that
I don't need to do array manipulation, but simply submit it to the
native method and then wait for it to complete the results, indicate
that there should be a way to indicate this to swig, resulting in a
(hopefully) sleeker and faster interface.

As for my second question - does swig have a typemap for primitive 2d
arrays? I could not find one in arrays_java.i, and it seems like a
relatively common thing that might be used since all matrices are
represented as 2d arrays. Could you give me any pointers as to how a
float* -> float[][] might be implemented?

Any tips, hints, pointers would be most welcome as I am presently
stuck! Many thanks in advance and thank you for having the patience to
read through!

Kosta Krauth

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Kosta Krauth | 1 Mar 2009 23:24
Picon
Gravatar

Re: JAVA performance tweaking, 2D arrays (matrices) and typemaps

Hi Brian,
you are correct, it was not SWIG that was causing the delay but rather
the setup time of the CUDA library that occurs during the first
cudamalloc command. The real set-up time is more along the lines of
170ms, but yes, pretty bad as you noted yourself. I found several
posts in the NVIDIA forums where people were quoting similar times, so
I guess it's not uncommon. The workaround was obviously to do a dummy
malloc once the library is first called. Subsequent calls were
executed nearly instantly, more along the lines of what is expected.
It still takes around 20ms to make a blank call with 1 million floats
to the native method, but that's more than a tenfold increase in
performance so I'll live with it :)

Considering that's off the plate, any suggestions regarding
implementation of a 2d array (matrix) of primitives?

Thanks for all the help so far!!

On Sun, Mar 1, 2009 at 7:02 PM, Kosta Krauth <kosta.krauth <at> gmail.com> wrote:
> As a part of my final year project in college, I am creating several
> test-cases to assess the feasibility of running high performance gpgpu
> algorithms from java (wrapped using swig). The question that poses
> itself is - does the swig performance hit diminish the benefits of
> using the GPU. As a disclaimer, I am a beginner when it comes to swig
> so my attempts at writing interface files are very basic :)
>
> The first test I created for sorting does not fare too well with my
> (probably naive) swig interface config. On average, it takes roughly
> 350ms to execute the call to the native method. Due to this, the
> benefits only start to show themselves with datasets that exceed 10
> million elements. I would like to think that there is a way to improve
> this.
>
> I have tried searching for performance tips on the swig documentation
> site and the only thing I could find was to use
>
> %typemap(javafinalize) SWIGTYPE ""
>
> when manipulating huge arrays of complex objects. Using this directive
> didn't change anything in my particular case. Considering I don't do
> any manipulation, but rather send the array pointer and then wait for
> the native method to perform the manipulation, this should be a rather
> simple thing to do.
>
> In a hope to simplify the whole process I looked at the
> INPUT/OUTPUT/INOUT directives to use with my parameters. However, this
> didn't introduce any performance benefits either. Here are the
> interfaces I tried:
>
> %module parallel_sort
> %include "typemaps.i"
> %{
> extern void sort(float *array, int num_elements);
> %}
> extern void sort(float *INOUT, int num_elements);
>
> and
>
> %module parallel_sort
> %include <arrays_java.i>
> %apply float[] {float *array}
> %{
>       #include "parallel_sort.h"
> %}
>
> %include "parallel_sort.h"
>
> The header file simply contained: void sort(float *array, int num_elements);
>
> Both resulting libraries had equivalent performance. At this point I'm
> running out of ideas. Would having 2 array pointers (one pointing to
> input array and one to resulting array) improve things? The fact that
> I don't need to do array manipulation, but simply submit it to the
> native method and then wait for it to complete the results, indicate
> that there should be a way to indicate this to swig, resulting in a
> (hopefully) sleeker and faster interface.
>
> As for my second question - does swig have a typemap for primitive 2d
> arrays? I could not find one in arrays_java.i, and it seems like a
> relatively common thing that might be used since all matrices are
> represented as 2d arrays. Could you give me any pointers as to how a
> float* -> float[][] might be implemented?
>
> Any tips, hints, pointers would be most welcome as I am presently
> stuck! Many thanks in advance and thank you for having the patience to
> read through!
>
> Kosta Krauth
>

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Haoyu Bai | 2 Mar 2009 06:08
Picon

Re: Python 3.0.1 Error

On Mon, Mar 2, 2009 at 5:41 AM, Justin Holewinski <shawmishrak <at> gmail.com> wrote:
> I am trying to use SWIG with Python 3.0.1, but the generated wrapper code is
> not compiling against the Python 3.0.1 API.  GCC gives the following errors:
>
> MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigObject_type()’:
> MyClass_wrap.cxx:1747: error: invalid conversion from ‘PyObject*
> (*)(PyObject*)’ to ‘void*’
> MyClass_wrap.cxx:1772: error: ‘cmpfunc’ was not declared in this scope
> MyClass_wrap.cxx:1772: error: expected `}' before ‘SwigPyObject_compare’
> MyClass_wrap.cxx:1772: error: expected ‘,’ or ‘;’ before
> ‘SwigPyObject_compare’
> MyClass_wrap.cxx:1818: error: ‘tmp’ was not declared in this scope
> MyClass_wrap.cxx: At global scope:
> MyClass_wrap.cxx:1825: error: expected unqualified-id before ‘return’
> MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigPacked_type()’:
> MyClass_wrap.cxx:1943: error: ‘cmpfunc’ was not declared in this scope
> MyClass_wrap.cxx:1943: error: expected `}' before ‘SwigPyPacked_compare’
> MyClass_wrap.cxx:1943: error: expected ‘,’ or ‘;’ before
> ‘SwigPyPacked_compare’
> MyClass_wrap.cxx:1989: error: ‘tmp’ was not declared in this scope
> MyClass_wrap.cxx: At global scope:
> MyClass_wrap.cxx:1996: error: expected unqualified-id before ‘return’
> MyClass_wrap.cxx:1997: error: expected declaration before ‘}’ token
>
>
> Visual Studio 2008 gives similar errors.  I am invoking Swig as follows:
>
> $ /path/to/swig -c++ -python -py3 -Wall MyClass.i
>
>
> I have tried this with Swig 1.3.38 and the SVN trunk (revision 11141), and
> Python 3.0.1 and Stackless Python 3.0.1.
>
> Any ideas?  Am I passing the wrong arguments to Swig?
>
>
> Thanks!
>

Hi,

I have regularly run SWIG's test suite with Python 3.x's SVN checkout,
and there's no such errors. Could you try to run it with Python 2.x
and see if there are still errors? And you may remove the -py3 option,
then the generated code can be compiled with both Python 2.x and 3.x.

-- Haoyu Bai

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
Justin Holewinski | 2 Mar 2009 06:31
Picon

Re: Python 3.0.1 Error

The errors do not occur with Python 2.6.1 and 2.7 (SVN trunk), nor with Stackless Python 2.6.1.  The error does occur with Python 3.0.1 (release or Python 3.0 SVN branch), Python 3.1 (SVN branch), and Stackless Python 3.0.1, all built from source.

At least one of the problems seems to be the lack of a cmpfunc typedef in Python 3.x.  I don't know the Python C API well enough to know what exactly changed, but most of the compile errors are a result of this missing typedef.  However, even if I manually insert that typedef, I still get a couple of the compile errors, namely the first one.

The SWIG/Python examples also fail to build with the same errors if I target a 3.x installation of Python.  These are with unmodified Python distributions from python.org and/or stackless.com.

On Mon, Mar 2, 2009 at 12:08 AM, Haoyu Bai <divinekid <at> gmail.com> wrote:
On Mon, Mar 2, 2009 at 5:41 AM, Justin Holewinski <shawmishrak <at> gmail.com> wrote:
> I am trying to use SWIG with Python 3.0.1, but the generated wrapper code is
> not compiling against the Python 3.0.1 API.  GCC gives the following errors:
>
> MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigObject_type()’:
> MyClass_wrap.cxx:1747: error: invalid conversion from ‘PyObject*
> (*)(PyObject*)’ to ‘void*’
> MyClass_wrap.cxx:1772: error: ‘cmpfunc’ was not declared in this scope
> MyClass_wrap.cxx:1772: error: expected `}' before ‘SwigPyObject_compare’
> MyClass_wrap.cxx:1772: error: expected ‘,’ or ‘;’ before
> ‘SwigPyObject_compare’
> MyClass_wrap.cxx:1818: error: ‘tmp’ was not declared in this scope
> MyClass_wrap.cxx: At global scope:
> MyClass_wrap.cxx:1825: error: expected unqualified-id before ‘return’
> MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigPacked_type()’:
> MyClass_wrap.cxx:1943: error: ‘cmpfunc’ was not declared in this scope
> MyClass_wrap.cxx:1943: error: expected `}' before ‘SwigPyPacked_compare’
> MyClass_wrap.cxx:1943: error: expected ‘,’ or ‘;’ before
> ‘SwigPyPacked_compare’
> MyClass_wrap.cxx:1989: error: ‘tmp’ was not declared in this scope
> MyClass_wrap.cxx: At global scope:
> MyClass_wrap.cxx:1996: error: expected unqualified-id before ‘return’
> MyClass_wrap.cxx:1997: error: expected declaration before ‘}’ token
>
>
> Visual Studio 2008 gives similar errors.  I am invoking Swig as follows:
>
> $ /path/to/swig -c++ -python -py3 -Wall MyClass.i
>
>
> I have tried this with Swig 1.3.38 and the SVN trunk (revision 11141), and
> Python 3.0.1 and Stackless Python 3.0.1.
>
> Any ideas?  Am I passing the wrong arguments to Swig?
>
>
> Thanks!
>

Hi,

I have regularly run SWIG's test suite with Python 3.x's SVN checkout,
and there's no such errors. Could you try to run it with Python 2.x
and see if there are still errors? And you may remove the -py3 option,
then the generated code can be compiled with both Python 2.x and 3.x.

-- Haoyu Bai

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Justin Holewinski | 2 Mar 2009 06:52
Picon

Re: Python 3.0.1 Error

Minimal compilation commands:

[jholewinski <at> cerberus swig1]$ /usr/local/swig-trunk/bin/swig -c++ -python -Wall MyClass.i
[jholewinski <at> cerberus swig1]$ g++ -I/usr/local/python-3.0.1/include/python3.0 -c MyClass_wrap.cxx -o MyClass_wrap.o
MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigObject_type()’:
MyClass_wrap.cxx:1747: error: invalid conversion from ‘PyObject* (*)(PyObject*)’ to ‘void*’
MyClass_wrap.cxx:1772: error: ‘cmpfunc’ was not declared in this scope
MyClass_wrap.cxx:1772: error: expected `}' before ‘SwigPyObject_compare’
MyClass_wrap.cxx:1772: error: expected ‘,’ or ‘;’ before ‘SwigPyObject_compare’
MyClass_wrap.cxx:1818: error: ‘tmp’ was not declared in this scope
MyClass_wrap.cxx: At global scope:
MyClass_wrap.cxx:1825: error: expected unqualified-id before ‘return’
MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigPacked_type()’:
MyClass_wrap.cxx:1943: error: ‘cmpfunc’ was not declared in this scope
MyClass_wrap.cxx:1943: error: expected `}' before ‘SwigPyPacked_compare’
MyClass_wrap.cxx:1943: error: expected ‘,’ or ‘;’ before ‘SwigPyPacked_compare’
MyClass_wrap.cxx:1989: error: ‘tmp’ was not declared in this scope
MyClass_wrap.cxx: At global scope:
MyClass_wrap.cxx:1996: error: expected unqualified-id before ‘return’
MyClass_wrap.cxx:1997: error: expected declaration before ‘}’ token
[jholewinski <at> cerberus swig1]$


Interface file  (MyClass.i):

%module MyModule
%{
#include <string>
#include "MyClass.hpp"
%}

%include "MyClass.hpp"


Class header file  (MyClass.hpp):

class MyClass
{
public:

  MyClass();
  ~MyClass();

  const std::string& GetString() const;
  void SetString(const std::string& str);

private:

  std::string m_data;
};



If you need more detail, let me know which GCC flags you want to see.

Thanks for the help!


On Mon, Mar 2, 2009 at 12:36 AM, Haoyu Bai <divinekid <at> gmail.com> wrote:
On Mon, Mar 2, 2009 at 1:31 PM, Justin Holewinski <shawmishrak <at> gmail.com> wrote:
> The errors do not occur with Python 2.6.1 and 2.7 (SVN trunk), nor with
> Stackless Python 2.6.1.  The error does occur with Python 3.0.1 (release or
> Python 3.0 SVN branch), Python 3.1 (SVN branch), and Stackless Python 3.0.1,
> all built from source.
>
> At least one of the problems seems to be the lack of a cmpfunc typedef in
> Python 3.x.  I don't know the Python C API well enough to know what exactly
> changed, but most of the compile errors are a result of this missing
> typedef.  However, even if I manually insert that typedef, I still get a
> couple of the compile errors, namely the first one.
>
> The SWIG/Python examples also fail to build with the same errors if I target
> a 3.x installation of Python.  These are with unmodified Python
> distributions from python.org and/or stackless.com.
>
> On Mon, Mar 2, 2009 at 12:08 AM, Haoyu Bai <divinekid <at> gmail.com> wrote:
>>
>> On Mon, Mar 2, 2009 at 5:41 AM, Justin Holewinski <shawmishrak <at> gmail.com>
>> wrote:
>> > I am trying to use SWIG with Python 3.0.1, but the generated wrapper
>> > code is
>> > not compiling against the Python 3.0.1 API.  GCC gives the following
>> > errors:
>> >
>> > MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigObject_type()’:
>> > MyClass_wrap.cxx:1747: error: invalid conversion from ‘PyObject*
>> > (*)(PyObject*)’ to ‘void*’
>> > MyClass_wrap.cxx:1772: error: ‘cmpfunc’ was not declared in this scope
>> > MyClass_wrap.cxx:1772: error: expected `}' before ‘SwigPyObject_compare’
>> > MyClass_wrap.cxx:1772: error: expected ‘,’ or ‘;’ before
>> > ‘SwigPyObject_compare’
>> > MyClass_wrap.cxx:1818: error: ‘tmp’ was not declared in this scope
>> > MyClass_wrap.cxx: At global scope:
>> > MyClass_wrap.cxx:1825: error: expected unqualified-id before ‘return’
>> > MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigPacked_type()’:
>> > MyClass_wrap.cxx:1943: error: ‘cmpfunc’ was not declared in this scope
>> > MyClass_wrap.cxx:1943: error: expected `}' before ‘SwigPyPacked_compare’
>> > MyClass_wrap.cxx:1943: error: expected ‘,’ or ‘;’ before
>> > ‘SwigPyPacked_compare’
>> > MyClass_wrap.cxx:1989: error: ‘tmp’ was not declared in this scope
>> > MyClass_wrap.cxx: At global scope:
>> > MyClass_wrap.cxx:1996: error: expected unqualified-id before ‘return’
>> > MyClass_wrap.cxx:1997: error: expected declaration before ‘}’ token
>> >
>> >
>> > Visual Studio 2008 gives similar errors.  I am invoking Swig as follows:
>> >
>> > $ /path/to/swig -c++ -python -py3 -Wall MyClass.i
>> >
>> >
>> > I have tried this with Swig 1.3.38 and the SVN trunk (revision 11141),
>> > and
>> > Python 3.0.1 and Stackless Python 3.0.1.
>> >
>> > Any ideas?  Am I passing the wrong arguments to Swig?
>> >
>> >
>> > Thanks!
>> >
>>
>> Hi,
>>
>> I have regularly run SWIG's test suite with Python 3.x's SVN checkout,
>> and there's no such errors. Could you try to run it with Python 2.x
>> and see if there are still errors? And you may remove the -py3 option,
>> then the generated code can be compiled with both Python 2.x and 3.x.
>>
>> -- Haoyu Bai
>
>

That's strange. Could you post the detailed commands you used to swig
and compile it?

Also, it it better if you can attach a full output of gcc (or send it
to me off-list.)

Thanks!

-- Haoyu Bai

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Haoyu Bai | 2 Mar 2009 06:36
Picon

Re: Python 3.0.1 Error

On Mon, Mar 2, 2009 at 1:31 PM, Justin Holewinski <shawmishrak <at> gmail.com> wrote:
> The errors do not occur with Python 2.6.1 and 2.7 (SVN trunk), nor with
> Stackless Python 2.6.1.  The error does occur with Python 3.0.1 (release or
> Python 3.0 SVN branch), Python 3.1 (SVN branch), and Stackless Python 3.0.1,
> all built from source.
>
> At least one of the problems seems to be the lack of a cmpfunc typedef in
> Python 3.x.  I don't know the Python C API well enough to know what exactly
> changed, but most of the compile errors are a result of this missing
> typedef.  However, even if I manually insert that typedef, I still get a
> couple of the compile errors, namely the first one.
>
> The SWIG/Python examples also fail to build with the same errors if I target
> a 3.x installation of Python.  These are with unmodified Python
> distributions from python.org and/or stackless.com.
>
> On Mon, Mar 2, 2009 at 12:08 AM, Haoyu Bai <divinekid <at> gmail.com> wrote:
>>
>> On Mon, Mar 2, 2009 at 5:41 AM, Justin Holewinski <shawmishrak <at> gmail.com>
>> wrote:
>> > I am trying to use SWIG with Python 3.0.1, but the generated wrapper
>> > code is
>> > not compiling against the Python 3.0.1 API.  GCC gives the following
>> > errors:
>> >
>> > MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigObject_type()’:
>> > MyClass_wrap.cxx:1747: error: invalid conversion from ‘PyObject*
>> > (*)(PyObject*)’ to ‘void*’
>> > MyClass_wrap.cxx:1772: error: ‘cmpfunc’ was not declared in this scope
>> > MyClass_wrap.cxx:1772: error: expected `}' before ‘SwigPyObject_compare’
>> > MyClass_wrap.cxx:1772: error: expected ‘,’ or ‘;’ before
>> > ‘SwigPyObject_compare’
>> > MyClass_wrap.cxx:1818: error: ‘tmp’ was not declared in this scope
>> > MyClass_wrap.cxx: At global scope:
>> > MyClass_wrap.cxx:1825: error: expected unqualified-id before ‘return’
>> > MyClass_wrap.cxx: In function ‘PyTypeObject* _PySwigPacked_type()’:
>> > MyClass_wrap.cxx:1943: error: ‘cmpfunc’ was not declared in this scope
>> > MyClass_wrap.cxx:1943: error: expected `}' before ‘SwigPyPacked_compare’
>> > MyClass_wrap.cxx:1943: error: expected ‘,’ or ‘;’ before
>> > ‘SwigPyPacked_compare’
>> > MyClass_wrap.cxx:1989: error: ‘tmp’ was not declared in this scope
>> > MyClass_wrap.cxx: At global scope:
>> > MyClass_wrap.cxx:1996: error: expected unqualified-id before ‘return’
>> > MyClass_wrap.cxx:1997: error: expected declaration before ‘}’ token
>> >
>> >
>> > Visual Studio 2008 gives similar errors.  I am invoking Swig as follows:
>> >
>> > $ /path/to/swig -c++ -python -py3 -Wall MyClass.i
>> >
>> >
>> > I have tried this with Swig 1.3.38 and the SVN trunk (revision 11141),
>> > and
>> > Python 3.0.1 and Stackless Python 3.0.1.
>> >
>> > Any ideas?  Am I passing the wrong arguments to Swig?
>> >
>> >
>> > Thanks!
>> >
>>
>> Hi,
>>
>> I have regularly run SWIG's test suite with Python 3.x's SVN checkout,
>> and there's no such errors. Could you try to run it with Python 2.x
>> and see if there are still errors? And you may remove the -py3 option,
>> then the generated code can be compiled with both Python 2.x and 3.x.
>>
>> -- Haoyu Bai
>
>

That's strange. Could you post the detailed commands you used to swig
and compile it?

Also, it it better if you can attach a full output of gcc (or send it
to me off-list.)

Thanks!

-- Haoyu Bai

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H

Gmane