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

TypeError: initializer for ctype 'double *' must be a compatible pointer, not cdata 'double *'

liuzhenhai
created an issue

when I create two FFI() in the same context, I think I hit a bug. here is the python code:

{{{

!python

from cffi import FFI

ffi=FFI() ffi.cdef(""" void func(double *a); """) c=ffi.dlopen("./test.dll") a=ffi.new("double") c.func(a) print a[0] #the first block is fine

ffi=FFI() ffi.cdef(""" void func(double *a); """) c=ffi.dlopen("./test.dll") c.func(a) print a[0] # error }}}

I duplicate the first block code, but i didn't allocate a new variable instead of using the previous variable "a", then I get the error TypeError: initializer for ctype 'double ' must be a compatible pointer, not cdata 'double '

Comments (2)

  1. Armin Rigo
    • changed status to open

    Ah. It's not scrictly speaking a bug, because two different FFI instances have a completely separated set of types (e.g. what you cdef() into one doesn't influence what you can cdef() into the other). I agree that the error message is very obscure in this case, and also that types made without using the cdef() definitions should ideally be the same for both FFI instances.

    What is your use case for having several FFI instances?

  2. liuzhenhai reporter

    I find the issue when I play around the cffi in the console mode. I thought the data that allocate by cdef() would be global shared between different FFI instances at first. now I understand your design principle. I agree with your opinion.

  3. Log in to comment