import ctypes import pyarrow from pyarrow.cffi import ffi #c_schema = ffi.new('struct ArrowSchema*') #c_array = ffi.new('struct ArrowArray*') #ptr_schema = int(ffi.cast('uintptr_t', c_schema)) #ptr_array = int(ffi.cast('uintptr_t', c_array)) path = '/home/jan/projects/masque/test.gds' #clib = ctypes.CDLL('target/debug/libklamath_rs_ext.so') clib = ffi.dlopen('target/debug/libklamath_rs_ext.so') ret_ptr_array = ffi.new('struct ArrowArray[]', 1) ret_ptr_schema = ffi.new('struct ArrowSchema[]', 1) ffi.cdef(''' int read_path(const char* path, struct ArrowArray* array, struct ArrowSchema* schema); const char* last_error_message(void); ''') print(f'{ret_ptr_array[0]=}, {ret_ptr_schema[0]=}') status = clib.read_path(path.encode(), ret_ptr_array, ret_ptr_schema) if status != 0: message = ffi.string(clib.last_error_message()).decode('utf-8', errors='replace') raise RuntimeError(message) ptr_schema = int(ffi.cast('uintptr_t', ret_ptr_schema)) ptr_array = int(ffi.cast('uintptr_t', ret_ptr_array)) print(f'{ret_ptr_array[0]=}, {ret_ptr_schema[0]=}') print(f'python {ptr_array=:x} {ptr_schema=:x}') #print(f'{ret_ptr_array[0].buffers=} {ret_ptr_schema[0][0]=}') arr_new = pyarrow.Array._import_from_c(ptr_array, ptr_schema)