Skip to content

Pyray : convert function arguments based on c function signature #53

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Lcbx
Copy link

@Lcbx Lcbx commented Dec 15, 2021

Hi,

while testing the Pyray module I stumbled upon your comment about function calls using a lot of string comparisons at runtime, so here's an alternative that basically converts python arguments to the type expected by the c function.

Interestingly I have not found that great a performance improvement on the script I tested it on (~3%)
but at least we don't inspect the c function at each call anymore.

keep being awesome !

@Lcbx
Copy link
Author

Lcbx commented Dec 15, 2021

just found a bug using this.

some arguments expect pointers but can be given non ffi pointers ;
however since signatures expects a pointer it calls ffi.addressof on the argument and crashes. Imma fix that.

@Lcbx
Copy link
Author

Lcbx commented Dec 15, 2021

not the best fix but it works

@Lcbx
Copy link
Author

Lcbx commented Dec 15, 2021

found a way to check on type rather than str(type)

should be robust and work with dynamic since the C_POINTER type we check is determined in pyRay init

@electronstudio
Copy link
Owner

This looks like quite a major change so will probably take me a while to review it. Let me know when it’s finished anyway.

@Lcbx
Copy link
Author

Lcbx commented Dec 16, 2021

The implementation change is around 15 loc, only in pyray/init.py
other files are changes to examples

@Lcbx
Copy link
Author

Lcbx commented Dec 16, 2021

oh yeah and it's pretty much finished afaik,
tested it on a few examples (your pyrayTest, bunnyMark, boxCollisions and animation)

@electronstudio
Copy link
Owner

electronstudio commented Feb 3, 2022

Example is added, thanks. I had to add an unsigned int* to satisfy Raylib though,

@electronstudio
Copy link
Owner

oh i see, you wrote a special case for that call to add the unsigned int*. i don't really want to be special casing anything.

@electronstudio
Copy link
Owner

do you have a benchmark that shows a difference for the changes to pyray/init.py ?

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

Successfully merging this pull request may close these issues.

2 participants