swig

SWIG_SHARED_PTR macro with templated class

让人想犯罪 __ 提交于 2019-12-25 03:08:30
问题 I'm using SWIG with boost shared pointers to create python extensions. My current issue is that the SWIG_SHARED_PTR macro seems to work differently with templated classes. I'll give two examples, one without templates (example), and one with templates (example2). First I'll include the code, and at the end show the difference in behavior of the two extensions within python. The basic problem is that without templates the shared pointers appear in python as <example.Derived; proxy of <Swig

SWIG: Ruby overloading problems

风流意气都作罢 提交于 2019-12-25 02:48:07
问题 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 function names are always mapped to this library. The reason is that 'require' does only load stuff that is not already loaded, whereas 'load' reloads no matter what.

SWIG Interface File Structure Causing Duplicate Java Functions

…衆ロ難τιáo~ 提交于 2019-12-25 02:15:39
问题 I have the below SWIG Interface file structure that I feel is invalid. The int func(usigned char key[20]) resides in headerThree.h. When I leave in the %include "HeaderThree.h" I get a duplicate int func(SWIGTYPE_p_unsigned_char key);. If I remove the %include "HeaderThree.h", the other functions do not show up in the generated Example.java file..only the int func(short[] key) does. I would like to configure the SWIG .i file to not have the func(SWIGTYPE_p_unsigned_char key) function but to

Use SWIG to generate a proxy class for a C struct and a wrapper class for a pointer to the C struct

我只是一个虾纸丫 提交于 2019-12-25 01:48:40
问题 I'm trying to get SWIG to generate Java glue code for me to wrap a C library with. I have a C header file that looks (roughly) like this: struct MyDatabase; typedef struct MyDatabase MyDatabase; struct MyDatabase { const void *db; }; struct MyDatabase *open_database(char *name); I've written my SWIG interface file like this: %module database %{ #include "database.h" %} struct MyDatabase; %nodefaultctor MyDatabase; %nodefaultdtor MyDatabase; struct MyDatabase { const void *db; }; struct

SWIG reference count error with python callback

谁说我不能喝 提交于 2019-12-25 01:30:03
问题 I'm wrapping a C function in python where the function allows a callback into python. I have the wrapper working, but with a reference counting problem that I'd like help to understand and fix. [There are few working examples of language callbacks using SWIG that I could find so I could easily have got something quite wrong.] A simple C function, func(), that requires a callback is defined in cb_test.i. The func() creates a C array and passes that array as a param to the callback. The func()

How to pass a value to a function when the value is SWIGTYPE

亡梦爱人 提交于 2019-12-25 00:36:09
问题 I have a wrapped function in java like this: dosomething(SWIGTYPE_sometypeSTRUCT STRUCTtype); Originally in the C code, the declaration looks so: dosomething(sometypeSTRUCT* structtype); How can I pass the SWIGTYPE to the java function. if I do: SWIGTYPE_sometypeSTRUCT something = new SWIGTYPE_sometypeSTRUCT (); it won't work.. It will work only if I set somthing = null. 回答1: The problem is that SWIG hasn't seen a definition of sometypeSTRUCT - as far as it knows the pointer your dosomething

Unable to Call Native SWIG Method using DLL on Windows XP

我的梦境 提交于 2019-12-24 20:06:24
问题 I'm attempting to get my SWIG implementation to work on Windows XP (32bit) machine. My test.java is able to load the SWIG shared library dll (System.loadLibrary("TestJni")) but it throws the below exception when I attempt to call any C function that I've exposed using SWIG. I'm in search of some debugging tips. I created the shared library dll using 32 bit Linux using a Makefile. Maybe something is out of wack in the created of the SWIG shared library dll. I'm able to get this to work on

g++ linking and swig

只愿长相守 提交于 2019-12-24 15:27:01
问题 I have a cpp file with functions that I'm using in python with SWIG. I use the following commands to compile the source and create the file to use with python. swig -c++ -python mini.i g++ -O2 -c mini.cpp -I/usr/include/python2.4 -I/usr/lib/python2.4 g++ -O2 -c mini_wrap.cxx -I/usr/include/python2.4 -I/usr/lib/python2.4 g++ -shared mini.o mini_wrap.o -o _mini.so I'm trying now to use GSL in my source cpp source file. If I was just compiling the GSL file I would do g++ -lgsl -lgslcblas -lm -o

Preprocessor for_each witin SWIG interface

爷,独闯天下 提交于 2019-12-24 14:22:17
问题 I've been using the REFLECTABLE macro from this answer in my C++ header file, which looks like: #ifndef TIMER_H #define TIMER_H // From the linked question, but (deliberately) ignored by SWIG here, // only relevant is as much as it defines REFLECTABLE for other preprocessors #include "reflection.hh" struct Timer { REFLECTABLE ( (float) startTime, (float) endTime, ) }; #endif The SWIG preprocessor doesn't follow #include and doesn't handle the definition of REFLECTABLE from the linked question

Wrapping C function with pointer arguments using SWIG

守給你的承諾、 提交于 2019-12-24 13:42:08
问题 I'm trying to use SWIG to wrap an existing C library for use in Python. I'm running swig 2.0.10 on Windows XP with Python 2.7.4. The problem I'm encountering is that I'm unable to call a wrapped C function that has a pointer to an int as an argument which is where the function result is to be stored. I've distilled the problem into the follow example code: The C function in convert.c: #include <stdio.h> #include "convert.h" #include <stdlib.h> int convert(char *s, int *i) { *i = atoi(s);