看板 Python 關於我們 聯絡資訊
in c function f(char *p) 一塊memory 的複製 原本用SWIG 轉出來的module來使用 ,可是用create_string_buffer傳給 function f 會遇到 argument type 不對 後來把C編譯成 share library 然後用CDLL loadlibrary來使用 lib = CDLL("libtest.so") dump= lib.f; dump.argtypes =[c_char_p] data =create_string_buffer(100) dump(data) print repr(data.raw) 這樣運作 是沒遇到問題 不過資料看起來怪怪的 在C裡面資料是 100030029008.... 在python印出來是 \x00\x01\x00\x00\x03\x00\x00\x02\x00\t\x00\x08 有些資料會怪怪的, 有人知道該如何讓 python create 一塊memory 然後給C去寫資料嗎 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.171.51.33 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1499435901.A.C84.html
uranusjr: Python 的資料每 16 位元一組剛好等於 C 那邊的 8 位元 07/08 18:11
uranusjr: 所以看起來是你兩邊的格式沒有 match, 可能是 C 輸出的 07/08 18:11
uranusjr: 其實是 wchar * 之類的 07/08 18:11
os653: 你C跟Python一定有一邊輸出寫錯吧 07/08 18:25
os653: 直接叫function回傳0123456789abcdefg看結果比較快 07/08 18:26