小编mvm*_*mvm的帖子

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)
Run Code Online (Sandbox Code Playgroud)

client:

from cffi import FFI

ffi = FFI()

ffi.cdef("""
            int fooz(void); …
Run Code Online (Sandbox Code Playgroud)

c python segmentation-fault cffi python-cffi

5
推荐指数
0
解决办法
53
查看次数

标签 统计

c ×1

cffi ×1

python ×1

python-cffi ×1

segmentation-fault ×1