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
7
votes
1 answer

CFFI: TypeError: initializer for ctype 'char[]' must be a bytes or list or tuple, not str

Using the CFFI library for Python, I'm trying to coax a Python string into a char*, so that I can pass it to a C function that accepts char*. I can't seem to figure out what the right incantation is. Consider this example: >>> from cffi import…
101010
  • 14,866
  • 30
  • 95
  • 172
7
votes
1 answer

Generated windows exe (pyinstaller) could not load _cffi_backend

I am trying to generate executable(x86) with pyinstaller(3.0) on windows7(x64). I have installed cffi and other needed packages with pip. I can import cffi and _cffi_backend module successfully from command line: >>> import cffi >>> import…
mgundes
  • 75
  • 1
  • 9
7
votes
3 answers

Python CFFI convert structure to dictionary

There is a way to initialize structure with dictionary: fooData= {'y': 1, 'x': 2} fooStruct = ffi.new("foo_t*", fooData) fooBuffer = ffi.buffer(fooStruct) Is there some ready function to do the conversion? fooStruct =…
Arpegius
  • 5,817
  • 38
  • 53
7
votes
2 answers

Python CFFI module fails when loading dll: OSError 0x7e

I run Python 3.3 (Anaconda distribution) under Windows 7, 64-bit. I have attempted to install the Weasyprint app/library, which has a number of dependencies, including CFFI, which I had to compile from source because no compatible version of it was…
Erik Norvelle
  • 637
  • 7
  • 9
6
votes
1 answer

How to configure python cffi library to use mingw?

Attempting to call cffi.FFI.verify() on windows will produce this error: distutils.errors.DistutilsPlatformError: Unable to find vcvarsall.bat I want to use mingw to compile instead of msvc. I tried to make distutils use mingw by creating…
vanem
  • 165
  • 9
5
votes
0 answers

Segmentation fault using CFFI when switching from Python 2 to Python 3

I am trying to execute a tiny CFFI app using python 3, but I always get Segmentation fault: 11. When I compile the same code using python 2, it works. api.py import cffi ffibuilder = cffi.FFI() with open('inter.h') as f: data = ''.join([line…
mvm
  • 51
  • 2
5
votes
1 answer

Why does Pip disregard configured repository with nested dependencies?

Problem Let us say I have a completely empty Python+Pip+R (pip 19.3.1) environment on a Linux machine and I want to install the package rpy2 with pip. Since I am behind a corporate firewall I configure pip to use a private…
trallnag
  • 2,041
  • 1
  • 17
  • 33
5
votes
1 answer

How to wrap a CFFI function in Numba taking Pointers

It should be a easy task, but I can't find a way how to pass a pointer of a scalar value to a CFFI function within a Numba function. Passing a pointer to an array works without problems using ffi.from_buffer. Example function import cffi ffi =…
max9111
  • 6,272
  • 1
  • 16
  • 33
5
votes
2 answers

How can I build Python CFFI modules during development?

What are best practices for building CFFI modules during development? Right now I'm using a Makefile: mylib/_ffi.so: my_lib/build_ffi.py python $< And then to test I can use: $ make && python test.py But this seems suboptimal. Is there a…
David Wolever
  • 148,955
  • 89
  • 346
  • 502
5
votes
3 answers

Installing python library cffi on Windows

If I pip install cffi, I get this: building '_cffi_backend' extension c:\mingw\bin\gcc.exe -mdll -O -Wall -Ic/libffi_msvc -IC:\python27\include -IC:\python27\PC -c c/_cffi_backend.c -o build\temp.win32-2.7\Release\c\_cffi_backend.o ... (lots of…
Range vs. Range
  • 325
  • 1
  • 3
  • 11
4
votes
0 answers

Issue with installation bcrypt for Python 3.7.10 env on Mac M1 Pro

For current project need to set up environment with Python 3.7 on Mac with M1 Pro. During installation of bcrypt requirement faced following error: import _cffi_backend as backend ImportError:…
Kirill l
  • 41
  • 2
4
votes
2 answers

Does calling a c function via ctypes in python release the GIL during execution of the C code

I want to call some c function from python to be able to improve performance of my code. But I cannot find online whether when I call a C function using the ctypes libraries the GIL is released. As a simple example: from ctypes import * fun =…
user2882307
4
votes
0 answers

How to make C-function pointer that is a closure over another C-function and a Python function parameter, from Python

I'm working with an interesting puzzle - how to create closures of C functions that reference Python data at runtime? This is a little long, but there's some technically interesting stuff here if you like programming puzzles, so is worth a…
user48956
  • 14,850
  • 19
  • 93
  • 154
4
votes
1 answer

Python CFFI: Build single module from multiple source files

My aim is to build a single module/extension from multiple C source files. What is the best practice to achieve this? What I tried: I know that theffi.set_source function has the optional sources and include_dir kwargs and that there should be a…
felixinho
  • 625
  • 7
  • 17
4
votes
0 answers

How to use CFFI with multiple header files

I have C header file with some functions and structure definitions. But that C header file includes multiple other c header files. Some of my structures that I need use other structures from other header files as their members. How can I use CFFI…
Akhady
  • 63
  • 2
1
2
3
14 15