How I create a Record type for a struct of voidpointers

I am using numba to interface to a c-function library. One function requires me to pass in a struct containing a list of void-pointers to external function calls. I plan to implement my functions through numbas cfunc wrapper, as per the cfunc numba manual and call the function inside my jitted functions following the guide in the docs (“calling-c-code-from-numba”, sorry can’t post links for some reason).

To do this I need to implement the function signature.

Here’s what I thought I could do initially for my struct (fmi2CallbackFunctions_numba:

from numba import types

fmi2CallbackFunctions_numba = types.Record.make_c_struct([
     ("logger", types.voidptr),
     ("allocateMemory", types.voidptr), 
     ...
])

The problem I am faced with is that numbas types.Record.make_c_struct does not support void pointers. So how can I extend that support of work around it?
Hope to hear some good suggestions :slight_smile:

Can you use integers and casting?

Hi, thanks for your reply. Are you asking me a question, or are you telling me I can do that? Can you give me an example? I didn’t find anything in the docs describing this particular case.

If I check ctypes, a void pointer typically takes up int64, so 8 bytes. But it seems llvm represents them by i8, so 1 byte. I’m not sure which one I should use in that case. Finally, how would the c wrapped function know that I’m passing it a pointer to a function, when I would be in fact, passing an integer?

Sorry for the questions, maybe it’s obvious if you’re a c programmer, but I’m just an engineer who’s trying to use numba to speed up calculations.

You can do that. There are examples here on discourse, and numbsql has some great examples.

Thanks again. I looked into the library, and there’s alot of @intrinsic calls, which seems to have very little documentation apart from one small example (but no explanations). Passing integers as addresses to pointers and then casting them as pointers did indeed occur to me as a possibility, that I’ve seen others apply as a work-around. Being what it is, a work-around, it occurs to me that this part of numba is fairly untouched. I’ll try to fiddle around and see what I can come up with.