swig

SWIG passing argument to python callback fuction

Hi, So I'm almost done. Now I have working code which calls python callback function. Only thing I need now is how to pass argument to the python callback function. My callback.c is: #include <stdio.h> typedef void (*CALLBACK)(void); CALLBACK my_callback = 0; void set_callback(CALLBACK c); void test(void); void set_callback(CALLBA...

What purpose does the ~ operator have in this code?

I have digging through the C# code generated by SWIG for Quantlib and came across the following code that gave me a humbling moment. Each of the generated classes implement IDisposable, and each of the generated classes have this convention pointed out below. public class MultiPath : IDisposable { // MultiPath is interchangable priv...

is all the available swig+python+mingw compile information outdated?

I'm trying to build a C++ extension for python using swig. I've followed the instructions below and the others to a T and can't seem to get my extension to load. I ran across this article on the MinGW site under "How do I create Python extensions?" http://www.mingw.org/wiki/FAQ I also found these tutorials: http://boodebr.org/main/p...

auto_ptr with swig

Hi, I'm trying to wrap a C++ library which uses auto_ptr. I'm using swig and want to generate python bindings. I'v seen the section of the swig docu on how to use swig with smart pointers here[0]. But I can't get it to work. swig generates code that wants to initialize the auto_ptr using a const reference, but auto_ptr defines the cop...

swig + mono : C# example errors of not finding the library

I use swig 2.0.1 + mono 2.6/2.8 on Mac OS X 10.6.4. The overall build is OK, and the build of the C# examples is also OK. The problem is that when I run the example (mono runme.exe), I always get the following errors. Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for example...

System.EntryPointNotFoundException error in SWIG on mono 2.8

I asked about an error for running Swig examples on mono 2.8 here. Adding "-arch i386" solved the issue with simple example, but when I tried to run the other examples, I got the following error, for example, with Examples/csharp/variables : Unhandled Exception: System.EntryPointNotFoundException: CSharp_ivar_set at (wrapper manage...

SWIG + SCIPY = Import Error on PyArray_TYPE

Hey gang, so I've written a swig wrapper for some C code. I'm trying to bridge the gap between scipy arrays and C arrays, which I know is messy. After a clean compilation (well...not including some warnings...) I'm getting this issue when I load the python-swig-c module: undefined symbol: PyArray_TYPE I've added my swig interface file...

How do I down-cast a c++ object from a python SWIG wrapper?

The problem: I've wrapped some c++ code in python using SWIG. On the python side, I want to take a wrapped c++ pointer and down-cast it to be a pointer to a subclass. I've added a new c++ function to the SWIG .i file that does this down-casting, but when I call it from python, I get a TypeError. Here are the details: I have two c++ cl...

xapian-bindings python compatibility

hello, i am able to get xapian working as expected with python on my development server but i am having issues with my web server. i keep running into this error: import xapian Traceback (most recent call last): File "", line 1, in File "/home/x/lib/python2.6/xapian/init.py", line 28, in ...

SWIG: Ruby overloading problems

Hi, I have a sinatra web application and a C++ library that I can 'require' in sinatra (ruby) using bindings created by swig. I also have a second -very similar- library, in which the function names are partially the same as in the first one. When I require them both, the one that is loaded first 'wins', i.e. calls to the ambiguous fun...

How to wrap a <myClass*, myClass*> C++ dictionary using SWIG for Python and .NET

Hi, I'm wrapping C++ code into Python and .NET code by using SWIG 2.0.0. I'm able to wrap a (myClass*, std::string) by introducing the following sentence in the "interface.i" file: %template(Dictionary_myClass_String) std::map<myClass*, std::string>; But I'm getting several errors if i try this: %template(Dictionary_myClass_myClass)...

SWIG: C++, Python. Single Interface for different shared libraries(sharing common base class)

Environment : C++, Python, SWIG Problem : C++ : I have different shared library(.so) files which share common base class. SWIG: I can have a wrapper for each .so file & can use corresponding .py in python module. But, this makes lot of interface files & also lot of import statements in python. Expected: I would like to have best poss...

swig/python detected a memory leak... no destructor found - for enums!

This is about embedded python using swig. I have an std::map exposed to python (embedded python). When the script is executed, swig spits out the below "warning" at the end (when the map goes out of scope - I guess): swig/python detected a memory leak of type 'std::map< MyEnum, std::string> ... no destructor found The .i file is: en...

SWIG: Avoid name clashes

What is the best way to avoid name clashes in SWIG generated functions? I have two different C++ classes with partially identical function names. When I call such a function on an object, given both classes are loaded in the target language, it seems related to which library was loaded first, which function gets actually executed. It ha...

SWIG cross platform

My application is using SWIG to communicate between c++ and python on windows. suppose if my interface is "example.h" swig is generating example.py, example_wrap.cxx /* File : example.i */ %module example %{ #include "example.h" %} %include "std_string.i" %include "std_wstring.i" %include "example.h" I am porting my application ...

Python Swig wrapper: how access underlying PyObject

I've got class A wrapped with method foo implemented using %extend: class A { ... %extend { void foo() { self->foo_impl(); } } Now I want to increase ref count to an A inside foo_impl, but I only got A* (as self). Question: how can I write/wrap function foo, so that I have an access both to A* and underlying PyObject*...

How to compile Box2D for C# with SWIG?

I'm trying to compile Box2D for use in C# with SWIG. I've created this Box2D.i file, %module Box2D %{ #include "Box2D/Box2D.h" %} %include "Box2D/Box2D.h" Which I placed one level up from the Box2D.h file file, and "compiled" it with, swig.exe -csharp -c++ -includeall -ignoremissing -outdir SWIG Box2d.i This gives me all the .cs ...

Error when trying to price instrument when using Quantlib

I am receiving the following error when trying to price a 20x10 swap from a bootstrapped curve. The error get thrown on the last line of the ImpliedRate function SwapRatesServiceTests.ImpliedRate_ForTwenty_x_TenYearSwap_ReturnsRate: System.ApplicationException : 2nd leg: empty Handle cannot be dereferenced I don't have the faint...

python class inherits object

Is there any reason for a class declaration to inherit object? I just found some code that does this and I can't find a good reason why. class MyClass(object): # class code follows... The code is using swig for binding some C code to Python, if that's relevant. ...

implementing callback between Python and C

I have wrapped some C code using SWIG to use it as a python library. Within this framework, some python code I have written calls a C function, which returns a string. However, for creating the string, the C function requires a ranking, the generation of which I have implemented in Python. How would I go about implementing this using ca...