什麼是正確的方式(我越來越seg.fault)到uint8
緩衝器發送到C函數定義爲:蟒蛇ctypes的UINT8緩衝區的使用情況
void f(uint8* p, size_t len)
_lib.f.argtypes=[ctypes.POINTER(ctypes.c_ubyte), ctypes.c_uint]
什麼是正確的方式(我越來越seg.fault)到uint8
緩衝器發送到C函數定義爲:蟒蛇ctypes的UINT8緩衝區的使用情況
void f(uint8* p, size_t len)
_lib.f.argtypes=[ctypes.POINTER(ctypes.c_ubyte), ctypes.c_uint]
通過你把方式創建的數組對象你的評論 - (cbytes.c_ubyte * 256)()
都很好。 但在ctypes「專業術語」中,此對象不等同於ctypes.POINTER(ctypes.c_ubyte) - 當您嘗試以數組作爲參數調用函數時,ctypes應警告您。無論如何,可能當你將創建的數組作爲參數傳遞時,ctypes不會傳遞對其內容的引用,而是對C(可能是Python對象的地址,而不是其內容)的其他內容。
如果你投的一個指針數組來創建的指針類型的內容,它可能會工作:
pointer_type = ctypes.POINTER(ctypes.c_ubyte)
_lib.f.argtypes=[pointer_type), ctypes.c_uint]
data_block = (ctypes.c_ubyte * 256)()
pointer = ctypes.cast(ctypes.addressof(data_block, pointer_type))
_lib.f(pointer, 256)
哪裏數據你實際上是試圖發送?它告訴benice看看你迄今爲止所嘗試過的。 – jsbueno 2012-02-04 20:33:06
我試過(cbytes.c_ubyte * 256)() – mete 2012-02-04 20:56:38