Karim Bernardet | 2 Jan 2009 14:48
Picon

swig, gloox and python

Hi

I am trying to use a python version of gloox (XMPP client library 
written in C++). The python binding is done using SWIG (provided by the 
author of gloox and I made minor fixes). I am trying to adapt first a 
c++ example to python.

The code below fails with

Traceback (most recent call last):
  File "tutu.py", line 54, in ?
    t.run()
  File "tutu.py", line 28, in run
    self.f = gloox.SIProfileFT( self.c, self )
  File 
"/home/karim/boulot/gliders/archi/project//lib/python2.4/site-packages/gloox/gloox.py", 
line 1965, in __init__
    this = _gloox.new_SIProfileFT(*args)
NotImplementedError: Wrong number of arguments for overloaded function 
'new_SIProfileFT'.
  Possible C/C++ prototypes are:
    gloox::SIProfileFT(gloox::ClientBase *,gloox::SIProfileFTHandler 
*,gloox::SIManager *,gloox::SOCKS5BytestreamManager *)
    gloox::SIProfileFT(gloox::ClientBase *,gloox::SIProfileFTHandler 
*,gloox::SIManager *)
    gloox::SIProfileFT(gloox::ClientBase *,gloox::SIProfileFTHandler *)

If I comment gloox.LogHandler.__init__( self ) (and 
self.c.logInstance().registerLogHandler( gloox....), it "works".
The order to initialize the objects seems to be important. The error can 
(Continue reading)

Mathieu Malaterre | 2 Jan 2009 15:54
Picon

Re: Automatically generated callbacks using directors (python)

Carlos,

  Those macros look awesome. I was looking on how to deal with c++
callback and python and could not find any documentation.

Un-usable, you need to define you callback in the .i file (could
someone give me a practical example!):
http://www.swig.org/Doc1.3/SWIG.html#SWIG_nn30

Looks completely outdated:
http://www.swig.org/Doc1.1/HTML/Python.html#n11

swig comes with an example, but with a funky syntax (thisown=0 /
.disown() and you still need to explicitely delete the callback),
clearly not user oriented.

2008/8/31 Carlos Pita <carlosjosepita <at> gmail.com>:
> Hi all,
>
> I've hacked up a couple of macros for automatically generating
> callbacks that I'd like to share with you because I know it's a
> recurrent subject here.
>
> The idea behind the macros is simple: implement the callback as a
> virtual method of a class, implement this method in python, and let c
> call it through its director. Actually, the callback is implemented as
> a python callable and then wrapped into a virtual method for you, so
> you don't need to mess with a mere implementation concern. The macros
> that implement all this are not that complex at all, they just hide
> the details.
(Continue reading)

Mathieu Malaterre | 6 Jan 2009 11:04
Picon

Re: Python and float *[]

On Mon, Dec 29, 2008 at 8:30 PM, Bryan Rockwood
<bryan.rockwood <at> raytheon.com> wrote:
> Greetings,
>
> I am new to SWIG and would appreciate an idea or two on how to handle
> data that is to be passed to a C function.  Specifically, I am trying to
> get this function to work with Python and NUMPY objects.  In this case,
> two of the variables in the C function are of type 'float *[]' which is
> an array of pointers to 1D arrays.  What is the best way to handle that
> in the interface file?  Any pointers would be appreciated (pun
> intended).  Thank you in advance.

Have you read:

http://matt.eifelle.com/2008/11/04/exposing-an-array-interface-with-swig-for-a-cc-structure/

HTH
--

-- 
Mathieu

------------------------------------------------------------------------------
Richard Prescott | 6 Jan 2009 21:50
Picon

problem with %typemap and %extend

Hello everybody,

I am new to the list and haven't found my answer elsewhere so I guess it is the best place here for asking...

It looks to me that typemaps are not respected for method created within %extend.  I have attached an exemple showing that.  It is generated using SWIG 1.3.33.  I just hope I have done something wrong and someone here will point me out my error or show me a workaround.

Thanks in advance for helping.  It is appreciated.

Regards

Richard

Attachment (test.i): application/octet-stream, 915 bytes
------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
William S Fulton | 6 Jan 2009 21:57
Picon
Favicon
Gravatar

Re: problem with %typemap and %extend

Richard Prescott wrote:
> Hello everybody,
> 
> I am new to the list and haven't found my answer elsewhere so I guess it 
> is the best place here for asking...
> 
> It looks to me that typemaps are not respected for method created within 
> %extend.  I have attached an exemple showing that.  It is generated 
> using SWIG 1.3.33.  I just hope I have done something wrong and someone 
> here will point me out my error or show me a workaround.
> 
> Thanks in advance for helping.  It is appreciated.
> 
>
Have you tried putting the typemap before the declaration of the structs?

William

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
Justin Bayer | 7 Jan 2009 12:40
Gravatar

Example from the webpage not working

Hi group,

I started playing with swig today, but unfortunately the tutorial does
not work for me. I am using Mac OS 10.5, Python 2.6.1, Swig 1.3.35 and
am on a 64 bit machine.

This is what happens after running the example:

$ python -c "import example"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "example.py", line 7, in <module>
    import _example
ImportError: dlopen(./_example.so, 2): no suitable image found.  Did find:
	./_example.so: can't map

Any ideas on this issue? Also, is there an irc channel? #swig on
freenode did not get me any usable results, since it's used by
different people. ;)

