swig

How to explicitly close datasets in GDAL ruby binding?

我是研究僧i 提交于 2020-01-03 15:57:09
问题 I am using GDAL 1.7.1 from ruby1.9 to generate GeoTIFF files. In the tutorial they recommend to use GDALClose() to close the datasets and flush any remaining content to the filesystem. The same happens in the destructor for the dataset. The problem is that the ruby bindings rely on this destructor mechanism to close the dataset, and I need the result of the file already in the process that generates it. Since ruby is garbage collected, it seems I can not reliably close my files, without

Wrapping template template parameter class with SWIG

為{幸葍}努か 提交于 2020-01-03 10:58:15
问题 I have a C++ class like the following: template< template<typename> class ContainerType, typename MemberType> class MyClass { public: MyClass(ContainerType<MemberType>* volData); } which I am trying to wrap with SWIG. My MyClass.i looks like: %module MyClass %{ #include "SimpleContainer.h" #include "MyClass.h" %} %include "SimpleContainer.h" %include "MyClass.h" %template(MyClass_SimpleContainer_Int) MyClass<SimpleContainer, int>; However, SWIG seems to have problems with the template

Wrapping template template parameter class with SWIG

删除回忆录丶 提交于 2020-01-03 10:58:14
问题 I have a C++ class like the following: template< template<typename> class ContainerType, typename MemberType> class MyClass { public: MyClass(ContainerType<MemberType>* volData); } which I am trying to wrap with SWIG. My MyClass.i looks like: %module MyClass %{ #include "SimpleContainer.h" #include "MyClass.h" %} %include "SimpleContainer.h" %include "MyClass.h" %template(MyClass_SimpleContainer_Int) MyClass<SimpleContainer, int>; However, SWIG seems to have problems with the template

Can you SWIG a boost::optional<>?

一曲冷凌霜 提交于 2020-01-03 08:49:34
问题 I've been using SWIG successfully to build a wrapper interface to make my C++ libraries available in C#. Recently I exposed some boost::optional<> objects and SWIG is having problems with them. Is there a standard way to deal with this? Someone must have run into this before... 回答1: Since SWIG doesn't understand boost types, typemaps have to be written. Here's a pair of typemaps for boost::optional<int> . From Python, None or an integer can be passed into a function: %typemap(in) boost:

SWIG return PyObject as python object?

别等时光非礼了梦想. 提交于 2020-01-03 05:24:31
问题 Suppose I have a SWIG-wrapped class taking care of a pointer to some data, as shown in the following code. I would like to construct a numpy ndarray object from the data and return it to the user. I want it to use the data as it's buffer but not take the ownership. If I'm right, I shall use the numpy C++ api PyArray_SimpleNewFromData . However, my question is how do I return this to python? If I write the following get function, will SWIG automatically return it as a python object? If not,

segfault using SWIG converted code for tcl

徘徊边缘 提交于 2020-01-03 03:13:10
问题 I'm having a segmentation fault with my program. In fact I write a library in C++ and convert it for tcl using SWIG. The segfault occurs here: return Tcl_NewIntObj(static_cast< int >(value)); where value=0 the gdb back trace shows: (gdb) bt #0 0x000054b6 in ?? () #1 0xb6650d5d in SWIG_From_long (value=0) at mntdisplay_wrap.cc:1712 #2 SWIG_From_int (value=0) at mntdisplay_wrap.cc:1722 #3 Testguimnt_Init (interp=0x9714e28) at mntdisplay_wrap.cc:3774 #4 0xb76748fe in Tcl_LoadObjCmd () from /opt

Python: Referring to an Exception Class Created with PyErr_NewException in an Extension Module

江枫思渺然 提交于 2020-01-03 00:00:11
问题 I am creating my own Python extension (using SWIG, but I hope that is not relevant). In the C++ side of it, I am using PyErr_NewException to create a custom exception object. // C++ - create a custom Python Exception class. m = Py_InitModule((char *) "MyModule", SwigMethods); g_pyMyErr = PyErr_NewException( "MyModule.MyErr", 0, 0 ); Py_INCREF(g_pyMyErr); int result = PyModule_AddObject(m, "MyErr", g_pyMyErr); The above code returns success values and I can throw the above exception

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

微笑、不失礼 提交于 2020-01-02 21:21:38
问题 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. 回答1: Since you say "or something else" in the Q's title -- if you choose to use

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

大憨熊 提交于 2020-01-02 21:21:06
问题 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. 回答1: Since you say "or something else" in the Q's title -- if you choose to use

SWIG+c+Python: Passing and receiving c arrays

孤街醉人 提交于 2020-01-02 16:13:39
问题 I am trying to reuse some old c code with SWIG and Python. Right now I am quite confused. The errors I get can be demonstrated on a small example: bsp.h: extern void add(int a[], int b[], int c[]); bsp.c: #include "bsp.h" void add(int a[], int b[], int c[]) { c[0] = a[0] + b[0]; c[1] = a[1] + b[1]; } bsp.i %module bsp %{ #include "bsp.h"; %} %include "bsp.h"; setup.py: #!/usr/bin/env python from distutils.core import setup, Extension bsp_module = Extension('_bsp', sources = ['bsp_wrap.c',