Issue #116 new

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()
    ffi.cdef("""
    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 *")

lib1.f(f1)
lib2.f(f2)

Results in:

(71050223369f0860) /tmp $ python t.py
Traceback (most recent call last):
  File "t.py", line 27, in <module>
    lib1.f(f1)
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 (2)

  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