Skip to content

Commit aa5dfff

Browse files
committed
Merge pull request #77410 from dsnopek/object-pointer-pointer-encoding
Standardize Object ptrcall encoding on `Object **`
2 parents 17bfccc + 77733fa commit aa5dfff

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

core/object/ref_counted.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,11 @@ class WeakRef : public RefCounted {
242242
template <class T>
243243
struct PtrToArg<Ref<T>> {
244244
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
245+
if (p_ptr == nullptr) {
246+
return Ref<T>();
247+
}
245248
// p_ptr points to a RefCounted object
246-
return Ref<T>(const_cast<T *>(reinterpret_cast<const T *>(p_ptr)));
249+
return Ref<T>(const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr)));
247250
}
248251

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

261264
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
265+
if (p_ptr == nullptr) {
266+
return Ref<T>();
267+
}
262268
// p_ptr points to a RefCounted object
263-
return Ref<T>((T *)p_ptr);
269+
return Ref<T>(*((T *const *)p_ptr));
264270
}
265271
};
266272

core/variant/method_ptrcall.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ MAKE_PTRARG_BY_REFERENCE(Variant);
159159
template <class T>
160160
struct PtrToArg<T *> {
161161
_FORCE_INLINE_ static T *convert(const void *p_ptr) {
162-
return const_cast<T *>(reinterpret_cast<const T *>(p_ptr));
162+
if (p_ptr == nullptr) {
163+
return nullptr;
164+
}
165+
return const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr));
163166
}
164167
typedef Object *EncodeT;
165168
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
@@ -170,7 +173,10 @@ struct PtrToArg<T *> {
170173
template <class T>
171174
struct PtrToArg<const T *> {
172175
_FORCE_INLINE_ static const T *convert(const void *p_ptr) {
173-
return reinterpret_cast<const T *>(p_ptr);
176+
if (p_ptr == nullptr) {
177+
return nullptr;
178+
}
179+
return *reinterpret_cast<T *const *>(p_ptr);
174180
}
175181
typedef const Object *EncodeT;
176182
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {

core/variant/variant_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ class VariantInternal {
502502
case Variant::PACKED_COLOR_ARRAY:
503503
return get_color_array(v);
504504
case Variant::OBJECT:
505-
return v->_get_obj().obj;
505+
return get_object(v);
506506
case Variant::VARIANT_MAX:
507507
ERR_FAIL_V(nullptr);
508508
}

modules/mono/editor/bindings_generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2889,7 +2889,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
28892889

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

2892-
itype.c_arg_in = "(void*)%s";
2892+
itype.c_arg_in = "&%s";
28932893
itype.c_type = "IntPtr";
28942894
itype.c_type_in = itype.c_type;
28952895
itype.c_type_out = "GodotObject";

0 commit comments

Comments
 (0)