swig

Python ctypes callback function to SWIG

你离开我真会死。 提交于 2019-12-12 11:18:00
问题 I have a SWIG C++ function that expects a function pointer (WNDPROC), and want to give it a Python function that has been wrapped by ctypes.WINFUNCTYPE. It seems to me that this should be compatible, but SWIG's type checking throws an exception because it doesn't know that the ctypes.WINFUNCTYPE type is acctually a WNDPROC. What can I do to pass my callback to SWIG so that it understands it? 回答1: I don't have a windows machine to really check this, but I think you need to create a typemap to

How to pass Python instance to C++ via Python/C API

落花浮王杯 提交于 2019-12-12 10:47:57
问题 I'm extending my library with Python (2.7) by wrapping interfaces with SWIG 2.0, and have a graph object in which I want to create a visitor. In C++, the interface looks like this: struct Visitor { virtual void OnStateBegin() = 0; virtual void OnNode(Node* n) = 0; virtual void OnStateEnd() = 0; }; I would like to define a class in Python that does the equivalent, all defined in python, that will allow for the definition of a visitor: class GraphVisitor: def __init__(self, label): self._label

nodeJS + Swig template passing variable to javascript

谁说我不能喝 提交于 2019-12-12 10:46:12
问题 Is there any way using express + swig template for nodeJS to pass variables from the server side to client side javascript? I know it can be done in Jade but I'd rather stick with a template engine that more closely resembles HTML. Thanks for the help guys! 回答1: OK I will assume that you could configure your express with consolidate.swig if not please read this link (http://tinyurl.com/kcs8kvy). Well I didn't find the direct way to pass variable values to client javascript but I have found a

SWIG & C/C++ Python API connected - SEGFAULT

感情迁移 提交于 2019-12-12 10:12:05
问题 my task is to create dual program. At the beginning I start C program that calls throught C/C++ API of Python some Python method. The called method after that call a function that is created with SWIG. I show you my sample also with backtrace from gdb after I am given Segmentation fault. main.c: #include <Python.h> #include <stdio.h> #include "utils.h" int main(int argc, char** argv) { printf("Calling from C !\n"); increment(); int i; for(i = 0; i < 11; ++i) { Py_Initialize(); PyObject *pname

Accessing C struct array to Python with SWIG

余生长醉 提交于 2019-12-12 09:42:09
问题 I attempting to call into existing C code from Python. The C code defines a struct B that contains an struct array of A s. The C code also defines a function that puts values into the structure when called. I can access the array member variable, but it is not an list (or something that supports indexing). Instead, I am getting an object that is a proxy for B* . I found this question, but it doesn't look like it was completely resolved. I'm also not sure how to make an instance of the Python

How to use a Python list to assign a std::vector in C++ using SWIG?

久未见 提交于 2019-12-12 08:06:48
问题 I have a simple C++ class that contains a std::vector member and a member function that takes a std::vector as an argument that I am wrapping with SWIG and calling from Python. The example code is below. After compiling it, I go into Python and do: import test t = test.Test() a = [1, 2, 3] b = t.times2(a) # works fine t.data = a # fails! The error message I get is: TypeError: in method 'Test_data_set', argument 2 of type 'std::vector< double,std::allocator< double > > *' I know that I can

cannot find symbol “Embeddedrcall_Init”

岁酱吖の 提交于 2019-12-12 05:59:35
问题 I am trying to create a dll file using swig for an embeddedR C Program in windows environment. I am using the below commands: C:\swigwin-3.0.12\Examples\r\Z>swig -c++ -tcl embeddedRCall.i C:\swigwin-3.0.12\Examples\r\Z>gcc -c embeddedRCall.c -I/swigwin-3.0.12/Examples/r/Z C:\swigwin-3.0.12\Examples\r\Z>gcc -c embeddedRCall_wrap.c -I/Tcl/include/tcl8.6 -I/swigwin-3.0.12/Examples/r/Z C:\swigwin-3.0.12\Examples\r\Z>gcc -shared embeddedRCall.o embeddedRCall_wrap.o -o embeddedRCall.dll -L/Tcl/lib

swig: how to pass void* into generic function

时间秒杀一切 提交于 2019-12-12 04:56:49
问题 I have scenario where I need pass around opaque void* pointers through my C++ <-> Python interface implemented based on SWIG (ver 1.3). I am able to return and accept void* in regular functions like this: void* foo(); void goo( void* ); The problems begins when I try to do the same using generic functions (and this is what I actually need to do). I was able to deal with "foo" scenario above with the function doing essentially something like this (stolen from code generated by SWIG itself for

Segmentation Fault (Core Dumped) when calling a python file from C++ .so

隐身守侯 提交于 2019-12-12 04:55:47
问题 I am trying to generate C++ based .SO file along with wrapper by using swig. This .SO was generated to make a call from python(Ubuntu Environment). It works well if i tried with Simple C++ code, but when i try to build with OpenCV, facing some issues. opencvtest.cpp: #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main() { Mat image; image = imread("/home/swigtest/MyPic.jpg",1); // Read the file

swig get return type from variable in struct as string array in java

独自空忆成欢 提交于 2019-12-12 03:46:56
问题 For a small Java project I needed to interact with existing code written in C, so to make things easy (I'm not a C/C++ programmer unfortunately..) I decided to use swig. The first problem I encountered: a C function that returned a NULL-delimited string resulted in wrapped code that returned a String, containing only the first value was solved by the 3(!) possible solutions Flexo provided in: SWIG get returntype from String as String array in java While continuing development on this project