swig

SWIG crashes on AIX (with python, and probably everything else SWIG support)

痞子三分冷 提交于 2019-12-09 21:57:06
问题 SWIG compiles and install easily on AIX. Unfortunately, a simple SWIG hello world (which also compiles - but not so easily) crashes with Segmentation Fault or Illegal Instruction (depending on some details of the compilation/linker process). This happens with both gcc and xlc (IBM c compiler). I tried only the native AIX linker ld, because the homonyms GNU ld was not installed on my system. File: example.c #include <time.h> double My_variable = 3.0; int fact(int n) { if (n <= 1) return 1;

Use method inherited from abtract C++ class in a Python class (SWIG)

你离开我真会死。 提交于 2019-12-09 19:25:57
问题 I am currently using SWIG to make the implementation of small modules easier in my main C++ programm. The class architecture is as follow : foo.hpp : class Foo { public: virtual int pureFunc() = 0; int func() { return (42); } }; file.i : %module(directors="1") foo %feature("director") Foo; %{ #include "foo.hpp" %} %include "foo.hpp" file.py : import sys sys.path.append('.') import foo class Bar(foo.Foo): def __init__(self): pass def pureFunc(self): return 21 lol = Bar() print lol.pureFunc()

Swig, returning an array of doubles

我们两清 提交于 2019-12-09 15:39:35
问题 I know, there are often many ways to solve certain problems. But here I know which way I want to have it, but I am unable to make it work with Python and SWIG... I have a C-function, which returns me an array of double values: double *my(int x) { double a,b,*buf; buf = malloc (x * sizeof(double)); a=3.14; b=2.7; buf[0]=a; buf[1]=b; return buf; } Here, I definitively want to have the array as a return value. Not, as in many examples a 'void' function, which writes into an input array. Now, I

Wrapping a C++ class in Python using SWIG

☆樱花仙子☆ 提交于 2019-12-09 09:59:54
问题 example.h : #ifndef EXAMPLE_H #define EXAMPLE_H class Math { public: int pi() const; void pi(int pi); private: int _pi; }; #endif example.cpp : #include "example.h" int Math::pi() const { return this->_pi; } void Math::pi(int pi) { this->_pi = pi; } example.swig : %module example %{ #define SWIG_FILE_WITH_INIT #include "example.h" %} %include "example.h" I then generate the wrappers, "example.py" and "example_wrap.c" using: swig -python example.swig When I try to compile the wrapper class

SIGSEGV error using SWIG to make a java shared library

匆匆过客 提交于 2019-12-09 01:09:16
问题 So, I'm trying to port a C library (libnfc) to Java using SWIG. I've got to the point of having a compiled shared library, and a basic "nfc_version()" method call will work. However, calling "nfc_init()" to set things up causes a SIGSEGV error. Calling the nfc library directly is fine. The commands I used to generate the shared library: swig -java -I../libnfc/include nfclib.i gcc -c -I/usr/lib/jvm/java-7-openjdk-i386/include/ -I/usr/lib/jvm/java-7-openjdk-i386/include/linux nfclib_wrap.c gcc

SWIG - Wrap C string array to python list

混江龙づ霸主 提交于 2019-12-08 21:55:59
问题 I was wondering what is the correct way to wrap an array of strings in C to a Python list using SWIG. The array is inside a struct : typedef struct { char** my_array; char* some_string; }Foo; SWIG automatically wraps some_string to a python string. What should I put in the SWIG interface file so that I can access my_array in Python as a regular Python string list ['string1', 'string2' ] ? I have used typemap as sugested : %typemap(python,out) char** { int len,i; len = 0; while ($1[len]) len++

how to use enum in swig with python?

蓝咒 提交于 2019-12-08 21:33:29
问题 I have a enum declaration as follows: typedef enum mail_ { Out = 0, Int = 1, Spam = 2 } mail; Function: mail status; int fill_mail_data(int i, &status); In the function above, status gets filled up and will send. When I am trying this through swig I am facing the following issues: It is not showing details of mail . When I try to print mail.__doc__ or help(mail) , it is throwing an error saying there is no such Attribute, though though i am able to use those values ( Spam , In , and Out ). As

Accessing void pointers in Python (using SWIG or something else)

試著忘記壹切 提交于 2019-12-08 21:03:32
I've been trying to use SWIG to wrap around a simple library that uses ioctl() to populate a structure like the following: struct data { header* hdr; void* data; size_t len; }; data is a pointer to a buffer, len is the length of that buffer. I'm unable to figure out how to convert data to a Python string (or array). Furthermore, I need a way to free that buffer in the destructor. Any suggestions are appreciated. Since you say "or something else" in the Q's title -- if you choose to use ctypes , you can represent a void* with c_void_p (one of ctypes' fundamental data types , and access

Python Callback from SWIG PyObject_Call Segfault

风流意气都作罢 提交于 2019-12-08 17:26:31
问题 I have a wx.py.Shell.shell widget which lets the user execute python code that interacts with my program. I want to be able to pass a function that the user defines in this space to my C++ code (Through the wxswig generated wrapper around my custom widget)and execute it. In my C++ code I'm using a std::function <> class to invoke bound functions (C++ or Python) So I created a simple class to wrap the PyObject with the function call operator. However I get a segfault when I try to call the

How to install SWIG on Linux centos [closed]

╄→尐↘猪︶ㄣ 提交于 2019-12-08 17:11:54
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . I want to install SWIG on My linux server to test some stuff. How can install that 回答1: You have a few options. The easiest is to check for a binary package in the CentOS repository. sudo yum install swig Alternatively, you can download SWIG from http://www.swig.org/download.html, untar it, ./configure, make,