swig

Swig and refrence counted c++ classes

Many of my c++ objects implement rerfrence counting through AddRef and FreeRef methods. If FreeRef reduces the refrence count to 0 then the object deletes its self. All methods which return a refrence counted object dont increment the refrence. This makes it simple since a smart pointer can then simply increment the count apon recieving...

A trivial Python SWIG error question

I am trying to get Python running with swig to do C/C++. I am running the tutorial here, 'building a python module'. When I do the call gcc -c example.c example_wrap.c -I /my_correct_path/python2.5 I get an error: my_correct_path/python2.5/pyport.h:761:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc ...

problems Wrapping Patricia Tries using Swig, python

Hello all! I'm trying to wrap the Patricia Tries (Perl's NET::Patricia) to be exposed in python. I am having difficulty with one of the classes. So instances the patricia node (below) as viewed from python have a "data" property. Reading it goes fine, but writing to it breaks. typedef struct _patricia_node_t { u_int bit; /* ...

Python SVN bindings for Windows

Where can I find precompiled Python SWIG SVN bindings for Windows? ...

Is it possible to split a SWIG module for compilation, but rejoin it when linking?

Hi all I hit this issue about two years ago when I first implemented our SWIG bindings. As soon as we exposed a large amount of code we got to the point where SWIG would output C++ files so large the compiler could not handle them. The only way I could get around the issue was to split up the interfaces into multiple modules and to co...

Debugging swig extensions for Python

Is there any other way to debug swig extensions except for doing gdb python stuff.py ? I have wrapped the legacy library libkdtree++ and followed all the swig related memory managemant points (borrowed ref vs. own ref, etc.). But still, I am not sure whether my binding is not eating up memory. It would be helpful to be able to ju...

Pass variables between C++ and Lua via Swig

I'm working on a C++ project with a large number of classes (150+), each of which has anywhere from 10 to 300 fields or so. I would really like to be able to provide a scripting interface for testing purposes so that I can code callbacks that don't require any re-compilation. I'd like to do this in Lua since I'm more familiar with its C ...

luaopen_my_example undefined after compiling swig wrapper

I'm just now diving into SWIG as a means for creating Lua bindings, and I've hit a snag. I made my interface file and built a shared object file from it all without any problems. However, when I run Lua and try to require the shared object, I get the following: Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio require("my_example")...

(SWIG / Lua) How to access the list of base / parent classes in swig_lua_class

I notice that in the generated SWIG wrappers for a given set of classes, SWIG keeps a list of C-string representations of all the parent classes from which that class inherits. (char ** base_names). I know there is a function swig_type(some_variable) that will return a string representation of a given variable's data type. Is there al...

Can't catch exception!

I'm using swig to wrap a class from a C++ library with python. It works overall, but there is an exception that is thrown from within the library and I can't seem to catch it in the swig interface, so it just crashes the python application! The class PyMonitor.cc describes the swig interface to the desired class, Monitor. Monitor's cons...

Swig bindings for python/lua do not initialize member data properly

I'm trying to build a set of Lua bindings for a collection of C++ classes, but have been toying with Python to see if I get better results. In either language the bindings seem to work, however, when I initialize an instance of a class that contains members of other classes, those data members do not seem to be guaranteed to be initializ...

Swig / Python memory leak detected

I have a very complicated class for which I'm attempting to make Python wrappers in SWIG. When I create an instance of the item in Python, however, I'm unable to initialize certain data members without receiving the message: >>> myVar = myModule.myDataType() swig/python detected a memory leak of type 'MyDataType *', no destructor found....

$stdin compatibility with std::istream using swig, C++, and Ruby

I have a function in C++ that takes in an std::istream as the input: class Foo { Foo(std::istream &); } Using SWIG, I've bound it to Ruby, but Ruby's $stdin variable is fundamentally different from anything like the stream classes in C++, so I'm not sure how to either 1) expose the C++ class to Ruby in a way that I can use $stdin,...

Basic assignment of swig wrapped variables fails

I created a lua module with a very large number of wrapped C++ classes using swig. The wrappers are generated and compiled (with -Wall) without any issues. However, in a couple of places that I've found, I run into the following issue: basic assignment of member data fails. If I run: Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio...

Swig typecast to derived class?

I notice that Swig provides a whole host of functions to allow for typecasting objects to their parent classes. However, in C++ one can produce a function like the following: A * getAnObject() { if(someBoolean) return (A *) new B; else return (A *) new C; } Where "A" is the parent of classes "B" and "C". One can then typec...

How do I build a Perl hash in C, using SWIG?

I'm trying to create a Perl hash from within a C library. Here's what I've got so far: static void add_string_to_perl_hash ( HV *hv, char * key, char *value ) { SV *obj = sv_2mortal(newSVpv(value, 0)); hv_store(hv, (const char *)key, strlen (key), obj, 0); SvREFCNT_inc(obj); } SV * do_get_test_hash () { static char *foo ="foo"...

How do I satisfy a 3rd-party shared library reference to stat when I'm creating a shared library shim rather than an executable?

I am the new maintainer for an in-house Python system that uses a set of 3rd-party shared C libraries via a shared library shim that is created using a combination of swig and a setup.py script. This has been working well until recently. The 3rd-party shared C libraries were updated for new functionality and now I get the following run-...

Swig c++ w/ Java loses type on polymorphic callback functions

Question: Why is my C++ swigged object losing its type when passed to a Java callback function? Setup: I've taken the Swig Java example for doing callbacks and added an object to be passed to the callback run(Parent p). The callback works as expected but when I pass a Child object the Java seems to lose its type and think its of type Pa...

Lua bindings to C++ and garbage collection.

Ok, here's a problem I'm having. I have Lua bindings to a rendering engine that has an internal render manager that keeps its own track of pointers for the render scene and manages them. The problem is that when I'm using it from Lua, if i don't keep a Lua reference to every single object i add to the C++ render manager, it starts to ga...

How to diagnose Java JNI EXCEPTION_ACCESS_VIOLATION errors in Windows Vista

We have a Java application that uses some C++ libraries through JNI. The application used to work just fine in Windows XP, but it does not work in Windows Vista, it just crashes the JVM right away. We also wrote the C++ libraries and produced JNI bindings using SWIG. We are a little bit clueless on where to start looking for a way to f...