helix icon indicating copy to clipboard operation
helix copied to clipboard

Use the standard convention for function pointers in libcruby

Open sgrif opened this issue 7 years ago • 6 comments

Typically you never take extern "C" fn directly, as there is no way to pass NULL there without using transmute. Bindgen and most other tools generally use Option for this purpose.

I've also changed the alloc and free functions to use the functions provided on box for converting to/from pointers, rather than relying on its internal representation. There's still the transmute on the class, but I'm not entirely sure what that's doing so I've left it alone for now.

sgrif avatar Nov 08 '17 18:11 sgrif

I'd like to discuss this with some Rust people before making this change.

wycats avatar Nov 28 '17 15:11 wycats

Did you ever get a chance to discuss this with some Rust people?

sgrif avatar Jan 10 '18 20:01 sgrif

@sgrif I did... I'm not convinced by your assertion that this is the "standard convention", nor do I know how to feel confident that Option has the representation you expect. @nikomatsakis convinced me that it's "unlikely to change" due to pervasiveness, but I really don't like the idea of depending on happenstances of representation (especially given the fact that fn representation has changed in the recent past).

wycats avatar Jan 11 '18 04:01 wycats

I called it the "standard convention", since it's what bindgen generates,

sgrif avatar Jan 11 '18 19:01 sgrif

@wycats @sgrif what's the status here?

wagenet avatar Mar 21 '18 23:03 wagenet

Is this superseded by #160?

wycats avatar Jul 29 '19 18:07 wycats