Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[project-vvm-async-api] get_supported_devices_jsonをfallibleに #502

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions crates/voicevox_core_c_api/include/voicevox_core.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion crates/voicevox_core_c_api/src/compatible_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,17 @@ pub extern "C" fn last_error_message() -> *const c_char {

#[no_mangle]
pub extern "C" fn supported_devices() -> *const c_char {
voicevox_get_supported_devices_json()
return SUPPORTED_DEVICES.as_ptr();

static SUPPORTED_DEVICES: Lazy<CString> = Lazy::new(|| {
CString::new(
SupportedDevices::get_supported_devices()
.unwrap()
.to_json()
.to_string(),
)
.unwrap()
});
}

#[no_mangle]
Expand Down
29 changes: 18 additions & 11 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,26 @@ pub unsafe extern "C" fn voicevox_synthesizer_get_metas_json(
synthesizer.metas().as_ptr()
}

static VOICEVOX_SUPPORTED_DEVICES_JSON: once_cell::sync::Lazy<CString> =
once_cell::sync::Lazy::new(|| {
CString::new(
serde_json::to_string(&SupportedDevices::get_supported_devices().unwrap()).unwrap(),
)
.unwrap()
});

/// サポートデバイス情報をjsonで取得する
/// @return サポートデバイス情報のjson文字列
/// @param [out] output_supported_devices_json サポートデバイス情報のjson文字列
/// @return 結果コード #VoicevoxResultCode
///
/// # Safety
/// @param output_supported_devices_json 自動でheapメモリが割り当てられるので ::voicevox_json_free で解放する必要がある
#[no_mangle]
pub extern "C" fn voicevox_get_supported_devices_json() -> *const c_char {
VOICEVOX_SUPPORTED_DEVICES_JSON.as_ptr()
pub unsafe extern "C" fn voicevox_get_supported_devices_json(
qryxip marked this conversation as resolved.
Show resolved Hide resolved
output_supported_devices_json: *mut *mut c_char,
) -> VoicevoxResultCode {
into_result_code_with_error((|| {
let supported_devices = CString::new(
SupportedDevices::get_supported_devices()?
.to_json()
.to_string(),
)
.unwrap();
output_supported_devices_json.write(supported_devices.into_raw());
Ok(())
})())
}

/// Audio query のオプション
Expand Down