[project-vvm-async-api] extern "C"
の生ポインタをABI互換のに置き換え
#514
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
内容
extern "C" fn
の宣言において、引数の型を次のように置き換えます。これによるC ABI上のシグネチャは変化しないはずであるので、.hは変化しません。&T
として読む*const T
→&T
&mut T
として読む*mut T
→&mut T
*mut T
→&mut MaybeUninit<T>
Box<T>
として扱う*mut T
→Box<T>
各公式ドキュメントを読めばこの置き換えをしていいことがわかりますし、cbindgenもそのように判断しています。
また1., 2., 3.についてはOSSでの実例もいくつも見つけることができます。4.だけ実例をあまり見つけることができないのですが、これは
Box<impl Sized>
のレイアウトが正式に保証されたのが Rust 1.41 (2020年)と比較的最近だからだと思われます(ただこのリンク先のコード例をもって正当性の根拠とすることができると思います)。関連 Issue
#497
その他
mainブランチの方に向けようか迷ったのですが、
Synthesizer
とかへの適用が主になると思ったので、project-vvm-async-apiに向けることにしました。このPRは現在 #512 に続く形で実装しています。