Skip to content

Commit 4eae5db

Browse files
authored
Fix autocorrect-java build error. (#296)
1 parent 60fd6d4 commit 4eae5db

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

autocorrect-java/src/lib.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use autocorrect::{LineResult, LintResult};
2+
use jni::JNIEnv;
23
use jni::objects::{JClass, JString};
34
use jni::sys::{jboolean, jintArray, jlong, jsize, jstring};
4-
use jni::JNIEnv;
55

6-
#[no_mangle]
6+
#[unsafe(no_mangle)]
77
pub extern "system" fn Java_io_github_huacnlee_AutoCorrect_format(
88
env: JNIEnv,
99
_class: JClass,
@@ -16,7 +16,7 @@ pub extern "system" fn Java_io_github_huacnlee_AutoCorrect_format(
1616
output.into_raw()
1717
}
1818

19-
#[no_mangle]
19+
#[unsafe(no_mangle)]
2020
pub extern "system" fn Java_io_github_huacnlee_AutoCorrect_formatFor(
2121
env: JNIEnv,
2222
_class: JClass,
@@ -31,7 +31,7 @@ pub extern "system" fn Java_io_github_huacnlee_AutoCorrect_formatFor(
3131
output.into_raw()
3232
}
3333

34-
#[no_mangle]
34+
#[unsafe(no_mangle)]
3535
pub extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeLintFor(
3636
env: JNIEnv,
3737
_class: JClass,
@@ -45,15 +45,14 @@ pub extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeLintFor(
4545
Box::into_raw(Box::new(result)) as jlong
4646
}
4747

48-
#[no_mangle]
49-
/// # Safety
48+
#[unsafe(no_mangle)]
5049
pub unsafe extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeLintResultString(
5150
env: JNIEnv,
5251
_class: JClass,
5352
lint_result: jlong,
5453
field: JString,
5554
) -> jstring {
56-
let result = &*(lint_result as *const LintResult);
55+
let result = unsafe { &*(lint_result as *const LintResult) };
5756
let field: String = env.get_string(field).unwrap().into();
5857

5958
let val = match field.as_str() {
@@ -66,14 +65,13 @@ pub unsafe extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeLintResu
6665
output.into_raw()
6766
}
6867

69-
#[no_mangle]
70-
/// # Safety
68+
#[unsafe(no_mangle)]
7169
pub unsafe extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeLintResultLines(
7270
env: JNIEnv,
7371
_class: JClass,
7472
lint_result: jlong,
7573
) -> jintArray {
76-
let result = &*(lint_result as *const LintResult);
74+
let result = unsafe { &*(lint_result as *const LintResult) };
7775

7876
let mut line_ptrs: Vec<jlong> = vec![];
7977
for line in result.lines.clone() {
@@ -86,15 +84,14 @@ pub unsafe extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeLintResu
8684
lines
8785
}
8886

89-
#[no_mangle]
90-
/// # Safety
87+
#[unsafe(no_mangle)]
9188
pub unsafe extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeLineResultString(
9289
env: JNIEnv,
9390
_class: JClass,
9491
line_result: jlong,
9592
field: JString,
9693
) -> jstring {
97-
let result = &*(line_result as *const LineResult);
94+
let result = unsafe { &*(line_result as *const LineResult) };
9895
let field: String = env.get_string(field).unwrap().into();
9996
let val = match field.as_str() {
10097
"new" => result.new.clone(),
@@ -106,15 +103,14 @@ pub unsafe extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeLineResu
106103
output.into_raw()
107104
}
108105

109-
#[no_mangle]
110-
/// # Safety
106+
#[unsafe(no_mangle)]
111107
pub unsafe extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeLineResultLong(
112108
env: JNIEnv,
113109
_class: JClass,
114110
line_result: jlong,
115111
field: JString,
116112
) -> jlong {
117-
let result = &*(line_result as *const LineResult);
113+
let result = unsafe { &*(line_result as *const LineResult) };
118114
let field: String = env.get_string(field).unwrap().into();
119115

120116
let val = match field.as_str() {
@@ -127,22 +123,21 @@ pub unsafe extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeLineResu
127123
val as jlong
128124
}
129125

130-
#[no_mangle]
131-
#[allow(unused)]
126+
#[unsafe(no_mangle)]
132127
pub extern "system" fn Java_io_github_huacnlee_AutoCorrect_loadConfig(
133128
env: JNIEnv,
134129
_class: JClass,
135130
config_str: JString,
136131
) {
137132
let config_str: String = env.get_string(config_str).unwrap().into();
138133

139-
match autocorrect::config::load(&config_str) {
134+
_ = match autocorrect::config::load(&config_str) {
140135
Ok(_config) => Ok(()),
141136
Err(e) => Err(&format!("{e}")),
142137
};
143138
}
144139

145-
#[no_mangle]
140+
#[unsafe(no_mangle)]
146141
pub extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeNewIgnorer(
147142
env: JNIEnv,
148143
_class: JClass,
@@ -155,15 +150,14 @@ pub extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeNewIgnorer(
155150
Box::into_raw(Box::new(ignorer)) as jlong
156151
}
157152

158-
#[no_mangle]
159-
/// # Safety
153+
#[unsafe(no_mangle)]
160154
pub unsafe extern "system" fn Java_io_github_huacnlee_AutoCorrect_nativeIgnorerIsIgnored(
161155
env: JNIEnv,
162156
_class: JClass,
163157
ignorer: jlong,
164158
filepath: JString,
165159
) -> jboolean {
166-
let ignorer = &*(ignorer as *const autocorrect::ignorer::Ignorer);
160+
let ignorer = unsafe { &*(ignorer as *const autocorrect::ignorer::Ignorer) };
167161
let filepath: String = env.get_string(filepath).unwrap().into();
168162

169163
ignorer.is_ignored(&filepath) as jboolean

0 commit comments

Comments
 (0)