Skip to content

Commit

Permalink
chore: Rustを1.82.0に上げ、その新機能を利用する
Browse files Browse the repository at this point in the history
Rustを1.82.0に上げてClippyの対応を行うとともに、次の新機能を利用する。

- `unsafe_attributes` (rust-lang/rust#128771)
- `raw_ref_op` (rust-lang/rust#127679)
  • Loading branch information
qryxip committed Oct 19, 2024
1 parent 683da55 commit bc632ae
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 65 deletions.
8 changes: 6 additions & 2 deletions crates/voicevox_core/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,15 @@ mod tests {
reason = "比較対象としてここは網羅されてなければなりません"
)]
let SupportedDevices { cpu: _, cuda, dml } = &SUPPORTED_DEVICES;
[cuda as *const _, dml as *const _]
#[expect(
clippy::borrow_deref_ref,
reason = "多分raw記法自体にまだ対応していない"
)]
[&raw const *cuda, &raw const *dml]
},
*GpuSpec::defaults()
.into_iter()
.map(|gpu| &SUPPORTED_DEVICES[gpu] as *const _)
.map(|gpu| &raw const SUPPORTED_DEVICES[gpu])
.collect::<Vec<_>>(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/infer/runtimes/onnxruntime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub(crate) mod blocking {
/// assert_eq!(ptr_addr(ort1), ptr_addr(ort2));
///
/// fn ptr_addr(obj: &impl Sized) -> usize {
/// obj as *const _ as _
/// &raw const *obj as _
/// }
/// # Ok(())
/// # }
Expand Down
30 changes: 20 additions & 10 deletions crates/voicevox_core_c_api/src/compatible_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ fn set_message(message: &str) {
.replace_range(.., &format!("{message}\0"));
}

#[no_mangle]
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
#[unsafe(no_mangle)]
pub extern "C" fn initialize(use_gpu: bool, cpu_num_threads: c_int, load_all_models: bool) -> bool {
init_logger_once();
let result = (|| {
Expand Down Expand Up @@ -150,7 +151,8 @@ pub extern "C" fn initialize(use_gpu: bool, cpu_num_threads: c_int, load_all_mod
}
}

#[no_mangle]
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
#[unsafe(no_mangle)]
pub extern "C" fn load_model(style_id: i64) -> bool {
init_logger_once();
let style_id = StyleId::new(style_id as u32);
Expand All @@ -171,33 +173,38 @@ pub extern "C" fn load_model(style_id: i64) -> bool {
}
}

#[no_mangle]
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
#[unsafe(no_mangle)]
pub extern "C" fn is_model_loaded(speaker_id: i64) -> bool {
init_logger_once();
ensure_initialized!(&*lock_synthesizer())
.is_loaded_model_by_style_id(StyleId::new(speaker_id as u32))
}

#[no_mangle]
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
#[unsafe(no_mangle)]
pub extern "C" fn finalize() {
init_logger_once();
*lock_synthesizer() = None;
}

#[no_mangle]
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
#[unsafe(no_mangle)]
pub extern "C" fn metas() -> *const c_char {
init_logger_once();
let model_set = voice_model_set();
model_set.all_metas_json.as_ptr()
}

#[no_mangle]
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
#[unsafe(no_mangle)]
pub extern "C" fn last_error_message() -> *const c_char {
init_logger_once();
ERROR_MESSAGE.lock().unwrap().as_ptr() as *const c_char
}

#[no_mangle]
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
#[unsafe(no_mangle)]
pub extern "C" fn supported_devices() -> *const c_char {
init_logger_once();
return SUPPORTED_DEVICES.as_ptr();
Expand All @@ -214,7 +221,8 @@ pub extern "C" fn supported_devices() -> *const c_char {
});
}

#[no_mangle]
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
#[unsafe(no_mangle)]
pub extern "C" fn yukarin_s_forward(
length: i64,
phoneme_list: *mut i64,
Expand All @@ -240,7 +248,8 @@ pub extern "C" fn yukarin_s_forward(
}
}

#[no_mangle]
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
#[unsafe(no_mangle)]
pub extern "C" fn yukarin_sa_forward(
length: i64,
vowel_phoneme_list: *mut i64,
Expand Down Expand Up @@ -277,7 +286,8 @@ pub extern "C" fn yukarin_sa_forward(
}
}

#[no_mangle]
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
#[unsafe(no_mangle)]
pub extern "C" fn decode_forward(
length: i64,
phoneme_size: i64,
Expand Down
Loading

0 comments on commit bc632ae

Please sign in to comment.