Skip to content

Commit

Permalink
Make jboolean an alias for bool instead of u8
Browse files Browse the repository at this point in the history
JNI only strictly defines two valid values for a `jboolean`
and there's no consensus on whether other values greater than one will
be interpreted as TRUE in all situations.

The safest interpretation is to say that it will lead to undefined
behaviour to pass any value besides zero or one as a `jboolean`.

Addresses jni-rs/jni-rs#400
Closes #19
  • Loading branch information
rib committed Jun 21, 2023
1 parent f0db59a commit b478617
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub type va_list = *mut c_void;
pub type jint = i32;
pub type jlong = i64;
pub type jbyte = i8;
pub type jboolean = u8;
pub type jboolean = bool;
pub type jchar = u16;
pub type jshort = i16;
pub type jfloat = f32;
Expand Down Expand Up @@ -68,8 +68,8 @@ pub enum jobjectRefType {
JNIWeakGlobalRefType = 3,
}

pub const JNI_FALSE: jboolean = 0;
pub const JNI_TRUE: jboolean = 1;
pub const JNI_FALSE: jboolean = false;
pub const JNI_TRUE: jboolean = true;

pub const JNI_OK: jint = 0;
pub const JNI_ERR: jint = -1;
Expand Down
6 changes: 6 additions & 0 deletions systest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,11 @@ fn main() {
// dllimport weirdness?
windows
});
cfg.skip_roundtrip(|s| {
matches!(
s,
"jboolean" // We don't need to be able to roundtrip all possible u8 values for a jboolean, since only 0 are 1 are considered valid.
)
});
cfg.header("jni.h").generate("../src/lib.rs", "all.rs");
}

0 comments on commit b478617

Please sign in to comment.