Regards,
-Justin

--

-- 
P.S.: No Dogs!

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
David Beazley | 7 Jan 2009 14:56

Re: Example from the webpage not working

Have you tried running the examples in the SWIG-1.3.35/Examples/python/simple directory?

Unless the tutorial is using the correct Macintosh linking/compiler options, it's unlikely
to work.  The examples that come with Swig should use the correct options.

Cheers,
Dave

On Wed 07/01/09  6:40 AM , "Justin Bayer" bayer.justin <at> googlemail.com sent:
> Hi group,
> 
> I started playing with swig today, but unfortunately the tutorial does
> not work for me. I am using Mac OS 10.5, Python 2.6.1, Swig 1.3.35 and
> am on a 64 bit machine.
> 
> This is what happens after running the example:
> 
> $ python -c "import example"
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> File "example.py", line 7, in <module>
> import _example
> ImportError: dlopen(./_example.so, 2): no suitable image found.  Did
> find:./_example.so: can't map
> 
> Any ideas on this issue? Also, is there an irc channel? #swig on
> freenode did not get me any usable results, since it's used by
> different people. ;)
> 
> 
> Regards,
> -Justin
> 
> 
> 
> 
> 
> 
> 
> -- 
> P.S.: No Dogs!
> 
> ---------------------------------------------------------------------------
> ---Check out the new SourceForge.net Marketplace.
> It is the best place to buy or sell services for
> just about anything Open Source.
> http://p.sf.net/sfu/Xq1LFB_______________________________________________
> Swig-user mailing list
> Swig-user <at> lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/swig-user
> 
> 

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
Justin Bayer | 7 Jan 2009 17:12
Gravatar

Using classes/functions/etc from a dynamic/shared library

Hi group,

I have a dynamic library on OS X which has some classes/functions that
I want to access from python. So far I have done the following:

mylib.i
---------------------------
%module mylib
%{
#include "mylib.h"
%}

class mylib::myclass;
#define BLUBB 1
---------------------------

then I run the following commands:

$ swig -Wall -python -c++ src/swig/arac.i
*snip*
$ gcc -lmylib -Lpath/to/mylib -c -Wno-long-double
src/swig/arac_wrap.cxx -I/path/to/mylib/headers
-I/usr/local/include/python2.6 -I/usr/local/lib/python2.6/config -o
mylib_wrap.o
*snip*
$ gcc -lmylib -Lpath/to/mylib -Wno-long-double -bundle -undefined
suppress -flat_namespace mylib_wrap.o -o _mylib.so
*snip*
$ python -c "import mylib; dir(mylib._mylib)"
['BLUBB', '__doc__', '__file__', '__name__', '__package__']

So myclass does not appear. What am I doing wrong?

Regards,
-Justin

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
David Beazley | 7 Jan 2009 17:38

Re: Using classes/functions/etc from a dynamic/sharedlibrary

Swig is not going to do anything unless you give it the actual definition of mylib::myclass.  The
declaration you have below is just a forward class declaration (which Swig just ignores 
because it provides no useful information).

Cheers,
Dave

On Wed 07/01/09 11:12 AM , "Justin Bayer" bayer.justin <at> googlemail.com sent:
> Hi group,
> 
> I have a dynamic library on OS X which has some classes/functions that
> I want to access from python. So far I have done the following:
> 
> mylib.i
> ---------------------------
> %module mylib
> %{
> #include "mylib.h"
> %}
> 
> class mylib::myclass;
> #define BLUBB 1
> ---------------------------
> 
> then I run the following commands:
> 
> $ swig -Wall -python -c++ src/swig/arac.i
> *snip*
> $ gcc -lmylib -Lpath/to/mylib -c -Wno-long-double
> src/swig/arac_wrap.cxx -I/path/to/mylib/headers
> -I/usr/local/include/python2.6 -I/usr/local/lib/python2.6/config -o
> mylib_wrap.o
> *snip*
> $ gcc -lmylib -Lpath/to/mylib -Wno-long-double -bundle -undefined
> suppress -flat_namespace mylib_wrap.o -o _mylib.so
> *snip*
> $ python -c "import mylib; dir(mylib._mylib)"
> ['BLUBB', '__doc__', '__file__', '__name__', '__package__']
> 
> So myclass does not appear. What am I doing wrong?
> 
> 
> Regards,
> -Justin
> 
> ---------------------------------------------------------------------------
> ---Check out the new SourceForge.net Marketplace.
> It is the best place to buy or sell services for
> just about anything Open Source.
> http://p.sf.net/sfu/Xq1LFB_______________________________________________
> Swig-user mailing list
> Swig-user <at> lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/swig-user
> 
> 

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
John Whitley | 7 Jan 2009 18:17
Favicon

Re: Using classes/functions/etc from adynamic/sharedlibrary

Note also that this doesn't have to be a complete class definition.  You
can provide a subset of the class declaration in your interface file
(mylib.i) to control which functionality you want to expose into the
target language (Python, in your example).  If you want all code in
mylib.h wrapped, then just use:

	%include "mylib.h"

instead of your forward declaration.

-- John

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB

Gmane