Skip to content

Commit

Permalink
Merge pull request #31 from jni-rs/rib/pr/warn-missing-debug-impl
Browse files Browse the repository at this point in the history
Warn on missing_debug_implementations
  • Loading branch information
rib authored Aug 31, 2023
2 parents 065c79a + f5dc14f commit 52baab2
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![doc(html_root_url = "https://docs.rs/jni-sys/0.3.0")]
#![allow(non_snake_case, non_camel_case_types)]
#![warn(rust_2018_idioms)]
#![warn(rust_2018_idioms, missing_debug_implementations)]

use std::os::raw::c_char;
use std::os::raw::c_void;
Expand All @@ -20,6 +20,7 @@ pub type jfloat = f32;
pub type jdouble = f64;
pub type jsize = jint;

#[derive(Debug)]
pub enum _jobject {}
pub type jobject = *mut _jobject;
pub type jclass = jobject;
Expand Down Expand Up @@ -56,9 +57,39 @@ impl Clone for jvalue {
*self
}
}
impl std::fmt::Debug for jvalue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let b = unsafe { self.b };
// For all except `jboolean` then any bitwise pattern is a valid value
// so even though we don't know which specific type the given `jvalue`
// represents we can effectively cast it to all possible types.
f.debug_struct("jvalue")
.field(
"z",
&if b == 0 {
"false"
} else if b == 1 {
"true"
} else {
"invalid"
},
)
.field("b", unsafe { &self.b })
.field("c", unsafe { &self.c })
.field("s", unsafe { &self.s })
.field("i", unsafe { &self.i })
.field("j", unsafe { &self.j })
.field("f", unsafe { &self.f })
.field("d", unsafe { &self.d })
.field("l", unsafe { &self.l })
.finish()
}
}

#[derive(Debug)]
pub enum _jfieldID {}
pub type jfieldID = *mut _jfieldID;
#[derive(Debug)]
pub enum _jmethodID {}
pub type jmethodID = *mut _jmethodID;

Expand Down Expand Up @@ -94,7 +125,7 @@ pub const JNI_VERSION_9: jint = 0x00090000;
pub const JNI_VERSION_10: jint = 0x000a0000;

#[repr(C)]
#[derive(Copy)]
#[derive(Copy, Debug)]
pub struct JNINativeMethod {
pub name: *mut c_char,
pub signature: *mut c_char,
Expand Down Expand Up @@ -1274,7 +1305,7 @@ pub struct JNINativeInterface_ {
}

#[repr(C)]
#[derive(Copy)]
#[derive(Copy, Debug)]
pub struct JNIEnv_ {
pub functions: *const JNINativeInterface_,
}
Expand All @@ -1286,7 +1317,7 @@ impl Clone for JNIEnv_ {
}

#[repr(C)]
#[derive(Copy)]
#[derive(Copy, Debug)]
pub struct JavaVMOption {
pub optionString: *mut c_char,
pub extraInfo: *mut c_void,
Expand All @@ -1299,7 +1330,7 @@ impl Clone for JavaVMOption {
}

#[repr(C)]
#[derive(Copy)]
#[derive(Copy, Debug)]
pub struct JavaVMInitArgs {
pub version: jint,
pub nOptions: jint,
Expand All @@ -1314,7 +1345,7 @@ impl Clone for JavaVMInitArgs {
}

#[repr(C)]
#[derive(Copy)]
#[derive(Copy, Debug)]
pub struct JavaVMAttachArgs {
pub version: jint,
pub name: *mut c_char,
Expand Down

0 comments on commit 52baab2

Please sign in to comment.