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

Add Box<T> to the supported types, where T: Sized #474

Closed
eliaslevy opened this issue Feb 21, 2020 · 4 comments
Closed

Add Box<T> to the supported types, where T: Sized #474

eliaslevy opened this issue Feb 21, 2020 · 4 comments

Comments

@eliaslevy
Copy link

As of Rust 1.41.0:

Box<T>, where T: Sized is now ABI compatible with the C language's pointer (T*)
types. So if you have an extern "C" Rust function, called from C, your Rust function can
now use Box<T>, for some specific T, while using T* in C for the corresponding function.

(from Announcing Rust 1.41.0)

So that

#[no_mangle]
pub extern fn test() -> Box<i32> { Box::new(1i32) }

should generate

int32_t * test();
@emilio
Copy link
Collaborator

emilio commented Feb 21, 2020

This makes sense. To be clear, you can already do this in C++ if you do:

template <typename T> using Box = T*;

For C, and maybe for function arguments, we probably want to do this automagically.

The reason why I think we shouldn't do it automatically for C++ members and such is that in C++ having Box<T> is actually useful (if you don't care about Box parameter-passing).

See also the discussion in #451

@mgeier
Copy link

mgeier commented Mar 27, 2020

For C, and maybe for function arguments, we probably want to do this automagically.

Are there any news on this?

It would be great to have this!

@emilio
Copy link
Collaborator

emilio commented Oct 7, 2020

4ce324c fixed this.

@emilio emilio closed this as completed Oct 7, 2020
@mgeier
Copy link

mgeier commented Oct 7, 2020

Thanks @emilio, this works great!

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

No branches or pull requests

3 participants