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

Problem casting mut ref in call to native function #2214

Closed
boggle opened this issue Apr 15, 2012 · 6 comments
Closed

Problem casting mut ref in call to native function #2214

boggle opened this issue Apr 15, 2012 · 6 comments
Labels
A-codegen Area: Code generation I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@boggle
Copy link
Contributor

boggle commented Apr 15, 2012

Passing a v: &mut int to a function in a native module that expects a &mut c_int via a type cast v as &mut c_int yields an internal compiler error

I hit this when rewriting math and am logging this here.

@brson
Copy link
Contributor

brson commented Apr 16, 2012

Do you have a test case?

@boggle
Copy link
Contributor Author

boggle commented Apr 16, 2012

Hit this when writing the new lib math in a currently unused function, went for using plain pointers for now.

cf. https://github.com/boggle/rust/blob/libmath/src/libmath/math_impl/generic.rs#L163 which calls https://github.com/boggle/rust/tree/libmath/src/libmath/math_impl#L67

@ghost ghost assigned brson Apr 19, 2012
@catamorphism
Copy link
Contributor

This appears to have been fixed fortuitously. I added a test case -- src/test/run-pass/issue-2214.rs -- which I believe tests the same issue, and it passes. Closing.

@nikomatsakis
Copy link
Contributor

So... I am looking at this test now... casting a *int to a *c_int does not seem like a particularly good idea, as int and c_int have different sizes. I guess int is strictly larger than c_int, so this probably works out ok on a little-endian machine, but in general it's not something we want in our libraries.

@boggle
Copy link
Contributor Author

boggle commented Aug 4, 2012

I thought rust int was defined as == c_int. Have to think about this in terms of math lib.

@nikomatsakis
Copy link
Contributor

No, they are not the same. That's why we give a warning if you use Rust int in the definition of a native function. A rust int is the same as C's intptr_t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

4 participants