Giter Site home page Giter Site logo

Comments (7)

iduartgomez avatar iduartgomez commented on June 29, 2024

Thanks for the report, hopefully will take a look this week.

from rustypy.

iduartgomez avatar iduartgomez commented on June 29, 2024

I have reproduced the issue both in the container and in my local environment with a fresh virtualenv.

Running the tests on a fresh virtualenv worked though (maybe if you perform pip install . from the source it would work with pytest, this is what is done in CI and local dev). Nevertheless it doesn't matter as I could reproduce it in local dev, will check what is going on.

from rustypy.

iduartgomez avatar iduartgomez commented on June 29, 2024

I've identified the issue. For this particular case of the provided example library (a single extern C fn), the syn parser does not seem to like the content of the library , what ends up happening is that internally syn catches an unwinding panic and then returns, but without any parsed content whatsoever!

This means the crate data is never visited by the parser and hence no fn calls are generated... but it returns successfully. Gonna experiment a bit more to be sure this is the only problem. The fix in this case IMO would be to ensure that there have been any bindings generated (the caller is expecting at least one binding), and if there are none, then propagate the error. Additionally maybe document this behavior so is not unexpected in the future.

This would be less cryptic than just an AttributeError.

EDIT: The unwinding happens always and I got confused cause I was not passing the prefix appropriately, it actually parses the function but I am not generating the binds correctly as the type is not being appropriately annotated.

from rustypy.

iduartgomez avatar iduartgomez commented on June 29, 2024

@craigfay I failed to see an other problem, you cannot return a Vec<i32> here, you must return a raw pointer with the wrapper type, *mut PyList (so is required to use the rustypy library in the Rust side too) in Rust, and then in Python bind it appropriately specifying the return type.

Check tests.test_rs_to_py.GenerateRustToPythonBinds.test_list_conversion test for an example, maybe this is not sufficiently explained in the Wiki, neither in the "Type conversions#Calling Rust from Python" section nor the "Calling Rust from Python" one and should point to those examples or write a standalone full example. Also how to link rustypy in Rust is not pointed either...

PR to the Wiki to improve all this is welcome.

Ideally I wanted to write a proc macro to handle all the FFI automatically and generate the extern function calls automatically, with a lot of work this could also be handled automatically from the Python side, but for now it must be done manually by the caller.

from rustypy.

iduartgomez avatar iduartgomez commented on June 29, 2024

Discovered the error on the python side, you are passing an empty list for prefixes which shouldn't be allowed, have to catch this and raise an error.

from rustypy.

iduartgomez avatar iduartgomez commented on June 29, 2024

@craigfay I uploaded a new version with a couple fixes and also made a PR (craigfay/rustypy_debug#1) to your example repo with a couple changes needed to fix it. If you rebuild the docker image from scratch it should work now.

A PR to improve documentation/examples for clarity here is also welcome.

I uploaded the bridging library to crates.io for easier linking, the whole process now is a bit inefficient though as it's compiled twice (once in Python and other in Rust), so could be streamlined in the future probably.

from rustypy.

iduartgomez avatar iduartgomez commented on June 29, 2024

Closing the issue, if there is any problem let me know! Thanks for the report.

from rustypy.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.