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

ignored __stdcall #547

Closed
Dushistov opened this issue Feb 28, 2017 · 11 comments
Closed

ignored __stdcall #547

Dushistov opened this issue Feb 28, 2017 · 11 comments
Labels

Comments

@Dushistov
Copy link
Contributor

This simplified example to demonstrate error, that cause random crashes,
in jni dll (windows 7 32bit) written on rust. The cause is silent replace of __stdcall calling conversation
with __cdecl calling conversation:

Input C/C++ Header

struct JNINativeInterface_ {
  int (__stdcall *GetVersion)(void *env);
};

Bindgen Invokation

$ bindgen test.h 

Actual Results

#[repr(C)]
#[derive(Debug, Copy)]
pub struct JNINativeInterface_ {
    pub GetVersion: ::std::option::Option<unsafe extern "C" fn(env:
                                                                   *mut ::std::os::raw::c_void)
                                              -> ::std::os::raw::c_int>,
}

Expected Results

#[repr(C)]
#[derive(Debug, Copy)]
pub struct JNINativeInterface_ {
    pub GetVersion: ::std::option::Option<unsafe extern "stdcall" fn(env:
                                                                   *mut ::std::os::raw::c_void)
                                              -> ::std::os::raw::c_int>,
}
@emilio
Copy link
Contributor

emilio commented Feb 28, 2017

Huh, we should keep track of that, thanks for the report.

@emilio emilio added the bug label Feb 28, 2017
@emilio
Copy link
Contributor

emilio commented Feb 28, 2017

So, fun part is I can't reproduce because I don't have a windows machine. That being said, I can probably find something or coerce libclang to show it.

Meanwhile, if you could do the following for me, it'd be super-helpful:

  • Run bindgen with:
__stdcall void bar();
  • Run your example with --emit-clang-ast.
  • Run your example with RUST_LOG=bindgen

And post the results here, it'd be great :)

Thanks in advance!

@emilio
Copy link
Contributor

emilio commented Mar 1, 2017

See #549, this is arguably a libclang bug :(. That patch works around the issue and should work.

Thanks for reporting!

@Dushistov
Copy link
Contributor Author

Dushistov commented Mar 1, 2017

here result of

set RUST_LOG=bindgen
bindgen --version
INFO:bindgen: Clang Version: clang version 3.9.0 (branches/release_39)
bindgen 0.22.0
bindgen --emit-clang-ast test3.h > clang-output.txt 2>rust-log.txt

clang-output.txt
rust-log.txt

@Dushistov
Copy link
Contributor Author

So, fun part is I can't reproduce because I don't have a windows machine.

I used virtual box image, that provide Microsoft for free:

https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/

See #549, this is arguably a libclang bug :(. That patch works around the issue and should work.

note, that by default bindgen emit code with derive(Debug), but this is actually not works
for stdcall fn pointers: see my rustc bug report

@emilio
Copy link
Contributor

emilio commented Mar 1, 2017

note, that by default bindgen emit code with derive(Debug), but this is actually not works
for stdcall fn pointers.

😞

I'll have to add an explicit path for that I guess. Sigh. Does derive(Copy) work?

@Dushistov
Copy link
Contributor Author

Dushistov commented Mar 1, 2017

I'll have to add an explicit path for that I guess. Sigh.

For note: this is Sun/Oracle guys fault in usage of __stdcall for JNI interface for Java, not my :)

Does derive(Copy) work?

Yes

@emilio
Copy link
Contributor

emilio commented Mar 1, 2017

For note: this is Sun/Oracle guys fault in usage of __stdcall for JNI interface for Java, not my :)

Oh, sure, sorry if I made you think this was somehow your fault. It's just quite disappointing to see this intersection between libclang and rustc bugs that makes bindgen even more complicated than what it is :(

@emilio
Copy link
Contributor

emilio commented Mar 1, 2017

Actually reading that bug and the rust source seems even funnier. Since there's a hard-coded limit in the number of arguments they implement these traits for, that means that bindgen will not produce compilable code for stuff like:

typedef void (*my_fun_t)(int, int, int, int, int, int, int, int, int, int, int,
                         int, int, int, int, int);

struct Foo {
  my_fun_t callback;
};

@emilio
Copy link
Contributor

emilio commented Mar 1, 2017

I added a fix for that too at #549.

@Dushistov
Copy link
Contributor Author

Thanks, I tested on windows 7 (32 bit), and at now my project(https://github.com/Dushistov/rust_swig) works on windows without problems, at least all tests passed.

Dushistov added a commit to Dushistov/flapigen-rs that referenced this issue Mar 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants