Skip to content
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

Standardize Object ptrcall encoding on Object ** #77410

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions core/object/ref_counted.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,11 @@ class WeakRef : public RefCounted {
template <class T>
struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
if (p_ptr == nullptr) {
return Ref<T>();
}
// p_ptr points to a RefCounted object
return Ref<T>(const_cast<T *>(reinterpret_cast<const T *>(p_ptr)));
return Ref<T>(const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr)));
}

typedef Ref<T> EncodeT;
Expand All @@ -259,8 +262,11 @@ struct PtrToArg<const Ref<T> &> {
typedef Ref<T> EncodeT;

_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
if (p_ptr == nullptr) {
return Ref<T>();
}
// p_ptr points to a RefCounted object
return Ref<T>((T *)p_ptr);
return Ref<T>(*((T *const *)p_ptr));
}
};

Expand Down
10 changes: 8 additions & 2 deletions core/variant/method_ptrcall.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ MAKE_PTRARG_BY_REFERENCE(Variant);
template <class T>
struct PtrToArg<T *> {
_FORCE_INLINE_ static T *convert(const void *p_ptr) {
return const_cast<T *>(reinterpret_cast<const T *>(p_ptr));
if (p_ptr == nullptr) {
return nullptr;
}
return const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr));
}
typedef Object *EncodeT;
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
Expand All @@ -170,7 +173,10 @@ struct PtrToArg<T *> {
template <class T>
struct PtrToArg<const T *> {
_FORCE_INLINE_ static const T *convert(const void *p_ptr) {
return reinterpret_cast<const T *>(p_ptr);
if (p_ptr == nullptr) {
return nullptr;
}
return *reinterpret_cast<T *const *>(p_ptr);
}
typedef const Object *EncodeT;
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
Expand Down
2 changes: 1 addition & 1 deletion core/variant/variant_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ class VariantInternal {
case Variant::PACKED_COLOR_ARRAY:
return get_color_array(v);
case Variant::OBJECT:
return v->_get_obj().obj;
return get_object(v);
case Variant::VARIANT_MAX:
ERR_FAIL_V(nullptr);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/editor/bindings_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2865,7 +2865,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() {

itype.cs_out = "%5return (%2)%0(%1);";

itype.c_arg_in = "(void*)%s";
itype.c_arg_in = "&%s";
itype.c_type = "IntPtr";
itype.c_type_in = itype.c_type;
itype.c_type_out = "GodotObject";
Expand Down