Python is passing 32bit pointer address to C functions

前端 未结 4 977
说谎
说谎 2021-02-15 03:41

I would like to call my C functions within a shared library from Python scripts. Problem arrises when passing pointers, the 64bit addresses seem to be truncated to 32bit address

4条回答
  •  难免孤独
    2021-02-15 04:41

    If you don't tell ctypes what type the parameters are, it attempts to infer it from the values that you pass to the function. And this inference will not always work as you need.

    The recommended way to deal with this is to set the argtypes attribute of the function and so explicitly tell ctypes what the parameter types are.

    plate.plate.argtypes = [
        ctypes.POINTER(ctypes.c_float), 
        ctypes.POINTER(ctypes.c_float), 
        ctypes.c_int
    ]
    

    Then you can call the function like this:

    plate.plate(x.ctypes.data, y.ctypes.data, N)
    

提交回复
热议问题