swig

How to avoid memory leak with shared_ptr and SWIG

可紊 提交于 2019-12-21 09:25:13
问题 I'm trying to use boost::shared_ptr 's to allow for me to use c++ file I/O stream objects in my python script. However, the generated wrapper warns me that it is leaking memory. Here's a minimal .i file exhibiting the problem: %module ptrtest %include "boost_shared_ptr.i" %include "std_string.i" %shared_ptr( std::ofstream ) %{ #include <fstream> #include <boost/shared_ptr.hpp> typedef boost::shared_ptr< std::ofstream > ofstream_ptr; ofstream_ptr mk_out(const std::string& fname ){ return

what does the last argument to SWIG_NewPointerObj mean?

被刻印的时光 ゝ 提交于 2019-12-21 07:16:31
问题 I have a compatibility library that uses SWIG to access a C++ library. I would find it useful to be able to create a SWIG-wrapped Python object inside this layer (as opposed to accepting the C++ object as an argument or returning one). I.e. I want the PyObject* that points to the SWIG-wrapped C++ object. I discovered that the SWIG_NewPointerObj function does exactly this. The SWIG-generated xx_wrap.cpp file uses this function, but it's also made available in the header emitted by swig -python

javascript extension to use C based APIs(clutter) in a webapp

烈酒焚心 提交于 2019-12-21 03:42:28
问题 My goal is to use the C libraries to form web apps. I have choosen the way to do that via using "SWIG" tool. The Swig tool requires three things 1) .c file which defines all the functions. 2) .i file also called interface file which is creating the interface to load the APIs wherin I used the extern keyword. 3) APP written in javascript extension (.js file). I used SWIG tool to compile and run this app to verify the .js file has made correctly. The application is running fine on XMING X11

Python Properties & Swig

自闭症网瘾萝莉.ら 提交于 2019-12-20 08:19:12
问题 I am attempting to create python bindings for some C++ code using swig. I seem have run into a problem trying to create python properties from some accessor functions I have for methods like the following: class Player { public: void entity(Entity* entity); Entity* entity() const; }; I tried creating a property using the python property function but it seems that the wrapper classes swig generates are not compatible with it at least for setters. How do you create properties using swig? 回答1:

Remove SWIGTYPE from Generated Class name

白昼怎懂夜的黑 提交于 2019-12-20 05:26:16
问题 Is there anyway to remove the SWIGTYPE part from the generated class names and replace with another string literal? i.e. change SWIGTYPE_p_ex_session.java to ex_session.java (strip off generated "SWIGTYPE_p_") SWIG .i file: %module Example %{ #include "ExampleApi.h" struct ex_session{}; %} %include "ExampleApi.h" ExampleApi.h contains the below: typedef struct ex_session session_t; 回答1: Assuming the real issue here is the "ugly name" then I'd solve this one by making sure SWIG has at least an

Is it possible to add code to an existing method when using Swig to build a C# wrapper for C++ code?

浪尽此生 提交于 2019-12-20 04:24:32
问题 When using Swig to wrap C++ code, it is possible to add methods to the native C++ type using %extend . It is possible to add methods to the C# wrapper class using %typemap(cscode) . Where a method already exists in the wrapper class, is there a way to add additional lines of code? For example, my C# wrapper method looks like this: public void ItemChanged(CollectionObject collectionObject, string propertyName) { mynamespacePINVOKE.mynamespace_DataObjectCollection_ItemChanged(swigCPtr,

%typemapping of a C++ Library for Python Interface

☆樱花仙子☆ 提交于 2019-12-20 03:36:12
问题 I want to create a python wrapper for my C++ library. It would be cool, if there is a automatic conversion of std::vector to python lists and the other way round. Unfortunatly if I add this code to my Interface-file I still get errors in run-time. %typemap(in) std::vector<float> value (std::vector<float> vIn) { int iLen = PySequence_Length($input); for(unsigned int i = 0; i < iLen; i++) { PyObject *o = PySequence_GetItem($input, i); if (PyNumber_Check(o)) { vIn.push_back((float)PyFloat

How do I check if an externalptr is NULL from within R

旧时模样 提交于 2019-12-20 03:07:35
问题 I'm using SWIG to generate wrapper code to access C code from within the R language. The wrapper code uses the R externalptr type to hold references to C pointers. In some situations, those pointers are NULL on the C side, which show up in R as a nil value when displayed. On the R side, calling is.null() and is.na() on the externalptr both return FALSE . For example: > val = librdf_query_results_get_binding_value(results, 2) > val An object of class "_p_librdf_node_s" Slot "ref": <pointer:

How to pass list of structs to C in SWIG/Python

房东的猫 提交于 2019-12-20 02:38:24
问题 I have a C++ class I'm exporting via swig, and a function that takes an array of Foo s: typedef class Foo { int i; } Foo; void func(Foo *all_foos); Now I'd like to be able to pass a python list containing those into all_foos: afoo = mymod.Foo() bfoo = mymod.Foo() mymod.func([afoo, bfoo]) I have a typemap which doesn't work. See the FIXME line for where I need help. %typemap(in) Foo ** { /* Check if it's a list */ if (PyList_Check($input)) { int size = PyList_Size($input); int i = 0; $1 = (Foo

swig Nothing known about base class 'std::string', ignored

别等时光非礼了梦想. 提交于 2019-12-19 23:20:53
问题 I am trying to use swig to build ruby wrappers around a c++ library. Most of it seems to be working but I have one issue that I am pretty sure is related to the above warning. It looks like one of the classes I am wrapping is inherited from std::string. I see the above warning message when I run swig. When I call a method on an object in ruby that should be returning a string, I see this SWIG::Type_p_std__string:0x..... I am thinking I need to some how fix the above warning to the this to