Skip to content

Conversation

@Bromeon
Copy link
Member

@Bromeon Bromeon commented Nov 24, 2025

Introduces new internal traits EngineToGodot + EngineFromGodot. These are used by functions in generated code for engine APIs. Where available, they delegate to ToGodot + FromGodot traits via blanket impl. In addition, they have implementations for types that make sense on an engine level, but not for user-defined #[func] functions or Variant conversions.

This addresses multiple problems:

  1. Type u64 currently implements ToGodot/FromGodot out of necessity:

    • It's required for engine-provided APIs, which are backed by C++ std::uint64_t and thus safe.
    • However, #[func] interacts with GDScript, which does not have an unsigned 64-bit type. The current implementation panics, which is the only instance of such behavior in otherwise infallible ToGodot::to_godot(). Silently changing value would be even worse.
    • This PR removes impl To/FromGodot for u64.
  2. Similar: raw pointers like native-struct *const AudioFrame, or *const c_void used in virtual methods.

    • While not technically unsound (?), there's hardly a way to use those correctly in variant conversions or #[func]. You can just do 123.to_variant().to::<*mut Glyph>() and obtain a bad pointer.
    • Again, engine methods need them but #[func] doesn't.
    • Removing such impls also declutters the impl docs for ToGodot and FromGodot.
  3. There is currently a bug: API calls cause runtime panics for some u64 values.

    • If highest bit is set, i.e. value > i64::MAX, the ToGodot validation kicks in and causes panic.
    • Itest u64_fileaccess_roundtrip tests that this works after the changes.
  4. Relatedly, bitfields are represented as u64.

    • According to my brief research, there are no bitfields that currently use the highest bit, but this is possible. If that happens, then a panic could also occur.
    • A private EngineToGodot trait can handle this case without exposing error-prone conversions for public use.

@Bromeon Bromeon added this to the 0.5 milestone Nov 24, 2025
@Bromeon Bromeon added bug breaking-change Requires SemVer bump c: core Core components c: ffi Low-level components and interaction with GDExtension API labels Nov 24, 2025
@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1413

@Bromeon Bromeon force-pushed the qol/u64-engine-only branch from 88ebf37 to 2008b2d Compare November 24, 2025 22:21
Allows to treat user-defined #[func] conversions separately
from engine-provided APIs (class methods, enums, ...).

Removes #[func] support for u64.
@Bromeon Bromeon force-pushed the qol/u64-engine-only branch from 2008b2d to abdd40e Compare December 4, 2025 19:03
@Bromeon Bromeon enabled auto-merge December 4, 2025 19:07
@Bromeon Bromeon added this pull request to the merge queue Dec 4, 2025
Merged via the queue into master with commit e45c123 Dec 4, 2025
20 checks passed
@Bromeon Bromeon deleted the qol/u64-engine-only branch December 4, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Requires SemVer bump bug c: core Core components c: ffi Low-level components and interaction with GDExtension API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants