-
Notifications
You must be signed in to change notification settings - Fork 125
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
Fix: 空の辞書でクラッシュするバグを修正 #733
Conversation
return Err( | ||
ErrorRepr::UseUserDict(anyhow!("辞書のコンパイルに失敗しました")).into(), | ||
); | ||
return Err(ErrorRepr::UseUserDict(anyhow!("辞書を読み込めませんでした。")).into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
よくよく考えたらコンパイルの失敗ではないので。(コンパイルに失敗していたらSEGVで落ちるはず)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
let Resources { mecab, .. } = &mut *self.resources.lock().unwrap(); | ||
let result = mecab.load_with_userdic(self.dict_dir.as_ref(), None); |
There was a problem hiding this comment.
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(ユーザー辞書)
にもできるな〜と。(それはそれでちょっと分かりづらいかもですが)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確かにやっていることとしてはそうなので、その方がよいかもしれません。
エラーメッセージも統合できるはず。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ちょっと試してましたが、下だとユーザー辞書のパスがifを抜けた時点でdropされちゃってコンパイルが落ちるんですよね...
とりあえず共通化は達成できました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど・・・。こういうときって普通どうするんでしょうか・・・。
所有権を移動できるらしいPathBuf
とかにする・・・?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ユーザー辞書のパスというよりユーザー辞書のファイルが、ですね(TempFile)
TempFileはdropされる時に消されるので、PathBufにしても多分解決しないと思います(存在しないファイルを指すパスになるはず?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど!!そりゃそうか。んじゃマージします!
There was a problem hiding this comment.
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(…)
ってやりますね。
まあこれでも十分に良いと思います。
追加でcommitさせてもらいましたが、 #733 (comment) がRustの便居になりそうなので、マージせず残しています。 |
内容
タイトル通り。
関連 Issue
(なし)
その他
Rustのユーザー辞書テスト、どこに書けば良いんだろうか...
open_jtalk.rs?