jni-rs / jni-sys

Apache License 2.0
55 stars 20 forks source link

Fix crash on Windows x86 32 bits. Use correct calling conventions. #4

Closed robmv closed 7 years ago

robmv commented 7 years ago

JNICALL on Windows is defined as __stdcall. All non varargs functions now use extern "system" in order to let Rust compiler choose stdcall on Windows x86 32 bits, for 64 bits and other platforms "system" == "C".

sfackler commented 7 years ago

Thanks! @sstecko I think this may explain some of the craziness you were seeing on 32 bit Windows.

sfackler commented 7 years ago

Published as 0.2.3

robmv commented 7 years ago

Thanks, that was fast 😂

sstecko commented 7 years ago

😀 Wow! Thanks much. This makes a lot of sense.

sstecko commented 7 years ago

Ah unfortunately this didn't address my specific issue. I still get a "Exception code: 0xc0000005" when trying to call FindClass on windows i686 32 bit

robmv commented 7 years ago

@sstecko If you have a small test case, I can look at it tomorrow when I have a Windows near.

I am using the jni crate, a wrapper consumer of jni-sys. My crash happened accesing the result of my first call to a JNIEnv function, specifically GetStringUTFChars.

I call this too:

fn throw_exception(env: &JNIEnv, message: &str) {
    let rt_ex = env.find_class("java/lang/RuntimeException").unwrap();
    env.throw_new(rt_ex, message).unwrap();
}

that should call FindClass, but haven't seen the case on Windows 32 bit when it actually fails and the exception is thrown. I will force it tomorrow to see what happen.

sfackler commented 7 years ago

I've gotten ctest set up so we shouldn't run into anything like this in the future hopefully: #5.