Skip to content

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

Merged
Hiroshiba merged 9 commits into
VOICEVOX:mainfrom
sevenc-nanashi:fix/crash-on-empty-dict
Feb 6, 2024
Merged

Hiroshiba merged 9 commits into
VOICEVOX:mainfrom
sevenc-nanashi:fix/crash-on-empty-dict

Conversation

@sevenc-nanashi

Copy link
Copy Markdown
Member

内容

タイトル通り。

関連 Issue

(なし)

その他

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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

@qryxip qryxip left a comment

Copy link
Copy Markdown
Member

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);

@Hiroshiba Hiroshiba Feb 5, 2024 •

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@sevenc-nanashi sevenc-nanashi Feb 6, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@qryxip qryxip Feb 6, 2024 •

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

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

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