Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jitclass cffi pointer #3043

Open
wrongbad opened this issue Jun 19, 2018 · 2 comments
Open

jitclass cffi pointer #3043

wrongbad opened this issue Jun 19, 2018 · 2 comments

Comments

@wrongbad
Copy link

Feature request

Similar to how cfunc.cffi generates function pointers for use with cffi
It would be very useful for jitclasses to be transformable to/from cffi void* pointers
This would be especially useful for cffi libraries that take callback func and a void* userdata
The userdata could be a jitclass, offering structured data for free in both the interpreter and "c" context

@wrongbad
Copy link
Author

wrongbad commented Jun 23, 2018

I'm in over my head here.

I see now that there is a note specifically about this "deferred topic" in cfunc.rst

I've found that I can have my jitclass instance "myObject" which contains only an array and pass _box.box_get_dataptr(myObject) to a cffi void*, and then interpret as a carray to read-write it. However this is obviously incorrect because when I come by later to print myObject in the interpreter it segfaults. So I'm apparently not getting the pointer to the backing array data, or the struct I assumed would share the same base address, and instead scribbling on some meta-data the python object needs.

I suppose a completely alternative approach is getting buffer api support for jitclasses and then constructing the object-view independently inside the callback - same as the carray() mechanism which is simple and reliable. I don't know enough about how carray gets compiled, hopefully this approach doesn't require mallocing to construct the "view", where you wouldn't in a pure-c approach. I'm skeptical of this because it looks like python buffers are designed somewhat specifically around the homogenous array use case, with multi-dims and strides and such.

And yet another approach is a pure python mechanism to process a nested class structure, calculating sizes and offsets to make it a view for a single numpy array or bytes object. Then simply piggy-back the working mechanism for arrays to/from void*.

@wrongbad
Copy link
Author

Looks like I can't use any of the nice carray() things if I want to avoid mallocs completely (e.g. for a real-time callback). Major oversight on my part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants