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
0 answers

Load a ctypes dlopen handle with cffi

I have this weird case where I absolutely need to open a library using ctypes._dlopen (intercepted method that use a weird memory layout) and then so I can use it in a more simpler way (with my header definitions) I need to load the handle (so the…
hube
  • 1
  • 3
0
votes
0 answers

How does one clear the tesseract cache?

I am using the cffi library with tesseract's C-interface. My deletion pattern is: if self.result_iterator != self.ffi.NULL and self.result_iterator is not None: …
Chris
  • 28,822
  • 27
  • 83
  • 158
0
votes
0 answers

Cffi: how does one call 'delete []'?

I have implemented the solution from this question in my cffi code: How to free memory in cffi In an effort to remove a clearly observable memory leak in python3. I have already reduced this memory leak, and identified a different culprit…
Chris
  • 28,822
  • 27
  • 83
  • 158
0
votes
0 answers

How to help Python locate shared object files in CFFI package

I am working on making a python wrapper for some existing code using CFFI, but I'm getting stuck with packaging and distribution for Linux. I've loosely followed the example here: https://github.com/wolever/python-cffi-example And I've read this…
WildCrustacean
  • 5,896
  • 2
  • 31
  • 42
0
votes
2 answers

How to create a valid CFFI representation of a numpy array of unicode strings?

I have a numpy.ndarray named values containing numpy.unicode_ strings and I have a C function foo that consumes an array of C-strings. There is a CFFI wrapper interface for foo. So I have tried to do something like this p =…
Yunus King
  • 1,141
  • 1
  • 11
  • 23
0
votes
1 answer

Python's CFFI - Pass in floating point value #define directives to cdef()

CFFI's documentation says that it supports the use of constants and macros (like #define) in the cdef "provided the macro is defined to be an integer value", but it doesn't explicitly say that floating point constants are not supported. I've tried…
tiltChimp
  • 3
  • 2
0
votes
0 answers

Implement derived class in Python while the base class be coded in C++

I have built a soft platform. It supports many "Widget" running on it. The platform is a Linux natural C++ application. The so-called "Widgets" are all derived class of one same base class, and implement a same API, linked into many *.so file…
Leon
  • 1,489
  • 1
  • 12
  • 31
0
votes
1 answer

Using cffi to call functions of shared library from python

I am calling some c-sdk from python code. This python code is running as lambda on greengrass. I am using cffi to call the function of shared so from python. My lambda (python code) is running as gcc_user but when i print the user in my C code, it…
0
votes
0 answers

CFFI: keep cdata alive as long as buffer is referencing it

I have wrapped C library via CFFI and I want my Python objects to provide buffer interface to underlying C data. I have something like this: class Series(object): def __init__(self): self._series = ffi.gc(new_series(), free_series) …
awdrt
  • 23
  • 4
0
votes
1 answer

cffi embedding_init_code import custom py files

i am trying to convert my python code to dll, in the code below under ffi.embedding_init_code i can import packages which i have installed with pip or conda like cv2, numpy, pil etc but i have created python file my_tools.py this is giving error…
Rawat
  • 461
  • 3
  • 6
  • 23
0
votes
1 answer

How do we get String in Java(JNA), that returned by Python function using CFFI

I have written code to access Python function using DLL in Java with th help of CFFI and JNA. However, I can't access String value returned by Python function using CFFI getting below error. plugin.py **import cffi ffibuilder =…
Sandy
  • 29
  • 3
0
votes
2 answers

How to access Python dunder methods in C using CFFI?

I was trying to follow this example to attempt to create a simple hash table in C that I could use in Python (using CFFI). Following are the corresponding files and relevant code. hash_table.h: typedef struct { size_t size; ... int…
Saucy Goat
  • 1,587
  • 1
  • 11
  • 32
0
votes
2 answers

Python passing read-only char ** as argument to a function

I have a C library function that expects a char const ** argument, such as: void set_values(void* object, char const ** values, int dim1, int dim2); Where values is an array of dim1*dim2 length pointing to null terminated string values. When I try…
David
  • 57
  • 6
0
votes
1 answer

Why do I get this error "ImportError: dlopen(...): Symbol not found"? when I import my library on python

I've been trying to use some C code in my python project with CFFI, however when I try to build and then import the library I built import _chebyshev_cffi, I get this following error: ImportError: dlopen(/Users/Username/Documents/code…
Pierre
  • 3
  • 3
0
votes
2 answers

Wrapping C code with python on the fly with CFFI/Cython

I am working on a project which requires me to create some wrappers in Python for the C library that I need to call from Python. For context, the C library I am using is a bunch of header files (.h) and statically linked library files (.a) I have…
abisheksampath
  • 376
  • 8
  • 23