-
Notifications
You must be signed in to change notification settings - Fork 13.3k
FFI call to C adds an extra argument before the specified argument list #7627
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
Comments
You probably need to use |
I had the functions returning
It looks like Rust enums are passed as C structs. The cdecl calling convention specifies that to return a structure, the caller passes a hidden first argument. I fixed it by removing the return type from my
I suppose |
I added documentation for when to use and not to use `c_void`, since it tripped me up when I started. (See issue #7627)
…-again, r=llogiq Updating issue templates again for rustbot It turns out that our current issue template can sometimes trigger a rustbot error message, as can be seen in [rust-lang#7626](rust-lang/rust-clippy#7626). I originally tested this in rust-lang#7599, but it's apparently a bit inconsistent. This PR adds backticks to the commands, as correctly suggested by `@mikerite` in the comments. (Thank you!) ``@rustbot` label +S-blocked` --- Now I also pushed a tiny link fix as well. 🙃 --- changelog: none
I'm trying to call a function in a C library with two args, a pointer and an int, and was seeing the C function segfault. When I break on the C function in GDB, I see that the pointer I passed in the first argument from Rust shows up in the second argument, and there's another address added as the first argument.
Simplified to a minimal example by passing a constant for the pointer to show that it's shifted into the second argument:
I'm using Fedora 18, 32-bit
rustc 0.7 (3e933b1 2013-07-06 08:32:10 -0700)
host: i686-unknown-linux-gnu
Here's the original code and GDB output:
I also tried calling
libusb_exit(ctx)
, and it also receives the wrong pointer and segfaults.The text was updated successfully, but these errors were encountered: