rpav / cl-autowrap

(c-include "file.h") => complete FFI wrapper
BSD 2-Clause "Simplified" License
214 stars 41 forks source link

Passing and returning structs by value #41

Open o-simon opened 9 years ago

o-simon commented 9 years ago

I'm trying to autowrap Chipmunk2D, a C library for 2D physics simulation: https://github.com/slembcke/Chipmunk2D

Many functions return and receive by value a structure that represents a 2D vector (cpVect if you are interested).

In the FAQs you mention to let you know if passing structs by value is necessary so you can prioritize this issue :D

What do you think? Is it doable?

Thank you!

rpav commented 9 years ago

It's doable, not sure how quickly though. ;) Basically, it just requires wrapping libffi and generating calls to that rather than "normal". I'll look into this and update.

o-simon commented 9 years ago

Thank you very much!

If there's a workaround I could use for the meantime, please let me know.

attila-lendvai commented 9 years ago

cffi itself has some support for struct by value, but it might be the case that autowrap skips the layer of cffi that would handle that...? sorry, that's all i know.

rpav commented 9 years ago

That's correct; CFFI wraps libffi for calls, but this would mean interfacing with its higher-level struct definition etc which autowrap more or less entirely ignores (for various reasons). Actually implementing this shouldn't be hard: autowrap can autowrap it. I'm just in the middle of another project at the moment unfortunately.

rpav commented 7 years ago

This is finally more-or-less implemented in the libffi branch. You need to load cl-autowrap/libffi. This can be used as a sole dependency or loaded after the fact.

Currently:

rpav commented 7 years ago

Some other caveats: