-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
Implement virtual methods that accept or return pointers (per #191) #272
Conversation
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-272 |
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.
Thanks a lot for this pull request! 😀
Added some comments in the code.
I'm not very sure if generally implementing ToVariant
/FromVariant
for pointer types is desired. Is there any use case outside of native structures? If not, we may have to bite the bullet and split the SignatureTuple
trait, as discussed on Discord 🤔 more thoughts on this?
If you rebase this code on latest master, the godot-itest
failure should go away and the license-guard
one should become more expressive (every file needs a license header).
7bbdde9
to
7b6e5eb
Compare
Regarding this, I don't think there's a use case in "ordinary" Godot code (read: Anything that doesn't end in the word "Extension"). But I personally think it's a lot nicer tunneling through a |
The question is: should this be part of the public API?
I'm actually more worried about the other side: "deserialization-from-Godot", aka. If we allow let variant = 32.to_variant();
let ptr = variant.to::<*mut String>(); While it is technically safe, we essentially committed a
But they always return a valid result, or the conversion fails as Result::Err. AFAIK it's not possible to construct invalid values (otherwise it might be a bug).
Maybe that's an indicator that it deserves a more specialized API than the high-level Either way, if you modify it, please preserve the current commit ( |
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.
Your last merge seems to have gone wrong; you are now reverting changes from the master
branch.
I just mentioned a few files, but many more are affected.
godot/Cargo.toml
Outdated
@@ -9,11 +9,11 @@ categories = ["game-engines", "graphics"] | |||
|
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.
Your seem to accidentally revert several unrelated changes from master
. Please undo those changes.
godot/src/lib.rs
Outdated
@@ -4,15 +4,15 @@ | |||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. |
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.
Also in this file.
itest/rust/Cargo.toml
Outdated
@@ -10,11 +10,13 @@ crate-type = ["cdylib"] | |||
|
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.
And here.
7b6e5eb
to
4107ee6
Compare
@Bromeon Oof, sorry about the botched rebase. I think it should be repaired now. Let me know if anything still looks suspicious. I see your argument regarding |
Added commit to split the signature tuple trait. It ended up being far simpler than I thought (the macro calls just automagically know which trait they need; there wasn't a lot of manual correction to be done). |
6712001
to
949534b
Compare
This is equivalent to doing let a: usize = 32;
let ptr = a as *mut String; Which is entirely legal in safe rust. i dont think this is an argument against allowing this conversion. Unless you're suggesting we change to using strict provenance, then this is entirely fine within rust. But using strict provenance would be a big change.
You can't construct invalid values in the sense of unsafety or unsoundness. But we can return semantically invalid values. Like returning a
An alternative solution here would be to leverage the This would require a fair bit of rewriting though, especially as it seems like we're misusing the pub trait GodotFuncMarshal: Sized {
/// Intermediate type through which Self is converted.
type Via;
/// The type returned when conversion fails
type Error: Debug;
...
} |
I'm aware of that, which is precisely why I mentioned "technically safe". You can write
Memory safety is irrelevant here, what I'm talking about is the potential to introduce bugs. And I'm not a fan of APIs that make this easy, especially if they mostly exist to serve internal implementation.
It looks like the latest revision of this PR works without |
This commit splits SignatureTuple into two separate traits: PtrcallSignatureTuple and VarcallSignatureTuple. The latter is a child of the former. PtrcallSignatureTuple is used for ptrcall and only demands GodotFuncMarshall of its arguments. VarcallSignatureTuple is used for varcall and additionally demands ToVariant, FromVariant, and VariantMetadata of its arguments, so pointers cannot benefit from the optimizations provided by varcall over ptrcall.
949534b
to
07f8d2e
Compare
bors try |
tryBuild failed: |
@Bromeon Are those bors failures merge conflicts? They don't look like parts of the codebase I've touched. What is bors doing that |
No, those point to an upstream change with Godot (the I'm already working on this, no action needed from your side 🙂 |
bors try |
tryBuild succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
bors r+ |
bors p=10 |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Thanks a lot for this addition and the patience! 🚀 |
314: `ApproxEq` trait + refactorings r=Bromeon a=Bromeon Changes: ### Add `ApproxEq` trait and implement it for many builtin types. * This standardizes checking for approximate equality across types. * Gets rid of the boilerplate 3rd argument `assert_eq_approx!(a, b, is_equal_approx)`. * That argument can still be specified if desired, using `assert_eq_approx!(a, b, fn = is_equal_approx)`. * In 95% of cases, it's not needed though. ### Refactor modules * `godot::builtin::math` is now a public module, which contains: * Godot ported functions such as `lerp`, `sign` * `ApproxEq` trait + `assert_eq_approx!`, `assert_ne_approx!` macros * glam utilities: `IVec4`, `GlamConv`, etc (internal) * The above symbols are no longer in `godot::builtin`. If this turns out to be an issue, we can also revert this in the future; but it might help some discoverability. Some symbols could also be considered to be part of the prelude. * Move `godot::native_structure` -> `godot::engine::native` * Added in #272 * Native structures are now less prominent because rarely used. * Move `real`-related symbols into their own `real.rs` file (internal; API unaffected). ### Refactor import statements (just around geometric types, not whole codebase) * Remove wildcard imports * Remove nested import statements * Consistent order Co-authored-by: Jan Haller <bromeon@gmail.com>
This MR adds all missing virtual functions which were previously omitted due to an argument or return value being a pointer. All pointers are translated into Rust-side raw pointers (
*const T
or*mut T
, as appropriate). All virtual trait functions which either take or return a pointer are marked asunsafe
.All
native_structures
structs in the JSON file have been translated into Rust-side structures (with#[repr(C)]
to ensure binary compatibility) and placed in thegodot::native
directory. These are all pure data structs (all fields are public and they have no methods). Many of the pointer functions take or return pointers to these native structures, so being able to construct and access them Rust-side is essential for this functionality.There is one double pointer in the JSON API.
const uint8_t**
appears in several of the networking functions. I believe the correct translation of this type (preservingconst
) is*mut *const u8
, which is what the code in this MR uses.