5

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)

mvm
  • 51
  • 2
  • It works fine for me on Windows (Python 3.7) and Linux (Python 3.8). I can't test on Mac, but I could test with other Python versions. – Armin Rigo Apr 01 '21 at 08:12

0 Answers0