swig

SWIG Python Structure Array

拈花ヽ惹草 提交于 2019-12-05 04:36:32
I've been searching for a few days trying to figure out how to turn an array of structures into a Python list. I have a function that returns a pointer to the beginning of the array. struct foo { int member; }; struct foo *bar() { struct foo *t = malloc(sizeof(struct foo) * 4); ... do stuff with the structs ... return t; } After calling the function from Python I get a single structure but trying to access the other elements of the array causes an error: foo = bar() print foo[1].member TypeError: 'foo' object does not support indexing I've tried using %array_class but to no avail. I've also

Heroku buildpacks - installing executables that are used by Python packages

狂风中的少年 提交于 2019-12-05 04:17:47
I am trying to install M2Crypto on Heroku. This relies on SWIG being installed. I've created a custom compiled swig executable and a custom buildpack . I then git push my code up to Heroku, the custom buildpack installs SWIG then tries to install M2Crypto but fails because it can't find swig . This is the buildpack customisation: # Install SWIG if [ ! -d $CACHE_DIR/swig ]; then cd $BUILD_DIR echo "-----> Fetching and installing SWIG 2" curl -O https://s3.amazonaws.com/guybowden/swig.tar.gz >/dev/null 2>&1 echo "-----> Installing ..." tar xzvf swig.tar.gz >/dev/null 2>&1 mv swig $CACHE_DIR/swig

使用swig在python中调用C++

自闭症网瘾萝莉.ら 提交于 2019-12-05 02:51:28
1、安装swig 下载链接: http://www.swig.org/survey.html tar -xvf swig-3.0.12.tar.gz ./configure --prefix=/usr/localswig(此处指定安装目录,不指定默认直接默认系统路径) make && make install 注意:如果在第二步中不成功,可能是没有安装pcre库,安装pcre步骤如下: pcre下载链接:http://www.pcre.org/ tar -xzvf pcre-8.21.tar.gz cd pcre-8.21 ./configure && make && make install 之后,再来测试swig是否安装成功,使用下面语句: swig -version 可能会报“找不到libpcre.so.1的错误”,解决办法如下,建立软连接: sudo ln -s /pcre-8.21/.libs/libpcre.so.0.0.1 /usr/lib/libpcre.so.1 2、建立接口 以一个简单的小程序为例: (1)编辑头文件和源文件 //mytest.h int add(int a,int b); int sub(int a,int b); //test.cpp int add(int a, int b){ return a+ b;} int sub(int a,int

Swig: How to wrap double& (double passed by reference)?

怎甘沉沦 提交于 2019-12-05 01:51:23
问题 I am using SWIG to access C++ code from Python. How do I elegantly wrap a function that returns values in variables passed by reference like void set(double&a) { a = 42.; } I could not find out how to do this. In the best case I'd be able to use the function in Python with Python floats: >>> b = 2. >>> set(b) >>> print b 42.0 At the moment it gives me a TypeError: in method 'TestDouble_set', argument 2 of type 'double &' . 回答1: Do it this way: Your swig interface file: %include <typemaps.i>

网站域名、备案、七牛云图床重新搭建与博客整理

梦想与她 提交于 2019-12-04 23:30:08
最近碰上了一个问题,七牛云开始回收测试域名,结果导致我的图床有些失灵、一些软件资源都无法下载。其实这个问题在前一段不蒜子统计修改的博客里已经有兆头了。不过当时没注意。最后还是被逼得只能购买了域名,各类备案,重新搭建图床。 1 域名购买及备案 在阿里云上购买域名备案就不具体说明了。详情参加下面的网址。 阿里云域名购买 阿里云备案 阿里云的域名备案推荐用阿里云手机app进行,现在已经不需要幕布,比原来简化了很多流程。 当然如果其他平台购买域名也是可以的。国外域名其实都不需要备案的,不过七牛云图床搭建要求主站域名必须备案,反正是比较麻烦。 2 hexo博客自定义域名绑定 hexo博客本身就支持自定义域名的绑定。其实只需要将原来github仓库上的域名转接到新的域名上即可。首先是在hexo博客的source文件夹增加一个CNAME的文件,写入你的域名。接着在域名控制台设置解析DNS。 设置如下三个,一个CNAME,两个指向IPV4地址的,其实给的是github的IP。 这样设置完毕后,原来的网站即转接到新网址。 3 ICP备案与网安备案 ICP备案其实是阿里云那边已经帮忙提交了。阿里云一般一天时间帮你审核完毕,即自动提交工信部ICP备案,这个比较好解决。网安备案要求有服务器。花的时间比较长(尤其选交互式网站的话)。我这边是不小心选了交互式网站。但是建议可以选非交互式的,选www服务之类的

Iterating over std::map in PHP with SWIG

房东的猫 提交于 2019-12-04 21:55:38
问题 I am using SWIG to wrap a function that returns an std::map in PHP. In the PHP code, I need to iterate over the elements of the map. Thw SWIG library provides support for std::map with the std_map.i interface file, but only the following methods are wrapped: clear() del($key) get($key) has_key($key) is_empty() set($key, $x) size() How can I iterate over the elements of the map? Would I need to extend the std_map.i file with some sort of wrappers for iterators and begin() and end() ? 回答1: As

Releasing Python GIL while in C++ code

三世轮回 提交于 2019-12-04 21:27:23
问题 I've got a library written in C++ which I wrap using SWIG and use in python. Generally there is one class with few methods. The problem is that calling these methods may be time consuming - they may hang my application (GIL is not released when calling these methods). So my question is: What is the simplest way to release GIL for these method calls? (I understand that if I used a C library I could wrap this with some additional C code, but here I use C++ and classes) 回答1: The real problem is

Marshaling a Python PIL Image using SWIG

时光总嘲笑我的痴心妄想 提交于 2019-12-04 21:25:00
问题 I've got a library that takes in a very simple C image structure: // Represents a one-channel 8-bit image typedef struct simple_image_t { uint32 rows; uint32 cols; uint8 *imgdata; } simple_image; I didn't create this library, nor this structure, so I can't change it. I'm responsible for wrapping this library for python using SWIG. The Python wrapper needs to be able to take in a PIL Image and convert it into this structure. Here's how I'm doing it right now (using a SWIG %inline% ): // Allows

A trivial Python SWIG error question

▼魔方 西西 提交于 2019-12-04 20:07:46
问题 I am trying to get Python running with swig to do C/C++. I am running the tutorial here, 'building a python module'. When I do the call gcc -c example.c example_wrap.c -I /my_correct_path/python2.5 I get an error: my_correct_path/python2.5/pyport.h:761:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." example_wrap.c: In function 'SWIG_Python_ConvertFunctionPtr': example_wrap.c:2034: warning: initialization discards qualifiers from pointer target type

How to see C++ function invocations behind the SWIG interface, TensorFlow

这一生的挚爱 提交于 2019-12-04 20:03:10
问题 I'm working on TensorFlow and I want to know the relationship between each Python function and the correspondent C++ functions behind the SWIG interface. In other words, I want to be able to know exactly which C++ functions are invoked for every line of Python code of my TensorFlow application. I already saw how to debug the Python code here and how to display at which line of code a segmentation fault happens here, but in these ways I'm able to see only where an error is, while instead I