Skip to content

[DRAFT] GDExtension: Check conversions to/from GDExtension pointer types#112125

Draft
dsnopek wants to merge 1 commit into
godotengine:masterfrom
dsnopek:gdextension-interface-json-struct-handles
Draft

[DRAFT] GDExtension: Check conversions to/from GDExtension pointer types#112125
dsnopek wants to merge 1 commit into
godotengine:masterfrom
dsnopek:gdextension-interface-json-struct-handles

Conversation

@dsnopek
Copy link
Copy Markdown
Contributor

@dsnopek dsnopek commented Oct 28, 2025

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 interface

So, rather than using C-style casts or reinterpret_cast()s at each conversion, we would use the new to_gdextension() and from_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

@dsnopek dsnopek added this to the 4.x milestone Oct 28, 2025
@dsnopek dsnopek requested a review from a team as a code owner October 28, 2025 15:47
@dsnopek dsnopek requested review from a team as code owners October 28, 2025 15:47
@dsnopek dsnopek marked this pull request as draft October 28, 2025 15:47
@dsnopek dsnopek force-pushed the gdextension-interface-json-struct-handles branch from 7786eb4 to 7c3d7f2 Compare November 24, 2025 22:31
@dsnopek dsnopek force-pushed the gdextension-interface-json-struct-handles branch from 7c3d7f2 to cb1c900 Compare January 17, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant