Skip to content

Commit 5535fc9

Browse files
committed
#140: Mark drop_c_string as unsafe
1 parent 6c3796d commit 5535fc9

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

rust/src/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl Jvm {
182182

183183
cstrings_to_drop
184184
.into_iter()
185-
.for_each(utils::drop_c_string);
185+
.for_each(|s| unsafe {utils::drop_c_string(s)});
186186

187187
int_result
188188
};

rust/src/cache.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ pub(crate) fn set_utils_exception_to_string_method(j: jmethodID) {
820820
});
821821
}
822822

823-
pub(crate) fn get_utils_exception_to_string_method() -> errors::Result<jmethodID> {
823+
pub(crate) unsafe fn get_utils_exception_to_string_method() -> errors::Result<jmethodID> {
824824
get_cached!(
825825
UTILS_THROWABLE_TO_STRING_METHOD,
826826
{
@@ -873,7 +873,7 @@ pub(crate) fn set_factory_constructor_method(j: jmethodID) {
873873
}
874874

875875
#[allow(dead_code)]
876-
pub(crate) fn get_factory_constructor_method() -> errors::Result<jmethodID> {
876+
pub(crate) unsafe fn get_factory_constructor_method() -> errors::Result<jmethodID> {
877877
get_cached!(
878878
FACTORY_CONSTRUCTOR_METHOD,
879879
{
@@ -900,7 +900,7 @@ pub(crate) fn set_factory_instantiate_method(j: jmethodID) {
900900
});
901901
}
902902

903-
pub(crate) fn get_factory_instantiate_method() -> errors::Result<jmethodID> {
903+
pub(crate) unsafe fn get_factory_instantiate_method() -> errors::Result<jmethodID> {
904904
get_cached!(
905905
FACTORY_INSTANTIATE_METHOD,
906906
{
@@ -935,7 +935,7 @@ pub(crate) fn set_factory_create_for_static_method(j: jmethodID) {
935935
});
936936
}
937937

938-
pub(crate) fn get_factory_create_for_static_method() -> errors::Result<jmethodID> {
938+
pub(crate) unsafe fn get_factory_create_for_static_method() -> errors::Result<jmethodID> {
939939
get_cached!(
940940
FACTORY_CREATE_FOR_STATIC_METHOD,
941941
{
@@ -969,7 +969,7 @@ pub(crate) fn set_factory_create_java_array_method(j: jmethodID) {
969969
});
970970
}
971971

972-
pub(crate) fn get_factory_create_java_array_method() -> errors::Result<jmethodID> {
972+
pub(crate) unsafe fn get_factory_create_java_array_method() -> errors::Result<jmethodID> {
973973
get_cached!(
974974
FACTORY_CREATE_JAVA_ARRAY_METHOD,
975975
{
@@ -1005,7 +1005,7 @@ pub(crate) fn set_factory_create_java_list_method(j: jmethodID) {
10051005
});
10061006
}
10071007

1008-
pub(crate) fn get_factory_create_java_list_method() -> errors::Result<jmethodID> {
1008+
pub(crate) unsafe fn get_factory_create_java_list_method() -> errors::Result<jmethodID> {
10091009
get_cached!(
10101010
FACTORY_CREATE_JAVA_LIST_METHOD,
10111011
{
@@ -1041,7 +1041,7 @@ pub(crate) fn set_factory_create_java_map_method(j: jmethodID) {
10411041
});
10421042
}
10431043

1044-
pub(crate) fn get_factory_create_java_map_method() -> errors::Result<jmethodID> {
1044+
pub(crate) unsafe fn get_factory_create_java_map_method() -> errors::Result<jmethodID> {
10451045
get_cached!(
10461046
FACTORY_CREATE_JAVA_MAP_METHOD,
10471047
{
@@ -1120,7 +1120,7 @@ pub(crate) fn set_invoke_method(j: jmethodID) {
11201120
});
11211121
}
11221122

1123-
pub(crate) fn get_invoke_method() -> errors::Result<jmethodID> {
1123+
pub(crate) unsafe fn get_invoke_method() -> errors::Result<jmethodID> {
11241124
get_cached!(
11251125
INVOKE_METHOD,
11261126
{
@@ -1157,7 +1157,7 @@ pub(crate) fn set_invoke_static_method(j: jmethodID) {
11571157
});
11581158
}
11591159

1160-
pub(crate) fn get_invoke_static_method() -> errors::Result<jmethodID> {
1160+
pub(crate) unsafe fn get_invoke_static_method() -> errors::Result<jmethodID> {
11611161
get_cached!(
11621162
INVOKE_STATIC_METHOD,
11631163
{
@@ -1194,7 +1194,7 @@ pub(crate) fn set_invoke_to_channel_method(j: jmethodID) {
11941194
});
11951195
}
11961196

1197-
pub(crate) fn get_invoke_to_channel_method() -> errors::Result<jmethodID> {
1197+
pub(crate) unsafe fn get_invoke_to_channel_method() -> errors::Result<jmethodID> {
11981198
get_cached!(
11991199
INVOKE_TO_CHANNEL_METHOD,
12001200
{
@@ -1229,7 +1229,7 @@ pub(crate) fn set_invoke_async_method(j: jmethodID) {
12291229
});
12301230
}
12311231

1232-
pub(crate) fn get_invoke_async_method() -> errors::Result<jmethodID> {
1232+
pub(crate) unsafe fn get_invoke_async_method() -> errors::Result<jmethodID> {
12331233
get_cached!(
12341234
INVOKE_ASYNC_METHOD,
12351235
{
@@ -1264,7 +1264,7 @@ pub(crate) fn set_init_callback_channel_method(j: jmethodID) {
12641264
});
12651265
}
12661266

1267-
pub(crate) fn get_init_callback_channel_method() -> errors::Result<jmethodID> {
1267+
pub(crate) unsafe fn get_init_callback_channel_method() -> errors::Result<jmethodID> {
12681268
get_cached!(
12691269
INIT_CALLBACK_CHANNEL_METHOD,
12701270
{
@@ -1298,7 +1298,7 @@ pub(crate) fn set_field_method(j: jmethodID) {
12981298
});
12991299
}
13001300

1301-
pub(crate) fn get_field_method() -> errors::Result<jmethodID> {
1301+
pub(crate) unsafe fn get_field_method() -> errors::Result<jmethodID> {
13021302
get_cached!(
13031303
FIELD_METHOD,
13041304
{
@@ -1332,7 +1332,7 @@ pub(crate) fn set_clone_static_method(j: jmethodID) {
13321332
});
13331333
}
13341334

1335-
pub(crate) fn get_clone_static_method() -> errors::Result<jmethodID> {
1335+
pub(crate) unsafe fn get_clone_static_method() -> errors::Result<jmethodID> {
13361336
get_cached!(
13371337
CLONE_STATIC_METHOD,
13381338
{
@@ -1366,7 +1366,7 @@ pub(crate) fn set_cast_static_method(j: jmethodID) {
13661366
});
13671367
}
13681368

1369-
pub(crate) fn get_cast_static_method() -> errors::Result<jmethodID> {
1369+
pub(crate) unsafe fn get_cast_static_method() -> errors::Result<jmethodID> {
13701370
get_cached!(
13711371
CAST_STATIC_METHOD,
13721372
{
@@ -1404,7 +1404,7 @@ pub(crate) fn set_get_json_method(j: jmethodID) {
14041404
});
14051405
}
14061406

1407-
pub(crate) fn get_get_json_method() -> errors::Result<jmethodID> {
1407+
pub(crate) unsafe fn get_get_json_method() -> errors::Result<jmethodID> {
14081408
get_cached!(
14091409
GET_JSON_METHOD,
14101410
{
@@ -1439,7 +1439,7 @@ pub(crate) fn set_check_equals_method(j: jmethodID) {
14391439
});
14401440
}
14411441

1442-
pub(crate) fn get_check_equals_method() -> errors::Result<jmethodID> {
1442+
pub(crate) unsafe fn get_check_equals_method() -> errors::Result<jmethodID> {
14431443
get_cached!(
14441444
CHECK_EQUALS_METHOD,
14451445
{
@@ -1474,7 +1474,7 @@ pub(crate) fn set_get_object_class_name_method(j: jmethodID) {
14741474
});
14751475
}
14761476

1477-
pub(crate) fn get_get_object_class_name_method() -> errors::Result<jmethodID> {
1477+
pub(crate) unsafe fn get_get_object_class_name_method() -> errors::Result<jmethodID> {
14781478
get_cached!(
14791479
GET_OBJECT_CLASS_NAME_METHOD,
14801480
{
@@ -1509,7 +1509,7 @@ pub(crate) fn set_get_object_method(j: jmethodID) {
15091509
});
15101510
}
15111511

1512-
pub(crate) fn get_get_object_method() -> errors::Result<jmethodID> {
1512+
pub(crate) unsafe fn get_get_object_method() -> errors::Result<jmethodID> {
15131513
get_cached!(
15141514
GET_OBJECT_METHOD,
15151515
{
@@ -1544,7 +1544,7 @@ pub(crate) fn set_inv_arg_java_constructor_method(j: jmethodID) {
15441544
});
15451545
}
15461546

1547-
pub(crate) fn get_inv_arg_java_constructor_method() -> errors::Result<jmethodID> {
1547+
pub(crate) unsafe fn get_inv_arg_java_constructor_method() -> errors::Result<jmethodID> {
15481548
get_cached!(
15491549
INV_ARG_JAVA_CONSTRUCTOR_METHOD,
15501550
{
@@ -1578,7 +1578,7 @@ pub(crate) fn set_inv_arg_rust_constructor_method(j: jmethodID) {
15781578
});
15791579
}
15801580

1581-
pub(crate) fn get_inv_arg_rust_constructor_method() -> errors::Result<jmethodID> {
1581+
pub(crate) unsafe fn get_inv_arg_rust_constructor_method() -> errors::Result<jmethodID> {
15821582
get_cached!(
15831583
INV_ARG_RUST_CONSTRUCTOR_METHOD,
15841584
{
@@ -1607,7 +1607,7 @@ pub(crate) fn set_inv_arg_basic_rust_constructor_method(j: jmethodID) {
16071607
});
16081608
}
16091609

1610-
pub(crate) fn get_inv_arg_basic_rust_constructor_method() -> errors::Result<jmethodID> {
1610+
pub(crate) unsafe fn get_inv_arg_basic_rust_constructor_method() -> errors::Result<jmethodID> {
16111611
get_cached!(
16121612
INV_ARG_BASIC_RUST_CONSTRUCTOR_METHOD,
16131613
{
@@ -1688,7 +1688,7 @@ pub(crate) fn set_integer_constructor_method(j: jmethodID) {
16881688
});
16891689
}
16901690

1691-
pub(crate) fn get_integer_constructor_method() -> errors::Result<jmethodID> {
1691+
pub(crate) unsafe fn get_integer_constructor_method() -> errors::Result<jmethodID> {
16921692
get_cached!(
16931693
INTEGER_CONSTRUCTOR_METHOD,
16941694
{
@@ -1716,7 +1716,7 @@ pub(crate) fn set_integer_to_int_method(j: jmethodID) {
17161716
});
17171717
}
17181718

1719-
pub(crate) fn get_integer_to_int_method() -> errors::Result<jmethodID> {
1719+
pub(crate) unsafe fn get_integer_to_int_method() -> errors::Result<jmethodID> {
17201720
get_cached!(
17211721
INTEGER_TO_INT_METHOD,
17221722
{
@@ -1784,7 +1784,7 @@ pub(crate) fn set_long_constructor_method(j: jmethodID) {
17841784
});
17851785
}
17861786

1787-
pub(crate) fn get_long_constructor_method() -> errors::Result<jmethodID> {
1787+
pub(crate) unsafe fn get_long_constructor_method() -> errors::Result<jmethodID> {
17881788
get_cached!(
17891789
LONG_CONSTRUCTOR_METHOD,
17901790
{
@@ -1812,7 +1812,7 @@ pub(crate) fn set_long_to_long_method(j: jmethodID) {
18121812
});
18131813
}
18141814

1815-
pub(crate) fn get_long_to_long_method() -> errors::Result<jmethodID> {
1815+
pub(crate) unsafe fn get_long_to_long_method() -> errors::Result<jmethodID> {
18161816
get_cached!(
18171817
LONG_TO_LONG_METHOD,
18181818
{
@@ -1860,7 +1860,7 @@ pub(crate) fn set_short_constructor_method(j: jmethodID) {
18601860
});
18611861
}
18621862

1863-
pub(crate) fn get_short_constructor_method() -> errors::Result<jmethodID> {
1863+
pub(crate) unsafe fn get_short_constructor_method() -> errors::Result<jmethodID> {
18641864
get_cached!(
18651865
SHORT_CONSTRUCTOR_METHOD,
18661866
{
@@ -1888,7 +1888,7 @@ pub(crate) fn set_short_to_short_method(j: jmethodID) {
18881888
});
18891889
}
18901890

1891-
pub(crate) fn get_short_to_short_method() -> errors::Result<jmethodID> {
1891+
pub(crate) unsafe fn get_short_to_short_method() -> errors::Result<jmethodID> {
18921892
get_cached!(
18931893
SHORT_TO_SHORT_METHOD,
18941894
{
@@ -1936,7 +1936,7 @@ pub(crate) fn set_character_constructor_method(j: jmethodID) {
19361936
});
19371937
}
19381938

1939-
pub(crate) fn get_character_constructor_method() -> errors::Result<jmethodID> {
1939+
pub(crate) unsafe fn get_character_constructor_method() -> errors::Result<jmethodID> {
19401940
get_cached!(
19411941
CHARACTER_CONSTRUCTOR_METHOD,
19421942
{
@@ -1964,7 +1964,7 @@ pub(crate) fn set_character_to_char_method(j: jmethodID) {
19641964
});
19651965
}
19661966

1967-
pub(crate) fn get_character_to_char_method() -> errors::Result<jmethodID> {
1967+
pub(crate) unsafe fn get_character_to_char_method() -> errors::Result<jmethodID> {
19681968
get_cached!(
19691969
CHARACTER_TO_CHAR_METHOD,
19701970
{
@@ -2012,7 +2012,7 @@ pub(crate) fn set_byte_constructor_method(j: jmethodID) {
20122012
});
20132013
}
20142014

2015-
pub(crate) fn get_byte_constructor_method() -> errors::Result<jmethodID> {
2015+
pub(crate) unsafe fn get_byte_constructor_method() -> errors::Result<jmethodID> {
20162016
get_cached!(
20172017
BYTE_CONSTRUCTOR_METHOD,
20182018
{
@@ -2040,7 +2040,7 @@ pub(crate) fn set_byte_to_byte_method(j: jmethodID) {
20402040
});
20412041
}
20422042

2043-
pub(crate) fn get_byte_to_byte_method() -> errors::Result<jmethodID> {
2043+
pub(crate) unsafe fn get_byte_to_byte_method() -> errors::Result<jmethodID> {
20442044
get_cached!(
20452045
BYTE_TO_BYTE_METHOD,
20462046
{
@@ -2092,7 +2092,7 @@ pub(crate) fn set_float_constructor_method(j: jmethodID) {
20922092
}
20932093

20942094
#[allow(dead_code)]
2095-
pub(crate) fn get_float_constructor_method() -> errors::Result<jmethodID> {
2095+
pub(crate) unsafe fn get_float_constructor_method() -> errors::Result<jmethodID> {
20962096
get_cached!(
20972097
FLOAT_CONSTRUCTOR_METHOD,
20982098
{
@@ -2122,7 +2122,7 @@ pub(crate) fn set_float_to_float_method(j: jmethodID) {
21222122
}
21232123

21242124
#[allow(dead_code)]
2125-
pub(crate) fn get_float_to_float_method() -> errors::Result<jmethodID> {
2125+
pub(crate) unsafe fn get_float_to_float_method() -> errors::Result<jmethodID> {
21262126
get_cached!(
21272127
FLOAT_TO_FLOAT_METHOD,
21282128
{
@@ -2174,7 +2174,7 @@ pub(crate) fn set_double_constructor_method(j: jmethodID) {
21742174
}
21752175

21762176
#[allow(dead_code)]
2177-
pub(crate) fn get_double_constructor_method() -> errors::Result<jmethodID> {
2177+
pub(crate) unsafe fn get_double_constructor_method() -> errors::Result<jmethodID> {
21782178
get_cached!(
21792179
DOUBLE_CONSTRUCTOR_METHOD,
21802180
{
@@ -2204,7 +2204,7 @@ pub(crate) fn set_double_to_double_method(j: jmethodID) {
22042204
}
22052205

22062206
#[allow(dead_code)]
2207-
pub(crate) fn get_double_to_double_method() -> errors::Result<jmethodID> {
2207+
pub(crate) unsafe fn get_double_to_double_method() -> errors::Result<jmethodID> {
22082208
get_cached!(
22092209
DOUBLE_TO_DOUBLE_METHOD,
22102210
{
@@ -2277,7 +2277,7 @@ pub(crate) fn set_get_classloader_method(j: jmethodID) {
22772277
}
22782278

22792279
#[cfg(target_os = "android")]
2280-
pub(crate) fn get_get_classloader_method() -> errors::Result<jmethodID> {
2280+
pub(crate) unsafe fn get_get_classloader_method() -> errors::Result<jmethodID> {
22812281
get_cached!(
22822282
GET_CLASSLOADER_METHOD,
22832283
{
@@ -2304,7 +2304,7 @@ pub(crate) fn set_load_class_method(j: jmethodID) {
23042304
}
23052305

23062306
#[cfg(target_os = "android")]
2307-
pub(crate) fn get_load_class_method() -> errors::Result<jmethodID> {
2307+
pub(crate) unsafe fn get_load_class_method() -> errors::Result<jmethodID> {
23082308
get_cached!(
23092309
GET_LOAD_CLASS_METHOD,
23102310
{

rust/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ pub fn to_c_string_struct(string: &str) -> CString {
4141
unsafe { CString::from_vec_unchecked(enc) }
4242
}
4343

44-
pub fn drop_c_string(ptr: *mut c_char) {
45-
let _ = unsafe { CString::from_raw(ptr) };
44+
pub unsafe fn drop_c_string(ptr: *mut c_char) {
45+
let _ = CString::from_raw(ptr);
4646
}
4747

4848
#[cfg(not(target_os = "windows"))]

0 commit comments

Comments
 (0)