-
Notifications
You must be signed in to change notification settings - Fork 352
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
Expose the full API for dynamic libraries and remove the need of using function pointers #139
base: master
Are you sure you want to change the base?
Conversation
I was a bit too early, there's still something wrong with the generated shared lib. Will push as soon as I have figured out the problem. |
Yeah, was about to say I can't get it to link with Clang. It says all the functions are missing. Also a heads up that it looks like you find/replaced "static" everywhere, including (non-function) things that were definitely supposed to be static, and some doc comments about "static bodies". ;) My understanding of inline functions in C99 was that an inline function will hint to inline the function within it's own module only. Extern references to it would be regular function calls. Static inline functions get around that by making a private copy in each module, and skipping code generation if the function is unused. I didn't realize you could even put a non-inline function in a header without causing duplicate symbols, inline or not. I'm still not sure how it didn't cause duplicate symbol errors, and even more surprised that the linker can't find the functions at all. So, my biggest worry is, have you run the benchmarks? With inlining disabled, Chipmunk is several times slower. Assuming the linking issue is resolvable, if the functions aren't inlined across modules then the performance is not going to be good. Quite honestly, for most of the affected functions, I often recommend using a native type to implement them anyway. Do you really want to use cpfmin() instead of your language's generic min function? Even the vector functions are pretty trivial to reimplement in a hundred lines of code or so if you don't already have a preferred vector type. |
Hi, thanks for your comments. One note, though: the functions still are And agreed, some functions could be just as well implemented in the native language. Yet having the complete API makes it easier to do a full automated import of the library, and I'm not sure what the performance penalties are, given that calling C code is usually very fast. Edit: and you got me there, definitely shouldn't make those variables non-static. |
This is related to pull #79, only this time for 7.x and working demos :)
All
static inline
functions have been madeinline
with corresponding declarations in their translation units, as recommended by the C standard. As a side-effect, Chipmunk now compiles to shared libraries which have the full set of functions defined in the headers built into them, as opposed to only the function pointers inchipmunk_ffi.h
.Implementors of bindings to this library can still use the "old" way of using function pointers with
cmake -DFUNCTION_POINTERS
if they want to, but I recommend deprecating this approach and eventually removing it (unless I'm missing something). The way I did this is, is by movingchipmunk_ffi.h
to a separate translation unit and adding it when the option is enabled inCMakeLists.txt
.Will be testing and using this in the Racket bindings.