Skip to content

Commit 683da55

Browse files
authored
refactor: cstr!("…")c"…"に置き換える (VOICEVOX#782)
Refs: VOICEVOX#771
1 parent b82f7dc commit 683da55

File tree

7 files changed

+40
-68
lines changed

7 files changed

+40
-68
lines changed

Cargo.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ color-eyre = "0.6.3"
2424
colorchoice = "1.0.2"
2525
comrak = "0.26.0"
2626
const_format = "0.2.33"
27-
cstr = "0.2.12" # https://github.com/dtolnay/syn/issues/1502
2827
derive-getters = "0.2.0"
2928
derive-new = "0.5.9"
3029
derive-syn-parse = "0.2.0"

crates/voicevox_core_c_api/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ camino.workspace = true
2424
chrono = { workspace = true, default-features = false, features = ["clock"] }
2525
colorchoice.workspace = true
2626
const_format.workspace = true
27-
cstr.workspace = true
2827
duplicate.workspace = true
2928
easy-ext.workspace = true
3029
educe.workspace = true

crates/voicevox_core_c_api/src/drop_check.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ impl CStringDropChecker {
107107
mod tests {
108108
use std::ffi::{c_char, CStr};
109109

110-
use cstr::cstr;
111-
112110
use super::CStringDropChecker;
113111

114112
#[test]
@@ -118,7 +116,7 @@ mod tests {
118116
)]
119117
fn it_denies_duplicated_char_ptr() {
120118
let checker = CStringDropChecker::new();
121-
let s = cstr!("").to_owned();
119+
let s = c"".to_owned();
122120
checker.whitelist(checker.whitelist(s));
123121
}
124122

crates/voicevox_core_c_api/src/result_code.rs

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::ffi::CStr;
22

3-
use cstr::cstr;
4-
53
/// 処理結果を示す結果コード。
64
#[repr(i32)]
75
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
@@ -65,56 +63,48 @@ pub enum VoicevoxResultCode {
6563
pub(crate) const fn error_result_to_message(result_code: VoicevoxResultCode) -> &'static CStr {
6664
use VoicevoxResultCode::*;
6765
match result_code {
68-
VOICEVOX_RESULT_NOT_LOADED_OPENJTALK_DICT_ERROR => {
69-
cstr!("OpenJTalkの辞書が読み込まれていません")
70-
}
71-
VOICEVOX_RESULT_GPU_SUPPORT_ERROR => cstr!("GPU機能をサポートすることができません"),
66+
VOICEVOX_RESULT_NOT_LOADED_OPENJTALK_DICT_ERROR => c"OpenJTalkの辞書が読み込まれていません",
67+
VOICEVOX_RESULT_GPU_SUPPORT_ERROR => c"GPU機能をサポートすることができません",
7268
VOICEVOX_RESULT_GET_SUPPORTED_DEVICES_ERROR => {
73-
cstr!("サポートされているデバイス情報取得中にエラーが発生しました")
69+
c"サポートされているデバイス情報取得中にエラーが発生しました"
7470
}
7571
VOICEVOX_RESULT_INIT_INFERENCE_RUNTIME_ERROR => {
76-
cstr!("推論ライブラリのロードまたは初期化ができませんでした")
72+
c"推論ライブラリのロードまたは初期化ができませんでした"
7773
}
78-
VOICEVOX_RESULT_OK => cstr!("エラーが発生しませんでした"),
79-
VOICEVOX_RESULT_STYLE_NOT_FOUND_ERROR => cstr!(
80-
"指定されたIDに対するスタイルが見つかりませんでした。音声モデルが読み込まれていないか\
81-
、読み込みが解除されています"
82-
),
83-
VOICEVOX_RESULT_MODEL_NOT_FOUND_ERROR => cstr!(
84-
"指定されたIDに対する音声モデルが見つかりませんでした。読み込まれていないか、読み込み\
85-
が既に解除されています"
86-
),
87-
VOICEVOX_RESULT_RUN_MODEL_ERROR => cstr!("推論に失敗しました"),
88-
VOICEVOX_RESULT_EXTRACT_FULL_CONTEXT_LABEL_ERROR => {
89-
cstr!("入力テキストからのフルコンテキストラベル抽出に失敗しました")
74+
VOICEVOX_RESULT_OK => c"エラーが発生しませんでした",
75+
VOICEVOX_RESULT_STYLE_NOT_FOUND_ERROR => {
76+
c"指定されたIDに対するスタイルが見つかりませんでした。音声モデルが読み込まれていない\
77+
か、読み込みが解除されています"
9078
}
91-
VOICEVOX_RESULT_INVALID_UTF8_INPUT_ERROR => cstr!("入力テキストが無効なUTF-8データでした"),
92-
VOICEVOX_RESULT_PARSE_KANA_ERROR => {
93-
cstr!("入力テキストをAquesTalk風記法としてパースすることに失敗しました")
79+
VOICEVOX_RESULT_MODEL_NOT_FOUND_ERROR => {
80+
c"指定されたIDに対する音声モデルが見つかりませんでした。読み込まれていないか、読み込み\
81+
が既に解除されています"
9482
}
95-
VOICEVOX_RESULT_INVALID_AUDIO_QUERY_ERROR => cstr!("無効なaudio_queryです"),
96-
VOICEVOX_RESULT_INVALID_ACCENT_PHRASE_ERROR => cstr!("無効なaccent_phraseです"),
97-
VOICEVOX_RESULT_OPEN_ZIP_FILE_ERROR => cstr!("ZIPファイルのオープンに失敗しました"),
98-
VOICEVOX_RESULT_READ_ZIP_ENTRY_ERROR => {
99-
cstr!("ZIP内のファイルを読むことができませんでした")
100-
}
101-
VOICEVOX_RESULT_INVALID_MODEL_HEADER_ERROR => cstr!("モデルの形式が不正です"),
102-
VOICEVOX_RESULT_MODEL_ALREADY_LOADED_ERROR => cstr!("同じIDのモデルを読むことはできません"),
103-
VOICEVOX_RESULT_STYLE_ALREADY_LOADED_ERROR => {
104-
cstr!("同じIDのスタイルを読むことはできません")
83+
VOICEVOX_RESULT_RUN_MODEL_ERROR => c"推論に失敗しました",
84+
VOICEVOX_RESULT_EXTRACT_FULL_CONTEXT_LABEL_ERROR => {
85+
c"入力テキストからのフルコンテキストラベル抽出に失敗しました"
10586
}
106-
VOICEVOX_RESULT_INVALID_MODEL_DATA_ERROR => {
107-
cstr!("モデルデータを読むことができませんでした")
87+
VOICEVOX_RESULT_INVALID_UTF8_INPUT_ERROR => c"入力テキストが無効なUTF-8データでした",
88+
VOICEVOX_RESULT_PARSE_KANA_ERROR => {
89+
c"入力テキストをAquesTalk風記法としてパースすることに失敗しました"
10890
}
109-
VOICEVOX_RESULT_LOAD_USER_DICT_ERROR => cstr!("ユーザー辞書を読み込めませんでした"),
110-
VOICEVOX_RESULT_SAVE_USER_DICT_ERROR => cstr!("ユーザー辞書を書き込めませんでした"),
91+
VOICEVOX_RESULT_INVALID_AUDIO_QUERY_ERROR => c"無効なaudio_queryです",
92+
VOICEVOX_RESULT_INVALID_ACCENT_PHRASE_ERROR => c"無効なaccent_phraseです",
93+
VOICEVOX_RESULT_OPEN_ZIP_FILE_ERROR => c"ZIPファイルのオープンに失敗しました",
94+
VOICEVOX_RESULT_READ_ZIP_ENTRY_ERROR => c"ZIP内のファイルを読むことができませんでした",
95+
VOICEVOX_RESULT_INVALID_MODEL_HEADER_ERROR => c"モデルの形式が不正です",
96+
VOICEVOX_RESULT_MODEL_ALREADY_LOADED_ERROR => c"同じIDのモデルを読むことはできません",
97+
VOICEVOX_RESULT_STYLE_ALREADY_LOADED_ERROR => c"同じIDのスタイルを読むことはできません",
98+
VOICEVOX_RESULT_INVALID_MODEL_DATA_ERROR => c"モデルデータを読むことができませんでした",
99+
VOICEVOX_RESULT_LOAD_USER_DICT_ERROR => c"ユーザー辞書を読み込めませんでした",
100+
VOICEVOX_RESULT_SAVE_USER_DICT_ERROR => c"ユーザー辞書を書き込めませんでした",
111101
VOICEVOX_RESULT_USER_DICT_WORD_NOT_FOUND_ERROR => {
112-
cstr!("ユーザー辞書に単語が見つかりませんでした")
102+
c"ユーザー辞書に単語が見つかりませんでした"
113103
}
114-
VOICEVOX_RESULT_USE_USER_DICT_ERROR => cstr!("OpenJTalkのユーザー辞書の設定に失敗しました"),
104+
VOICEVOX_RESULT_USE_USER_DICT_ERROR => c"OpenJTalkのユーザー辞書の設定に失敗しました",
115105
VOICEVOX_RESULT_INVALID_USER_DICT_WORD_ERROR => {
116-
cstr!("ユーザー辞書の単語のバリデーションに失敗しました")
106+
c"ユーザー辞書の単語のバリデーションに失敗しました"
117107
}
118-
VOICEVOX_RESULT_INVALID_UUID_ERROR => cstr!("UUIDの変換に失敗しました"),
108+
VOICEVOX_RESULT_INVALID_UUID_ERROR => c"UUIDの変換に失敗しました",
119109
}
120110
}

crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_load.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::mem::MaybeUninit;
66
use std::sync::LazyLock;
77

88
use assert_cmd::assert::AssertResult;
9-
use cstr::cstr;
109
use libloading::Library;
1110
use serde::{Deserialize, Serialize};
1211
use test_util::c_api::{self, CApi, VoicevoxInitializeOptions, VoicevoxResultCode};
@@ -33,8 +32,8 @@ impl assert_cdylib::TestCase for TestCase {
3332

3433
let word = {
3534
let mut word = lib.voicevox_user_dict_word_make(
36-
cstr!("this_word_should_not_exist_in_default_dictionary").as_ptr(),
37-
cstr!("アイウエオ").as_ptr(),
35+
c"this_word_should_not_exist_in_default_dictionary".as_ptr(),
36+
c"アイウエオ".as_ptr(),
3837
);
3938
word.word_type =
4039
c_api::VoicevoxUserDictWordType_VOICEVOX_USER_DICT_WORD_TYPE_PROPER_NOUN;
@@ -92,7 +91,7 @@ impl assert_cdylib::TestCase for TestCase {
9291
let mut audio_query_without_dict = std::ptr::null_mut();
9392
assert_ok(lib.voicevox_synthesizer_create_audio_query(
9493
synthesizer,
95-
cstr!("this_word_should_not_exist_in_default_dictionary").as_ptr(),
94+
c"this_word_should_not_exist_in_default_dictionary".as_ptr(),
9695
STYLE_ID,
9796
&mut audio_query_without_dict,
9897
));
@@ -105,7 +104,7 @@ impl assert_cdylib::TestCase for TestCase {
105104
let mut audio_query_with_dict = std::ptr::null_mut();
106105
assert_ok(lib.voicevox_synthesizer_create_audio_query(
107106
synthesizer,
108-
cstr!("this_word_should_not_exist_in_default_dictionary").as_ptr(),
107+
c"this_word_should_not_exist_in_default_dictionary".as_ptr(),
109108
STYLE_ID,
110109
&mut audio_query_with_dict,
111110
));

crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_manipulate.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use assert_cmd::assert::AssertResult;
1010
use tempfile::NamedTempFile;
1111
use uuid::Uuid;
1212

13-
use cstr::cstr;
1413
use libloading::Library;
1514
use serde::{Deserialize, Serialize};
1615
use test_util::c_api::{self, CApi, VoicevoxResultCode, VoicevoxUserDict, VoicevoxUserDictWord};
@@ -58,7 +57,7 @@ impl assert_cdylib::TestCase for TestCase {
5857
let dict = lib.voicevox_user_dict_new();
5958

6059
// 単語の追加のテスト
61-
let word = lib.voicevox_user_dict_word_make(cstr!("hoge").as_ptr(), cstr!("ホゲ").as_ptr());
60+
let word = lib.voicevox_user_dict_word_make(c"hoge".as_ptr(), c"ホゲ".as_ptr());
6261

6362
let word_uuid = add_word(dict, &word);
6463

@@ -69,7 +68,7 @@ impl assert_cdylib::TestCase for TestCase {
6968
assert_contains_uuid(&json, &word_uuid);
7069

7170
// 単語の変更のテスト
72-
let word = lib.voicevox_user_dict_word_make(cstr!("fuga").as_ptr(), cstr!("フガ").as_ptr());
71+
let word = lib.voicevox_user_dict_word_make(c"fuga".as_ptr(), c"フガ".as_ptr());
7372

7473
assert_ok(lib.voicevox_user_dict_update_word(dict, &word_uuid.into_bytes(), &word));
7574

@@ -84,8 +83,7 @@ impl assert_cdylib::TestCase for TestCase {
8483
// 辞書のインポートのテスト。
8584
let other_dict = lib.voicevox_user_dict_new();
8685

87-
let other_word =
88-
lib.voicevox_user_dict_word_make(cstr!("piyo").as_ptr(), cstr!("ピヨ").as_ptr());
86+
let other_word = lib.voicevox_user_dict_word_make(c"piyo".as_ptr(), c"ピヨ".as_ptr());
8987

9088
let other_word_uuid = add_word(other_dict, &other_word);
9189

@@ -110,7 +108,7 @@ impl assert_cdylib::TestCase for TestCase {
110108
// 辞書のセーブ・ロードのテスト
111109
let temp_path = NamedTempFile::new().unwrap().into_temp_path();
112110
let temp_path = CString::new(temp_path.to_str().unwrap()).unwrap();
113-
let word = lib.voicevox_user_dict_word_make(cstr!("hoge").as_ptr(), cstr!("ホゲ").as_ptr());
111+
let word = lib.voicevox_user_dict_word_make(c"hoge".as_ptr(), c"ホゲ".as_ptr());
114112
let word_uuid = add_word(dict, &word);
115113

116114
assert_ok(lib.voicevox_user_dict_save(dict, temp_path.as_ptr()));

0 commit comments

Comments
 (0)