所以我得到了一个32位Linux机器上的ctypes segfault,我不能在64位达尔文或Linux上重现。
这里是C:
typedef struct { void *ptr; } doodle; doodle C_intpointerfunction(int *a) { *a = 41; doodle foo; foo.ptr = a; return foo; }
这是编译与:
gcc -c intpointerlibrary.c gcc -shared intpointerlibrary.o -o libintpointerlib.so
这里是Python:
在Python下使用WinDLL多次加载DLL
在Win32中将临时DLL加载到Python中
有没有办法来调用python中的leftclick?
微软ICertAdmin2接口从Python ctypes
import numpy as N from ctypes import * _libintpointer = N.ctypeslib.load_library('libintpointerlib.so','.') _libintpointer.C_intpointerfunction.restype = c_void_p _libintpointer.C_intpointerfunction.argtypes = [POINTER(c_int)] def P_intpointerfunction(): lrc = c_int(0) print "lrc before (should be 0) = "+str(lrc.value) return_val = _libintpointer.C_intpointerfunction(byref(lrc)) print "lrc after (should be 41) = "+str(lrc.value) return return_val
rc = P_intpointerfunction()
我得到一个段错误。 我已经尝试创build一个Python类来包装在C端创build的返回的结构与相同的结果。 如果传回一个本地的ctypestypes(如c_int)一切工作正常..这是真的只是一个32位的Linux的问题,还是有什么我没有考虑? 谢谢!
Python的ctypes和没有足够的参数(4字节丢失)
查找正在运行的进程的基本地址
释放在Python中通过ctypes分配的内存
当用户在pipe理员组中时,ctypes.windll.shell32.IsUserAdmin()不返回1
在Python中使用GetExtendedTcpTable时出错
不知道你为什么设置restype = c_void_p ;
class DOODLE(Structure): _fields_ = [('ptr',c_void_p)] _libintpointer.C_intpointerfunction.restype = DOODLE
在Linux x86-64上按预期工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。