We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
C APIに次の関数を追加します。
void voicevox_set_rust_panic_translator(void (*translator)(const *VoicevoxRustPanicInfo));
この関数はRustのパニックの情報であるVoicevoxRustPanicInfoから、C++の例外などに変換するコールバックを登録します。そしてVOICEVOX COREの実装から万が一Rustのパニックが出た場合にそのパニック自体ではなく、変換されたC++の例外(など)が発されるようになります。
VoicevoxRustPanicInfo
C APIのextern "C"をextern "C-unwind"にした(#541)後、
extern "C"
extern "C-unwind"
panic=unwindにする。
panic=unwind
voicevox_set_rust_panic_translatorを実装。
voicevox_set_rust_panic_translator
Rustのパニックが発生しうる場所をstd::panic::catch_unwindで包み、"catch"したパニックを上記のvoid (*translator)(const *VoicevoxRustPanicInfo)に入れる。
std::panic::catch_unwind
void (*translator)(const *VoicevoxRustPanicInfo)
多分これを加工して使うことになる。
voicevox_core/crates/voicevox_core_c_api/src/helpers.rs
Line 10 in f2b66ec
translatorがunwindしなかった場合、std::process::abort。
translator
std::process::abort
N/A
The text was updated successfully, but these errors were encountered:
issue作成ありがとうございます!!
なるほどです、確かに例外を置き換えられるとより強固なライブラリになる気がしました。 ただどういう実装にすれば良いのかが全く検討つかないというのがちょっと正直なところです。
このあたりって何か前例あったりするのでしょうか? というのも、例えばC++以外の言語に例外を投げたい場合にどうなっていると嬉しいのかとか、先見の明を持っているかもしれないので参考になりそうだなと思った次第です。
Sorry, something went wrong.
DとかGoとかだとあるかもしれません。まだそのあたりまでは調べていません。
それ以前に、現在のRustだと #556 と両立できないことに気付いてしまいました。RustのパニックとC++の例外、両方の発生を同時に許容することはできません。
The behavior of catch_unwind when a foreign exception encounters it is currently left undefined.
catch_unwind
This constraint is partially met: the behavior of foreign exceptions with respect to catch_unwind is currently undefined, and left for future work.
このissueの機能と #556 、どちらが有用かというと #556 かと思います。まあパニックは回復不可能なエラーという位置付けなので、現状のプロセス強制終了の挙動でもよさそうな気がします。
で、このissueをどうするかですが、上記の"future work"がするっと成し遂げられて半年後とか3ヶ月後には利用可能になっている、ということも十分考えられるんですよね... なので存続はさせたいと思っています。
なるほどです!
両立できない
ちょっとちゃんとわかってないんですが、コード上両立はできるけれども、例外の発生のことを考えると危ないっていう感じですよね。 個人的にはまあその状態でも両方とも実装しちゃって、その中で例外が発生しちゃうとどうなるか分かりませんよ(=やめてください)という案内にするというのも全然ありかなとか思いました!
No branches or pull requests
内容
C APIに次の関数を追加します。
この関数はRustのパニックの情報である
VoicevoxRustPanicInfo
から、C++の例外などに変換するコールバックを登録します。そしてVOICEVOX COREの実装から万が一Rustのパニックが出た場合にそのパニック自体ではなく、変換されたC++の例外(など)が発されるようになります。Pros 良くなる点
Cons 悪くなる点
実現方法
C APIの
extern "C"
をextern "C-unwind"
にした(#541)後、panic=unwind
にする。voicevox_set_rust_panic_translator
を実装。Rustのパニックが発生しうる場所を
std::panic::catch_unwind
で包み、"catch"したパニックを上記のvoid (*translator)(const *VoicevoxRustPanicInfo)
に入れる。多分これを加工して使うことになる。
voicevox_core/crates/voicevox_core_c_api/src/helpers.rs
Line 10 in f2b66ec
translator
がunwindしなかった場合、std::process::abort
。VOICEVOXのバージョン
N/A
OSの種類/ディストリ/バージョン
その他
The text was updated successfully, but these errors were encountered: