-
Notifications
You must be signed in to change notification settings - Fork 121
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
[project-vvm-async-api] extern "C"
の生ポインタをABI互換のに置き換え
#514
Merged
Hiroshiba
merged 4 commits into
VOICEVOX:project-vvm-async-api
from
qryxip:project-vvm-async-api-use-same-layout-types
Jun 9, 2023
Merged
[project-vvm-async-api] extern "C"
の生ポインタをABI互換のに置き換え
#514
Hiroshiba
merged 4 commits into
VOICEVOX:project-vvm-async-api
from
qryxip:project-vvm-async-api-use-same-layout-types
Jun 9, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qryxip
changed the title
[project-vvm-async-api] C APIの宣言で互換レイアウトの型を使う
[project-vvm-async-api] C APIの宣言でABI互換の型を使う
Jun 8, 2023
qryxip
changed the title
[project-vvm-async-api] C APIの宣言でABI互換の型を使う
[project-vvm-async-api] Jun 9, 2023
extern "C" fn
の生ポインタをABI互換の型に置き換える
qryxip
changed the title
[project-vvm-async-api]
[project-vvm-async-api] Jun 9, 2023
extern "C" fn
の生ポインタをABI互換の型に置き換えるextern "C"
の生ポインタをABI互換のに置き換え
あ、このPRの利点ですが一応:
を目的としています。 |
|
↑ なしで。ユーザーに貸し出すべき配列が空だったらとか考えると利点の割に面倒になります。 |
なんか |
Hiroshiba
reviewed
Jun 9, 2023
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!!
引数の型でMaybeUninit
使うの面白いですね。
本当にやりたいのはwrite onlyな気がしますが。(そういうの無さそう)
問題ないと思うのでマージします!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 に続く形で実装しています。