(Note: we somehow lost the rust-dev cc, see Stefan's e-mail below)

Under the plan as I envisioned it in my head, ignoring the question about unsafety, it would be necessary to write a wrapper for a C function if you wanted it to have the same type as a Rust fn (as opposed to an `extern "C" fn()` type).  However, I could imagine permitting extern fn items to be coerced to Rust type, and having the compiler auto-generate a wrapper.  We plan to do something similar with top-level Rust fns: they will be coercable to a C function type, so that any Rust fn item can used as a callback, and not just an "extern fn".  However, this of course immediately raises the question of unsafety: we could presumably want a way to declare that those C functions are safe as well.

Another option is just to use a macro, of course.  Or that would be an option if we supported item-level macros, which we hopefully will soon.

The question I guess is how often this situation comes up.  Is it just libmath? Or is this sort of thing extremely common when doing bindings?


Niko

October 15, 2012 12:35 AM

So will it be necessary to write wrappers manually in the future? Right now f32 just re-exports native functions explicitly marked as pure in cmath:c_float.
How would that change? Don't really care that much as long as it doesn't become a boilerplaty hassle ;)


Cheers,


Stefan.


October 14, 2012 1:36 PM
Most likely such wrappers will be needed anyway eventually, because C functions are going to have type `extern "C" fn(...)` as part of <https://github.com/mozilla/rust/issues/3678>.  (Right now rustc generates those wrappers automatically)


Niko

Stefan Plantikow wrote:
October 13, 2012 2:55 AM


will there be a way to explicitly mark them as safe? Asking because if we go down this route, all calls in libmath will become unsafe without wrapping them in functions with unsafe blocks and that seems wrong.



boggle.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev
October 12, 2012 12:29 PM
+1 (one developer, one vote!) ;)

October 12, 2012 11:38 AM


+2

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to