python-cffi

Do I need to free memory returned from a C function called via CFFI?

隐身守侯 提交于 2019-12-06 01:53:26
I have this example code that has a function text() returning a newly allocated string: ffi_test = FFI() ffi_test.set_source('_test', ''' char* test() { return strdup("hello world"); } ''') ffi_test.cdef(''' char* test(); void free(void *); ''') ffi_test.compile(verbose=True) This works fine: In [1]: from _test import ffi, lib In [2]: x = lib.test() In [3]: ffi.string(x) Out[3]: b'hello world' In [4]: lib.free(x) However, I could not find anything in the docs whether I actually need to manually free() the returned string of if CFFI takes ownership of the pointer as soon as it's returned to

Failed to install “Cairocffi”

独自空忆成欢 提交于 2019-12-04 18:55:19
问题 I'm working with python3, and i'm trying to install " cairocffi " on Ubuntu. To do this, i've successfully installed: python-dev libffi-dev cffi But when i've trying to install "cairocffi" with pip install cairocffi ,I got: File "/usr/local/lib/python3.2/dist-packages/setuptools/dist.py", line 272 , in __init__ _Distribution.__init__(self,attrs) File "/usr/lib/python3.2/distutils/dist.py", line 261, in __init__ self.finalize_options() File "/usr/local/lib/python3.2/dist-packages/setuptools

Why is cffi so much quicker than numpy?

萝らか妹 提交于 2019-12-03 11:53:40
问题 I have been playing around with writing cffi modules in python, and their speed is making me wonder if I'm using standard python correctly. It's making me want to switch to C completely! Truthfully there are some great python libraries I could never reimplement myself in C so this is more hypothetical than anything really. This example shows the sum function in python being used with a numpy array, and how slow it is in comparison with a c function. Is there a quicker pythonic way of

Why is cffi so much quicker than numpy?

限于喜欢 提交于 2019-12-03 02:16:58
I have been playing around with writing cffi modules in python, and their speed is making me wonder if I'm using standard python correctly. It's making me want to switch to C completely! Truthfully there are some great python libraries I could never reimplement myself in C so this is more hypothetical than anything really. This example shows the sum function in python being used with a numpy array, and how slow it is in comparison with a c function. Is there a quicker pythonic way of computing the sum of a numpy array? def cast_matrix(matrix, ffi): ap = ffi.new("double* [%d]" % (matrix.shape[0

How to install cffi package on AWS Beanstalk

*爱你&永不变心* 提交于 2019-11-29 06:13:00
This question looks the same as this post , but since there was no answer, I am re-asking here. I have a Django project to be deployed on AWS Beanstalk, which is using a package cffi . When I run eb deploy , the error logs looks like: ...... Installing collected packages: cffi, characteristic, idna, pyasn1, enum34, ipaddress, cryptography, cssselect, Django, django-bower, django-celery, sqlparse, django-debug-toolbar, django-devserver, django-extensions, django-filter, django-model-utils, futures, django-pipeline, djangorestframework, html5lib, ipython, ipdb, librabbitmq, lxml, Markdown,

pip cffi package installation failed on osx

﹥>﹥吖頭↗ 提交于 2019-11-29 03:05:36
I am installing cffi package for cryptography and Jasmin installation. I did some research before posting question, so I found following option but which is seems not working: System Mac OSx 10.9.5 python2.7 Error c/_cffi_backend.c:13:10: fatal error: 'ffi.h' file not found #include <ffi.h> ^ 1 warning and 1 error generated. Please guide me on following issue. Thanks Command env DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib/ ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" sudo -E pip

How to pass a Numpy array into a cffi function and how to get one back out?

你离开我真会死。 提交于 2019-11-28 19:14:24
I am developing an audio algorithm using Python and Numpy. Now I want to speed up that algorithm by implementing a part of it in C. In the past, I have done this using cython . Now I want to do the same thing using the new cffi . For testing purposes, I wrote a trivial C function: void copy(float *in, float *out, int len) { for (int i=0; i<len; i++) { out[i] = in[i]; } } Now I want to create two numpy arrays and have those be processed by this function. I figured out a way to do that: import numpy as np from cffi import FFI ffi = FFI() ffi.cdef("void copy(float *in, float *out, int len);") C =

How to include external library with python wheel package

隐身守侯 提交于 2019-11-28 18:21:34
I want to create package for python that embeds and uses an external library ( .so ) on Linux using the cffi module. Is there standard way to include .so file into python package? The package will be used only internally and won't be published to pypi. I think Wheel packages are the best option - they would create platform specific package with all files ready to be copied so there will be no need to build anything on target environments. You can use auditwheel to inject the external libraries into the wheel: auditwheel repair: copies these external shared libraries into the wheel itself, and

How to install cffi package on AWS Beanstalk

随声附和 提交于 2019-11-27 23:46:04
问题 This question looks the same as this post, but since there was no answer, I am re-asking here. I have a Django project to be deployed on AWS Beanstalk, which is using a package cffi . When I run eb deploy , the error logs looks like: ...... Installing collected packages: cffi, characteristic, idna, pyasn1, enum34, ipaddress, cryptography, cssselect, Django, django-bower, django-celery, sqlparse, django-debug-toolbar, django-devserver, django-extensions, django-filter, django-model-utils,

pip cffi package installation failed on osx

孤街浪徒 提交于 2019-11-27 22:04:40
问题 I am installing cffi package for cryptography and Jasmin installation. I did some research before posting question, so I found following option but which is seems not working: System Mac OSx 10.9.5 python2.7 Error c/_cffi_backend.c:13:10: fatal error: 'ffi.h' file not found #include <ffi.h> ^ 1 warning and 1 error generated. Please guide me on following issue. Thanks Command env DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib/ ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in