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

Access to foreign function interface (FFI)? #15

Open
eriksank opened this issue Apr 29, 2022 · 4 comments
Open

Access to foreign function interface (FFI)? #15

eriksank opened this issue Apr 29, 2022 · 4 comments

Comments

@eriksank
Copy link

eriksank commented Apr 29, 2022

Would it be possible to expose Rust's FFI functionality for invoking (over the C ABI) functions located in external libraries?

https://doc.rust-lang.org/nomicon/ffi.html

That would allow hush shell users to use a world of existing software.

@gahag
Copy link
Collaborator

gahag commented Apr 29, 2022

Yes, I have plans on implementing it such that std.import would be able to import not only other Hush scripts, but native libraries too. It will take some work though, as I'll have to figure out how to safely share garbage collected objects through the FFI.

@eriksank
Copy link
Author

I wonder if the current dichotomy between HushFun and RustFun in src/runtime/value/function.rs can also handle out of the box functions en provenance from the C ABI?

Since a C function is typified by barely much more than a void pointer, I somehow suspect that memory allocated by such C functions will be very difficult to deallocate by the Hush shell. If the user doesn't free it manually, I think that the process will simply leak memory.

Rust itself considers native C code to be fundamentally unsafe.

That point is certainly conceded, but we still need to somehow reuse external native code. For example, using GTK or QT will always potentially leak memory.

We would still benefit from these things being available, regardless of their unsafety ...

@gahag
Copy link
Collaborator

gahag commented Apr 29, 2022

Makes sense to me. I guess we could add an ExternalFun struct, which would invoke a function through the FFI. Just need to figure out which useful parameters we should pass, and what to do with the return value. Sounds good to you?

@eriksank
Copy link
Author

Yes!

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

No branches or pull requests

2 participants