File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -1233,6 +1233,30 @@ impl Jvm {
1233
1233
}
1234
1234
}
1235
1235
1236
+ /// Consumes an `Instance` and returns its jobject. The returned jobject is a JNI local reference.
1237
+ pub fn instance_into_raw_object ( & self , instance : Instance ) -> errors:: Result < jobject > {
1238
+ debug ( & format ! ( "Getting the raw jobject from instance of class {}" , instance. borrow( ) . class_name( ) ) ) ;
1239
+ // Call the getObjectMethod. This returns a localref
1240
+ let object_instance = unsafe {
1241
+ ( opt_to_res ( cache:: get_jni_call_object_method ( ) ) ?) (
1242
+ self . jni_env ,
1243
+ instance. jinstance ,
1244
+ cache:: get_get_object_method ( ) ?,
1245
+ ) } ;
1246
+
1247
+ Self :: do_return (
1248
+ self . jni_env ,
1249
+ object_instance,
1250
+ )
1251
+ }
1252
+
1253
+ /// Consumes the `Jvm` and returns its `JNIEnv`
1254
+ pub fn into_raw ( self ) -> * mut JNIEnv {
1255
+ debug ( & format ! ( "Getting the raw JNIEnv from the Jvm" ) ) ;
1256
+
1257
+ self . jni_env
1258
+ }
1259
+
1236
1260
/// Returns the Rust representation of the provided instance, boxed
1237
1261
pub fn to_rust_boxed < T > ( & self , instance : Instance ) -> errors:: Result < Box < T > >
1238
1262
where
Original file line number Diff line number Diff line change @@ -163,6 +163,7 @@ mod lib_unit_tests {
163
163
use std:: collections:: HashMap ;
164
164
use std:: convert:: TryFrom ;
165
165
use std:: path:: MAIN_SEPARATOR ;
166
+ use std:: ptr:: null_mut;
166
167
use std:: thread:: JoinHandle ;
167
168
use std:: { thread, time} ;
168
169
@@ -1302,4 +1303,22 @@ mod lib_unit_tests {
1302
1303
assert ! ( jvm. check_equals( & null_instance, InvocationArg :: try_from( Null :: Integer ) ?) ?) ;
1303
1304
Ok ( ( ) )
1304
1305
}
1306
+
1307
+ #[ test]
1308
+ fn instance_into_raw_object ( ) -> errors:: Result < ( ) > {
1309
+ let jvm = create_tests_jvm ( ) ?;
1310
+ let test_instance = jvm. create_instance ( "org.astonbitecode.j4rs.tests.MyTest" , InvocationArg :: empty ( ) ) ?;
1311
+ let null_instance = jvm. invoke ( & test_instance, "getNullInteger" , InvocationArg :: empty ( ) ) ?;
1312
+ let jobj = jvm. instance_into_raw_object ( null_instance) ?;
1313
+ assert ! ( jobj == null_mut( ) ) ;
1314
+ Ok ( ( ) )
1315
+ }
1316
+
1317
+ #[ test]
1318
+ fn jvm_into_raw_object ( ) -> errors:: Result < ( ) > {
1319
+ let jvm = create_tests_jvm ( ) ?;
1320
+ let jobj = jvm. into_raw ( ) ;
1321
+ assert ! ( jobj != null_mut( ) ) ;
1322
+ Ok ( ( ) )
1323
+ }
1305
1324
}
You can’t perform that action at this time.
0 commit comments