swig

How to properly downcast in C# with a SWIG generated interface?

I've got a very large and mature C++ code base that I'm trying to use SWIG on to generate a C# interface for. I cannot change the actual C++ code itself but we can use whatever SWIG offers in the way of extending/updating it. I'm facing an issue where a C++ function that is written as below is causing issues in C#. A* SomeClass::next(...

Python crashes when plotting with matplotlib in module importing swig generated wrapper

I have a python module that imports a module generated with swig. When I try to call the show() function of matplotlib later in that module, python crashes without any hint, what went wrong. When I comment the import statement with the swig generated module out, everything works fine. Does anybody have a clue to what could be the reason ...

SWIG: C++ to C#, pointer to pointer marshalling.

I have some legacy code I want to port to C#. I cannot modify the C++ code, I just have to make do with what I'm given. So, the situation. I'm using SwIG, and I came across this function: void MarshalMe(int iNum, FooClass** ioFooClassArray); If I ran SWIG over this, it wouldn't know what to do with the array, so it will create a SWIG...

Easiest way of unit testing C code with Python

I've got a pile of C code that I'd like to unit test using Python's unittest library (in Windows), but I'm trying to work out the best way of interfacing the C code so that Python can execute it (and get the results back). Does anybody have any experience in the easiest way to do it? Some ideas include: Wrapping the code as a Python C...

SWIG: Python list to uint32_t *?

I'm trying to work with a Python module that was generated by SWIG. There's a C++ class defined that works like this (simplified): namespace Foo { class Thing { public: Thing(); ~Thing(); bool DoSomething(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer); }; }; When I try to call it from P...

Allowing threads from python after calling a blocking i/o code in a python extension generated using SWIG

I have written a python extension wrapping an existing C++ library live555 (wrapping RTSP client interface to be specific) in SWIG. The extension works when it is operated in a single thread, but as soon as I call the event loop function of the library, python interpreter never gets the control back. So if I create a scheduled task using...

Error with swig: undefined symbol: _ZN7hosters11hostersLink7getLinkEi

I'm trying to make a python binding for the this library: http://code.google.com/p/hosterslib/. I'm using swig, heres is the code: %module pyhosters %{ #include "hosters/hosters.hpp" %} %include "hosters/hosters.hpp" I run swig -c++ -python -o swig_wrap.cxx swig.i and I compile with g++ -O2 -fPIC -shared ...

SWIG: C++ to C# ... Arrays and new objects

I have asked a similar question somewhere else, but I still cannot find a good answer (see http://stackoverflow.com/questions/2479764/swig-c-to-c-pointer-to-pointer-marshalling ). First answer did comment on typemap, but actual error message (yes, it is a memory issue, but it is because P/Invoke is not marshalling properly) I'm currentl...

How to wrap a C function whose parameters are pointer to structs, so that it can be called from Lua?

I have the follwing C function. How should I wrap it so it can be called from a Lua script? typedef struct tagT{ int a ; int b ; } type_t; int lib_a_f_4(type_t *t) { return t->a * t->b ; } I know how to wrapr it if the function parameter type were int or char *. Should I use table type for a C structure? EDIT: I am usi...

c struct map to ruby using SWIG

Hi, Is there any body can confirm the description here is true? My experience is that I can not use Example::Vector.new at all. C/C++ structs are wrapped as Ruby classes, with accessor methods (i.e. "getters" and "setters") for all of the struct members. For example, this struct declaration: struct Vector { double x, y; }...

How to stringfy a swig matrix object in python

Hi, I am using swig wrapper of openbabel (written in C++, and supply a python wrapper through swig) Below i just use it to read a molecule structure file and get the unitcell property of it. import pybel for molecule in pybel.readfile('pdb','./test.pdb'): unitcell = molecule.unitcell print unitcell |..> |..> <o...

handling refrence to pointers/double pointers using SWIG [C++ to Java]

My code has an interface like class IExample { ~IExample(); //pure virtual methods ...}; a class inheriting the interface like class CExample : public IExample { protected: CExample(); //implementation of pure virtual methods ... }; and a global function to create object of this class - createExample( IExample *& obj ) { obj = new ...

SWIG generated code fails to run on PHP 5.3.2 undefined symbol: zend_error_noreturn

I have a library that I have been using successfully with PHP 5.1.6 with the help of some wrapper code generated by SWIG (v1.3.40). I have just upgraded to PHP 5.3.2 and I am seeing the following error: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/myLib_php.so' - /usr/lib/php/modules/myLib_php.so: und...

SWIG and Javascript: does embedding the JVM/Rhino into my C++ app is still the only solution?

I really like the idea of automatic binding generation like SWIG does. But it is still lacking Javascript binding. I read that it could not be done with Spidermonkey because of the JS Context that must be passed as parameter to each function. The only solution I found is to embed a JVM into my C++ application, generating bindings to Ja...

wrapp a function whose parameters are out type pointer to structure using swig

I have following function : typedef struct tagT{ int a ; int b ; }Point; int lib_a_f_5(Point *out_t) { out_t->a = 20; out_t->b = 30; return 0; } How should I direct the SWIG to generate the correct code for ruby (or lua)? When putting following statement to the interface file : %apply SWIGTYPE Point* {Point *out_t}; I got a warn...

PHP to C/C++ through CGI script

Hi guys! I realize it's probably something strange, but here is what I have. I have an application (handwriting recognition engine) written in C/C++. This application has Perl wrapper which was made by application's authors using SWIG. My website is written in PHP, so I'm looking for some ways to make PHP work with C/C++ application. ...

How do I conditionally compile C code snippets to my Perl module?

I have a module that will target several different operating systems and configurations. Sometimes, some C code can make this module's task a little easier, so I have some C functions that I would like to bind the code. I don't have to bind the C functions -- I can't guarantee that the end-user even has a C compiler, for instance, and it...

How to link as .so instead of .dylib on OSX 10.6 using qmake

Hey everyone, I am trying to use SWIG to wrap some C++ code for the use with Python. As described here it seems to be necessary to link my C++ code against an .so file, not a .dylib file. The thread suggests to use libtool in combination with the -module flag to link, but I am using qmake and need more precise instructions on how I do t...

Python: Is there a way to reflectivly list all attributes of a class

Given a class such as class MyClass: text = "hello" number = 123 Is there a way in python to inspect MyClass an determine that it has the two attributes text and number. I can not use something like inspect.getSource(object) because the class I am to get it's attributes for are generate using SWIG (so they are hidden in .so :)...

Several numpy arrays with SWIG

I am using SWIG to pass numpy arrays from Python to C++ code: %include "numpy.i" %init %{ import_array(); %} %apply (float* INPLACE_ARRAY1, int DIM1) {(float* data, int n)}; class Class { public: void test(float* data, int n) { //... } }; and in Python: c = Class() a = zeros(5) c.test(a) This works, but how can I pa...