Questions tagged [python-cffi]

Foreign Function Interface for Python calling C code. The aim of this project is to provide a convenient and reliable way of calling C code from Python.

Foreign Function Interface for Python calling C code. The aim of this project is to provide a convenient and reliable way of calling C code from Python.

More Details

216 questions
0
votes
1 answer

Multiple ffi definitions with ffi.include(...)

I have some cffi definitions spread over a few project sub-directories -- each cffi file defines types and functions, each compiles into a _.py file to be loaded. In the final application I ffi.include() the top level ones (which…
stustd
  • 303
  • 1
  • 10
0
votes
1 answer

Do you have to trigger the destruction of the last reference to a variable created using ffi.gc() from Python-CFFI?

Read in Python CFFI documentation: The interface is based on LuaJIT’s FFI (...) Read on LuaJIT website (about ffi.gc()): This function allows safe integration of unmanaged resources into the automatic memory management of the LuaJIT garbage…
DRz
  • 1,078
  • 1
  • 11
  • 29
0
votes
2 answers

Python CFFI memory management issues

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…
DRz
  • 1,078
  • 1
  • 11
  • 29
0
votes
1 answer

CFFI cannot find functions even though they are in the library

I am trying to load a shared library using CFFI. The code is meant to instantiate a C structure, print it and destroy it. #!/usr/bin/env python from cffi import FFI ffi = FFI() ffi.cdef(""" typedef struct { …
DRz
  • 1,078
  • 1
  • 11
  • 29
0
votes
1 answer

Does PyPy support gmpy2?

It seems from the discussions issue #60 and issue #40 that PyPy couldn't build gmpy before. All I intend to use currently is the probable prime is_prime code which is conveniently in gmpy2. I get the impression that the more calls to gmpy2 means…
qwr
  • 9,525
  • 5
  • 58
  • 102
0
votes
0 answers

Crytic error with distutils?

I am using cffi to write a Python wrapper to a C library. I cannot manage to compile the library, distutils throws some cryptic distutils.errors.DistutilsPlatformError "\"GNU was unexpected at this time Traceback (most recent call last): File…
Overdrivr
  • 6,296
  • 5
  • 44
  • 70
0
votes
1 answer

python cffi library object introspection results in __dict__ object change

I would like to get the full listing of enums from the header file using cffi. But I see a strange behaviour: by observing the object, I'm forcing the change in the underlying __dict__: >>> from cffi import FFI >>> ffi = FFI() >>> ffi.cdef('typedef…
Oleksiy
  • 6,337
  • 5
  • 41
  • 58
0
votes
2 answers

Python, PyPy and CFFI: what am I supposed to use?

I need to call C libraries with python, and after some consideration it seemed CFFI would be most adequate for the kind of job. By now, however, I am thouroughly confused if I'm using it right, because some things seem to work as intended only on…
UncleBob
  • 1,233
  • 3
  • 15
  • 33
0
votes
1 answer

VerificationError: CompileError: command 'cc' failed with exit status 1

I am trying to install: couchbase-python-cffi as part of a PyPi package. But I keep on getting the following error when trying to install couchbase-python-cffi: VerificationError: CompileError: command 'cc' failed with exit status 1 This error…
Ardy Dedase
  • 1,088
  • 9
  • 15
0
votes
1 answer

Getting a C pointer to a function generated by Theano?

I would like to use a Theano function from C/Fortran code (in particular, I want to use an implicit ODE solver written in Fortran with a function created in Theano). Are there any examples/resources on how to do that?
Krastanov
  • 6,479
  • 3
  • 29
  • 42
0
votes
1 answer

Python cffi module: does verify() require re-compiling the entire c library I want to use from my python code?

Say I need to use a few functions from a shared library, e. g. libfoo.so, from python code. I figured the cffi module could help me, especially as it seems to support opaque types if one uses the verify() function. I did not fully understand…
langlauf.io
  • 3,009
  • 2
  • 28
  • 45
0
votes
2 answers

How to import a local library with cffi

i have a test.c like below (in the same dir as the python file) #include void myprint(); void myprint() { printf("hi\n"); } and now i want to "import" it into my python script from cffi import FFI ffi = FFI() ffi.cdef("void…
timeyyy
  • 654
  • 9
  • 20
0
votes
1 answer

How CFFI use the c file in a certain directory?

I am learning to call c in python program by CFFI and write c file named 'add.c' as below : float add(float f1, float f2) { return f1 + f2; } and a python file named 'demo.py' to call add method in 'add.c': from cffi import FFI ffi =…
jerry_sjtu
  • 5,216
  • 8
  • 29
  • 42
0
votes
1 answer

python cffi crashes after callback

I have a proprietary dll which interfaces with usb device, ctypes interface for it is working fine, but cffi one is crashing after calling a callback. function SwitchOn(6) should return pointer to a struct if it finds a device and NULL if it…
vpoverennov
  • 307
  • 3
  • 10
0
votes
1 answer

How to call a __cdel decorated function with cffi?

Hi @eryksun and Python experts: I am trying to import a dll file into python with cffi with the following commands: from cffi import FFI ffi=FFI() lib=ffi.dlopen('ATC3DG.DLL') From a previous question about ctypes, I know that DLL are all cdecl…
audachang
  • 5
  • 1
1 2 3
14
15