Skip to content

Commit

Permalink
safe! (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
asukaminato0721 authored Oct 21, 2024
1 parent 4c6d126 commit 769c8a2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 44 deletions.
43 changes: 20 additions & 23 deletions src/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ pub(crate) struct Card {
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_New(
_env: JNIEnv,
_class: JClass,
) -> jlong {
pub extern "system" fn Java_com_example_fsrs_Card_New(_env: JNIEnv, _class: JClass) -> jlong {
to_raw(Card {
inner: fsrs::Card::new(),
})
}
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_ScheduledDays(
pub extern "system" fn Java_com_example_fsrs_Card_ScheduledDays(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -27,7 +24,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_ScheduledDays(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_toString<'a>(
pub extern "system" fn Java_com_example_fsrs_Card_toString<'a>(
env: JNIEnv<'a>,
_class: JClass<'a>,
card: jlong,
Expand All @@ -39,7 +36,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_toString<'a>(

// Due DateTime (Getter and Setter)
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_Due(
pub extern "system" fn Java_com_example_fsrs_Card_Due(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -50,7 +47,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_Due(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetDue(
pub extern "system" fn Java_com_example_fsrs_Card_SetDue(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -62,7 +59,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetDue(

// Stability (Getter and Setter)
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_Stability(
pub extern "system" fn Java_com_example_fsrs_Card_Stability(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -72,7 +69,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_Stability(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetStability(
pub extern "system" fn Java_com_example_fsrs_Card_SetStability(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -84,7 +81,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetStability(

// Difficulty (Getter and Setter)
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_Difficulty(
pub extern "system" fn Java_com_example_fsrs_Card_Difficulty(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -94,7 +91,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_Difficulty(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetDifficulty(
pub extern "system" fn Java_com_example_fsrs_Card_SetDifficulty(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -106,7 +103,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetDifficulty(

// Elapsed Days (Getter and Setter)
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_ElapsedDays(
pub extern "system" fn Java_com_example_fsrs_Card_ElapsedDays(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -116,7 +113,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_ElapsedDays(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetElapsedDays(
pub extern "system" fn Java_com_example_fsrs_Card_SetElapsedDays(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -128,7 +125,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetElapsedDays(

// Scheduled Days (Getter and Setter)
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetScheduledDays(
pub extern "system" fn Java_com_example_fsrs_Card_SetScheduledDays(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -140,7 +137,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetScheduledDays(

// Reps (Getter and Setter)
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_Reps(
pub extern "system" fn Java_com_example_fsrs_Card_Reps(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -150,7 +147,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_Reps(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetReps(
pub extern "system" fn Java_com_example_fsrs_Card_SetReps(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -162,7 +159,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetReps(

// Lapses (Getter and Setter)
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_Lapses(
pub extern "system" fn Java_com_example_fsrs_Card_Lapses(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -172,7 +169,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_Lapses(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetLapses(
pub extern "system" fn Java_com_example_fsrs_Card_SetLapses(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -184,7 +181,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetLapses(

// State (Getter and Setter)
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_State(
pub extern "system" fn Java_com_example_fsrs_Card_State(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -194,7 +191,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_State(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetState(
pub extern "system" fn Java_com_example_fsrs_Card_SetState(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -212,7 +209,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetState(

// Last Review (Getter and Setter)
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_LastReview(
pub extern "system" fn Java_com_example_fsrs_Card_LastReview(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand All @@ -223,7 +220,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_Card_LastReview(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Card_SetLastReview(
pub extern "system" fn Java_com_example_fsrs_Card_SetLastReview(
_env: JNIEnv,
_class: JClass,
card: jlong,
Expand Down
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ struct FSRS {
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_FSRS_Default(
_env: JNIEnv,
_class: JClass,
) -> jlong {
pub extern "system" fn Java_com_example_fsrs_FSRS_Default(_env: JNIEnv, _class: JClass) -> jlong {
to_raw(FSRS {
inner: fsrs::FSRS::default(),
})
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_FSRS_New(
pub extern "system" fn Java_com_example_fsrs_FSRS_New(
_env: JNIEnv,
_class: JClass,
parameter: jlong,
Expand All @@ -50,7 +47,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_FSRS_New(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_FSRS_Repeat(
pub extern "system" fn Java_com_example_fsrs_FSRS_Repeat(
__env: JNIEnv,
_class: JClass,
fsrs_: jlong,
Expand Down
2 changes: 1 addition & 1 deletion src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) struct Parameter {
pub(crate) inner: fsrs::Parameters,
}
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_Parameter_New(
pub extern "system" fn Java_com_example_fsrs_Parameter_New(
env: JNIEnv,
_class: JClass,
maximum_interval: jint,
Expand Down
2 changes: 1 addition & 1 deletion src/record_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) struct RecordLog {
pub(crate) inner: fsrs::RecordLog,
}
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_RecordLog_SchedulingInfo(
pub extern "system" fn Java_com_example_fsrs_RecordLog_SchedulingInfo(
_env: JNIEnv,
_class: JClass,
record_log: jlong,
Expand Down
22 changes: 11 additions & 11 deletions src/review_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct ReviewLog {
pub inner: fsrs::ReviewLog,
}
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_toString<'a>(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_toString<'a>(
env: JNIEnv<'a>,
_class: JClass<'a>,
card: jlong,
Expand All @@ -18,7 +18,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_toString<'a>(
.expect("string error")
}
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_Rating(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_Rating(
_env: JNIEnv,
_class: JClass,
review_log: jlong,
Expand All @@ -28,7 +28,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_Rating(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_ElapsedDays(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_ElapsedDays(
_env: JNIEnv,
_class: JClass,
review_log: jlong,
Expand All @@ -38,7 +38,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_ElapsedDays(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_ScheduledDays(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_ScheduledDays(
_env: JNIEnv,
_class: JClass,
review_log: jlong,
Expand All @@ -48,7 +48,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_ScheduledDays(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_State(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_State(
_env: JNIEnv,
_class: JClass,
review_log: jlong,
Expand All @@ -58,7 +58,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_State(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_ReviewedDate(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_ReviewedDate(
_env: JNIEnv,
_class: JClass,
review_log: jlong,
Expand All @@ -69,7 +69,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_ReviewedDate(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_SetReviewedDate(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_SetReviewedDate(
_env: JNIEnv,
_class: JClass,
review_log: jlong,
Expand All @@ -80,7 +80,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_SetReviewedDate(
chrono::DateTime::from_timestamp(reviewed_date_timestamp as i64, 0).expect("time error");
}
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_SetState(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_SetState(
_env: JNIEnv,
_class: JClass,
review_log: jlong,
Expand All @@ -96,7 +96,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_SetState(
};
}
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_SetScheduledDays(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_SetScheduledDays(
_env: JNIEnv,
_class: JClass,
review_log: jlong,
Expand All @@ -106,7 +106,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_SetScheduledDays(
rl.inner.scheduled_days = scheduled_days as i64;
}
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_SetElapsedDays(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_SetElapsedDays(
_env: JNIEnv,
_class: JClass,
review_log: jlong,
Expand All @@ -116,7 +116,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_SetElapsedDays(
rl.inner.elapsed_days = elapsed_days as i64;
}
#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_ReviewLog_SetRating(
pub extern "system" fn Java_com_example_fsrs_ReviewLog_SetRating(
_env: JNIEnv,
_class: JClass,
review_log: jlong,
Expand Down
4 changes: 2 additions & 2 deletions src/scheduling_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) struct SchedulingInfo {
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_SchedulingInfo_Card(
pub extern "system" fn Java_com_example_fsrs_SchedulingInfo_Card(
_env: JNIEnv,
_class: JClass,
scheduling_info: jlong,
Expand All @@ -19,7 +19,7 @@ pub unsafe extern "system" fn Java_com_example_fsrs_SchedulingInfo_Card(
}

#[no_mangle]
pub unsafe extern "system" fn Java_com_example_fsrs_SchedulingInfo_ReviewLog(
pub extern "system" fn Java_com_example_fsrs_SchedulingInfo_ReviewLog(
_env: JNIEnv,
_class: JClass,
scheduling_info: jlong,
Expand Down

0 comments on commit 769c8a2

Please sign in to comment.