swig

why does SWIG make illegal wrapper from in and argout typemaps?

和自甴很熟 提交于 2020-01-06 04:06:28
问题 I am trying to write an argout SWIG typemap. From this interface foobar.i file, which seems perfectly legal to me: %{ void f(int arg[2]) {} %} %typemap(in, numinputs = 0) int [ANY] {} %typemap(argout) int arg[ANY] { PySequence_SetItem($input, 0, PyInt_FromLong(0)); } void f(int arg[2]) {} SWIG compiles an illegal foobar_wrap.cxx file, because it contains the following fragment: PySequence_SetItem(, 0, PyInt_FromLong(0)); replacing $input with nothing. If I omit the in typemap, then the

why does SWIG make illegal wrapper from in and argout typemaps?

為{幸葍}努か 提交于 2020-01-06 04:05:04
问题 I am trying to write an argout SWIG typemap. From this interface foobar.i file, which seems perfectly legal to me: %{ void f(int arg[2]) {} %} %typemap(in, numinputs = 0) int [ANY] {} %typemap(argout) int arg[ANY] { PySequence_SetItem($input, 0, PyInt_FromLong(0)); } void f(int arg[2]) {} SWIG compiles an illegal foobar_wrap.cxx file, because it contains the following fragment: PySequence_SetItem(, 0, PyInt_FromLong(0)); replacing $input with nothing. If I omit the in typemap, then the

How to use numpy.i in swig?

假装没事ソ 提交于 2020-01-05 12:56:24
问题 I'm trying to wrap some c++ code with python using swig and I need to send NumPy arrays into the c++ vector class for some processing. My problem is that I don't seem to be able to access "numpy.i" in my swig .i file. How can I import/include numpy.i? add_vector.i %module add_vector %{ #define SWIG_FILE_WITH_INIT #include "add_vector.h" %} %include "numpy.i" %init %{ import_array(); %} %include std_vector.i %template(vecInt) std::vector<int>; %include "add_vector.h" Makefile all: rm -f *.so *

make fails on swig create ruby wrapper

戏子无情 提交于 2020-01-05 12:22:27
问题 I am trying to use swig to generate some wrappers for some c++ classes. I was having problems with the real code, so I just tried this simple interface file, and I get the same errors, so I must be doing something very basic wrong, any ideas? here is the simple interface file I am trying to build named MyClass.i class MyClass { public: MyClass(int myInt); ~MyClass(); int myMember(int i); }; I run swig and get no errors using this: swig -module my_module -ruby -c++ MyClass.i then with the

Extend C# Proxy Class for a C++ template

非 Y 不嫁゛ 提交于 2020-01-05 04:55:15
问题 TLDR: How do I access the template type "T" in C# for SWIG? Let's say I have the following templated class in C++ with a Validate function: template<typename T> struct MyTemplateClass { bool Validate(T* _in) { //... } // ... other stuff... MyTemplateClass is also a container for T* }; Let's say I instantiate the class for a variety of objects: %template(MyTemplateClassFoo) MyTemplateClass<Foo> %template(MyTemplateClassBar) MyTemplateClass<Bar> // etc. In C#, I want the Validate function to

Distutils: build multiple Python extension modules (written in Swig) that share a method

倾然丶 夕夏残阳落幕 提交于 2020-01-05 04:28:09
问题 I have four C++ files: A.h, A.cpp, B.h, B.cpp, and A.h is included in B.cpp A.h: #pragma once void A(); A.cpp: #include <iostream> void A() { std::cout << "A" << std::endl; } B.h: #pragma once void B(); B.cpp: #include "A.h" #include <iostream> void B() { A(); std::cout << "B" << std::endl; } Now I wrote two SWIG inerface files A.i and B.i A.i: %module A %{ #include "A.h" %} %include "A.h" B.i: %module B %{ #include "B.h" %} %include "B.h" The setup.py file is: from distutils.core import

Input sting for wrapped C++ function doesn't changing SWIG

梦想的初衷 提交于 2020-01-05 03:36:19
问题 I make Python wrapper for C++ library. mylib.i: %module mylib %include <std_string.i> %{ #include "mylib.h" %} %apply const std::string & {std::string &}; %apply std::string & {std::string &}; int getResult(const std::string& path, std::string& result); mylib.h: #pragma once #include <string> myEnum {foo=0, bar}; myEnum getResult(const std::string& path, std::string& result); After generating _mylib.so with following command: g++ -fPIC -Wall -Wextra -shared mylib_wrap.cxx -o _mylib.so -L.

Retrieving a Python type back from c++

[亡魂溺海] 提交于 2020-01-04 05:14:09
问题 This question is really an extension of the following two questions: How can I implement a C++ class in Python, to be called by C++? Swig downcasting from Base* to Derived* Suppose that I have the following c++ classes (simplified), which I am exposing to Python using SWIG: struct Component { virtual void update(double dt); } struct DerivedComponent : public Component { void update(double dt) { std::cout << "DerivedComponent::update()" << std::endl; } void f() { std::cout << "DerivedComponent

JNI for C using Swig & trouble with function pointer callback

放肆的年华 提交于 2020-01-04 01:49:21
问题 we have a C function in one of the libraries which are loaded in java, which accepts a function pointer function defination as below typedef char int8 typedef unsigned short uint16 uint32 poll_broadcasts(void *(pfn)(int8*,uint16)); In C it is used as below void handle_broadcasts( int8 *broadcast, uint16 length ) uint32 a = poll_broadcasts( (void*(*)(int8*,uint16)) handle_broadcasts ) But when you use Swig to generate JNI wrapper it creates following definition for poll_broadcast public static

Ignoring specific overloaded methods with Swig

落爺英雄遲暮 提交于 2020-01-03 16:59:48
问题 I'm making a wrapper of a C++ library so it can be used from Java, I'm doing this with Swig. What I'm facing is that i have a Class SomeClass , which has some overloaded methods ( someMethod ). Of this overloaded methods some receive complex data that i don't want to export to the wrapper, and some simple ones which i do want then exported. I'm trying to use the %rename("$ignore") directive but either i get all methods exported or none. I have another two types of Classes SimpleData and