python-cffi

What does “MemoryError: Stack overflow” mean while releasing memory using CFFI?

淺唱寂寞╮ 提交于 2019-12-13 03:47:39
问题 This question follows this one. I use CFFI to create a DLL and I call it from a C++ application. I was questioning myself to find how to release memory allocated by the DLL and I follow the idea mention by @metal in its answer. Here is now my Python code: import cffi ffibuilder = cffi.FFI() ffibuilder.embedding_api(''' char* get_string(); void free_char(char*); ''') ffibuilder.set_source('my_plugin', '') ffibuilder.embedding_init_code(''' from my_plugin import ffi, lib @ffi.def_extern() def

Python Couchbase CFFI - `AssertionError: backend.__version__ == __version__[:3])`

一曲冷凌霜 提交于 2019-12-13 00:44:12
问题 Full error text: No module named couchbase._libcouchbase Traceback (most recent call last): File "app_main.py", line 75, in run_toplevel File "runtests.py", line 12, in <module> mod = __import__(t, globals(), locals(), ['suite']) File "/home/travis/build/ardydedase/pycouchbase/tests/test_pycouchbase.py", line 15, in <module> from pycouchbase.utils import * File "/home/travis/build/ardydedase/pycouchbase/pycouchbase/__init__.py", line 11, in <module> import couchbase_ffi as couchase File "

Python CFFI memory management issues

不羁岁月 提交于 2019-12-12 02:52:13
问题 I am programming on Ubuntu, with Python 2.7.3 . I am using CFFI to populate a Python list with values coming from some C code. That list is quite big : around 71 000 characters long when printed. The C code is using many libraries. Hence, the following code is only here for a better understanding of what is happening. datas_list = [] for i in range( 0, x ): c_pDataStructure = ffi.new( "c_DataStructure[]", 1 ) // Create a pointer to the data structure c.SomeCFunction( c_pDataStructure ) //

Why my app crashes when I free a char* allocated by a DLL generated with CFFI?

人走茶凉 提交于 2019-12-11 18:44:15
问题 I'm using CFFI to generate a DLL: import cffi ffibuilder = cffi.FFI() ffibuilder.embedding_api(''' char* get_string(); ''') ffibuilder.set_source('my_plugin', '') ffibuilder.embedding_init_code(''' from my_plugin import ffi, lib @ffi.def_extern() def get_string(): val = "string" return lib.strdup(val.encode()) ''') ffibuilder.cdef(''' char *strdup(const char *); ''') ffibuilder.compile(target='my-plugin.*', verbose=True) I generate the DLL by running this previous script. Now, I create this

openshift python pip install cffi fails

我怕爱的太早我们不能终老 提交于 2019-12-11 12:54:52
问题 When the application is deployed after git push to openshift repo I get an error when requirements.txt is start to installing. The thing is, in my local machine there is not issue when I execute pip install cffi remote: Requirement already satisfied (use --upgrade to upgrade): aniso8601==0.92 in /var/lib/openshift/myuser/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages (from -r /var/lib/openshift/myuser/app-root/runtime/repo/requirements.txt (line 1)) remote:

Resolving circular shared-object dependencies with ctypes/cffi

我只是一个虾纸丫 提交于 2019-12-11 04:37:48
问题 I would like to use cffi (or even ctypes if I must) to access a C ABI from Python 3 on Linux. The API is implemented by a number of .so files (let's call them libA.so , libB.so and libC.so ), such that libA contains the main exported functions, and the other libs provide support for libA . Now, libA depends on libB and libB depends on libC . However, there's a problem. There's a global array defined by libA that libC expects to be present. So libC actually depends on libA - a circular

Using Python's CFFI and excluding system headers

匆匆过客 提交于 2019-12-10 19:03:43
问题 I'm trying to use Python's CFFI to develop Python bindings to a scientific model written in C. The CFFI documentation is a little sparse and I'm stuck at the cdef stage. My process up to now has followed these steps: Preprocess the header files: gcc -E -gcc -std=c99 -E -P src/my_c_interface.c -I./include/ -I../shared/include/ > header.txt This produces a text file that includes all the C declarations included in the header files in my include/ directories. It also includes declarations for

How to cast a pointer to a Python cffi struct to System.IntPtr (.NET)?

折月煮酒 提交于 2019-12-08 06:33:21
问题 I need to pass a System.IntPtr to a .NET function (Python with pythonnet). This pointer should refer to a struct created in cffi. I found this: from CLR.System import IntPtr, Int32 i = Int32(32) p = IntPtr.op_Explicit(i) This is what I tried so far import clr from cffi import FFI ffi = FFI() custom_t = ''' typedef struct { float x; float y; float z; } float3; ''' ffi.cdef(custom_t) cfloat3 = ffi.new("float3 *") cfloat3.x = 1.0 cfloat3.y = 2.0 cfloat3.z = 3.0 print(cfloat3) from System import

How can I embed a Python function that returns a string in C using cffi?

江枫思渺然 提交于 2019-12-07 22:07:07
问题 I'm trying to embed a Python function in C using PyPy and cffi. I'm following this guide from the PyPy documentation. The problem is, all the examples I've found operate on ints, and my function takes a string and returns a string. I can't seem to figure out how to embed this function in C, as C doesn't seem to really have strings, rather making do with arrays of chars. Here's what I've tried: # interface.py import cffi ffi = cffi.FFI() ffi.cdef(''' struct API { char (*generate_cool_page)

How can I embed a Python function that returns a string in C using cffi?

拜拜、爱过 提交于 2019-12-06 07:02:13
I'm trying to embed a Python function in C using PyPy and cffi. I'm following this guide from the PyPy documentation. The problem is, all the examples I've found operate on ints, and my function takes a string and returns a string. I can't seem to figure out how to embed this function in C, as C doesn't seem to really have strings, rather making do with arrays of chars. Here's what I've tried: # interface.py import cffi ffi = cffi.FFI() ffi.cdef(''' struct API { char (*generate_cool_page)(char url[]); }; ''') ... @ffi.callback("char[] (char[])") def generate_cool_page(url): # do some