mvm
mvm

Reputation: 51

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 for line in f if not line.startswith('#')])
    ffibuilder.embedding_api(data)

ffibuilder.set_source("p3", r'''
    #include "inter.h"
''')

ffibuilder.embedding_init_code("""
    from p3 import ffi
    
    @ffi.def_extern()
    def fooz():
        return 4
    """)

ffibuilder.compile(verbose=True)

client:

from cffi import FFI

ffi = FFI()

ffi.cdef("""
            int fooz(void);
        """)

lib = ffi.dlopen("p3.dylib")

lib.fooz()
print(lib)

Upvotes: 5

Views: 309

Answers (0)

Related Questions