[DRAFT] GDExtension: Check conversions to/from GDExtension pointer types#112125
Draft
dsnopek wants to merge 1 commit into
Draft
[DRAFT] GDExtension: Check conversions to/from GDExtension pointer types#112125dsnopek wants to merge 1 commit into
dsnopek wants to merge 1 commit into
Conversation
7786eb4 to
7c3d7f2
Compare
7c3d7f2 to
cb1c900
Compare
This file contains hidden or 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
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.
This PR builds on top of #107845
It generates the GDExtension interface header differently than the "legacy" version, swapping
void *for opaque structs, in an attempt to allow the compiler to validate conversions between Godot types and the types used by the GDExtension interfaceSo, rather than using C-style casts or
reinterpret_cast()s at each conversion, we would use the newto_gdextension()andfrom_gdextension()functions, which should only be able to perform valid conversions.While we haven't had a bug from invalid conversions recently, we have had numerous such bugs in the past, and this should make that impossible at compile time. It would also make life somewhat easier for contributors, because it should eliminate the question of which cast to use, or which GDExtension type is correct. Since they are all
void *in the legacy header and we're using casts that do no checking, it's really easy to use the wrong one, and we rely on imperfect human review to check it.In fact, in this PR, you can see a handful of cases where this change turned up the wrong GDExtension type being used!
NOTE: This PR is unfinished which is why it's marked as DRAFT. However, I wanted to share it, in order to show an important thing that PR #107845 would allow us to do