-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
GDExtension: PtrToArg::convert()
uses const-reference where possible
#80075
GDExtension: PtrToArg::convert()
uses const-reference where possible
#80075
Conversation
0998341
to
df033aa
Compare
_FORCE_INLINE_ static TypedArray<T> | ||
convert(const void *p_ptr) { | ||
_FORCE_INLINE_ static TypedArray<T> convert(const void *p_ptr) { |
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.
This is purely a whitespace change (should be more readable and still OK for clang-format) 🙂
df033aa
to
7acbbfb
Compare
PtrArg::convert()
uses const-reference where possiblePtrToArg::convert()
uses const-reference where possible
CI job Editor with doubles and GCC sanitizers failed with:
I encountered the same issue in my own nightly builds, also gcc memcheck running out of disk space... Was there a regression? Or GitHub decreased available disk space? |
@Bromeon See:
|
Good catch! This makes sense to me. Even outside the context of GDExtension, we do ptrcalls with code like: template <class T, class... P, size_t... Is>
void call_with_ptr_args_helper(T *p_instance, void (T::*p_method)(P...), const void **p_args, IndexSequence<Is...>) {
(p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...);
} In the case that one (or more) of the method's arguments takes a I ran godot-cpp's automated tests and they passed. So, this seems OK from the perspective of GDExtension. It could probably use to be reviewed by the core team as well. |
…nnecessary copies
7acbbfb
to
38334fd
Compare
Rebased onto |
Discussed at the GDExtension meeting, and we think this makes sense. This is also on the agenda to discuss at the core team meeting, where we hope to double check with them that this won't cause any other problems. |
Great Catch! |
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.
The core team meeting I was hoping to discuss this at didn't end up really happening. It'd still be nice to have a review from someone on the core team, however, I personally really think this should be OK. This is adding const &
in a template and so I think any issues would be detected at compile time, and this is compiling just fine on all platforms in the CI.
The compiler has to be conservative, because the pointer passed to It is our "insider knowledge" that a GDExtension binding keeps that pointer unchanged, as it's in a function call. |
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.
Couldn't get another review from the core team, but it looks overall sensible to me and I trust that if there's any issue with this change, we'll find out fast.
Thanks! |
Fixes #80074.
In the cases where
reinterpret_cast
is immediately dereferenced,PtrToArg::convert()
returns a const-reference instead of a value. This allows to reuse the object located at the address of the passedconst void*
pointer, instead of triggering the copy constructor.We cannot return const-references where temporary values are constructed. Most manual
PtrToArg
specializations fall under this category and are thus untouched.In some cases, we now return a const-reference to scalar types like
int
,bool
etc. Since the function is annotated as_FORCE_INLINE_
, I expect any such indirections to be optimized away though.I did some tests with the Rust binding (gdext) already, but I'd appreciate some input on this!