1. Python CFFI
  2. Untitled project
  3. cffi
  4. Issues
Issue #116 closed

Creating multiple ffi/lib instances with the same symbols leads to trouble

Alex Gaynor
created an issue
import cffi

def make_ffi_lib():
    ffi = cffi.FFI()
    typedef struct {
    } FOO_T;

    void f(FOO_T *);
    lib = ffi.verify("""
    typedef struct {
    } FOO_T;

    void f(FOO_T *f) {
    return ffi, lib

ffi1, lib1 = make_ffi_lib()
f1 = ffi1.new("FOO_T *")

ffi2, lib2 = make_ffi_lib()
f2 = ffi2.new("FOO_T *")


Results in:

(71050223369f0860) /tmp $ python t.py
Traceback (most recent call last):
  File "t.py", line 27, in <module>
TypeError: initializer for ctype 'FOO_T *' must be a pointer to same type, not cdata 'FOO_T *'

But only under CPython, under PyPy it runs fine.

Comments (3)

  1. Armin Rigo

    It's messy to implement without changing the whole world. I've tried a few times but give up for now, and replaced it with giving out a warning when you try to re-import the same .so.

  2. Log in to comment