8000 Fix: 空の辞書でクラッシュするバグを修正 by sevenc-nanashi · Pull Request #733 · VOICEVOX/voicevox_core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix: 空の辞書でクラッシュするバグを修正 #733

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

Merged
merged 9 commits into from
Feb 6, 2024

Conversation

sevenc-nanashi
Copy link
Member

内容

タイトル通り。

関連 Issue

(なし)

その他

Rustのユーザー辞書テスト、どこに書けば良いんだろうか...
open_jtalk.rs?

return Err(
ErrorRepr::UseUserDict(anyhow!("辞書のコンパイルに失敗しました")).into(),
);
return Err(ErrorRepr::UseUserDict(anyhow!("辞書を読み込めませんでした。")).into());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よくよく考えたらコンパイルの失敗ではないので。(コンパイルに失敗していたらSEGVで落ちるはず)

Copy link
Member
@qryxip qryxip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@qryxip qryxip requested a review from Hiroshiba January 27, 2024 07:32
Comment on lines 136 to 137
let Resources { mecab, .. } = &mut *self.resources.lock().unwrap();
let result = mecab.load_with_userdic(self.dict_dir.as_ref(), None);
Copy link
Member
@Hiroshiba Hiroshiba Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let Resources { mecab, .. } = &mut *self.resources.lock().unwrap();
let result = mecab.load_with_userdic(self.dict_dir.as_ref(), 

が重複しているのがちょっと気になりました。

if 空 {
  空の辞書でload
  return
}
ユーザー辞書作成
ユーザー辞書でload

という処理ですが、

ユーザー辞書 = if(空){
  NULL
} else {
  ユーザー辞書のパス
}
load(ユーザー辞書)

にもできるな〜と。(それはそれでちょっと分かりづらいかもですが)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かにやっていることとしてはそうなので、その方がよいかもしれません。
エラーメッセージも統合できるはず。

Copy link
Member Author
@sevenc-nanashi sevenc-nanashi Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっと試してましたが、下だとユーザー辞書のパスがifを抜けた時点でdropされちゃってコンパイルが落ちるんですよね...
とりあえず共通化は達成できました。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど・・・。こういうときって普通どうするんでしょうか・・・。
所有権を移動できるらしいPathBufとかにする・・・?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ユーザー辞書のパスというよりユーザー辞書のファイルが、ですね(TempFile)
TempFileはdropされる時に消されるので、PathBufにしても多分解決しないと思います(存在しないファイルを指すパスになるはず?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど!!そりゃそうか。んじゃマージします!

Copy link
Member
@qryxip qryxip Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

私ならOption::transposeを使ってOption<NamedTempFile>を得て load_with_userdicにby moveで突っ込み、その中で .as_ref().map(…)ってやりますね。

まあこれでも十分に良いと思います。

@Hiroshiba
Copy link
Member

追加でcommitさせてもらいましたが、 #733 (comment) がRustの便居になりそうなので、マージせず残しています。

@Hiroshiba Hiroshiba merged commit 8f4dcce into VOICEVOX:main Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0