I’m trying (unsuccessfully) to pass a pointer to a numpy structured array null-terminated string member to a native library function with a signature like “void funcname(const char*)”.
I’ve mocked this in the example below with the cfunc “c_callback”. Is there any relatively elegant way to pass the “x” member to the c_callback?
I’ve mucked about trying to nab the pointer with a bunch of lower-level things I understand even less than Python, usually ending up with errors like
mismatch of argument types: [char x 48]* vs int8*
It seems like this interoperability should be relatively simple, I’m probably just missing something obvious.
import numpy as np
from numba import types, njit, cfunc
@cfunc(types.void(types.CPointer(types.int8)))
def c_callback(arg):
pass
@njit
def make_ptr(array):
# c_callback(array[0]["x"]) # error: mismatch of argument types: [char x 48] vs int8*
pass
struct_type = np.dtype([("x", "S48")])
arr = np.empty(1, dtype=struct_type)
arr[0]["x"] = "hello"
print(arr)
make_ptr(arr)