Skip to content

Commit 3cd3f24

Browse files
committed
Ensure that PtrToArg specializations for native structs are used
1 parent df55005 commit 3cd3f24

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

binding_generator.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,12 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
11441144
else:
11451145
fully_used_classes.add("Wrapped")
11461146

1147+
# In order to ensure that PtrToArg specializations for native structs are
1148+
# always used, let's move any of them into 'fully_used_classes'.
1149+
for type_name in used_classes:
1150+
if is_struct_type(type_name) and not is_included_struct_type(type_name):
1151+
fully_used_classes.add(type_name)
1152+
11471153
for type_name in fully_used_classes:
11481154
if type_name in used_classes:
11491155
used_classes.remove(type_name)

include/godot_cpp/core/method_ptrcall.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ MAKE_PTRARG_BY_REFERENCE(Variant);
168168

169169
template <class T>
170170
struct PtrToArg<T *> {
171+
static_assert(std::is_base_of<Object, T>::value, "Cannot encode non-Object value as an Object");
171172
_FORCE_INLINE_ static T *convert(const void *p_ptr) {
172173
return reinterpret_cast<T *>(godot::internal::get_object_instance_binding(*reinterpret_cast<GDExtensionObjectPtr *>(const_cast<void *>(p_ptr))));
173174
}
@@ -179,6 +180,7 @@ struct PtrToArg<T *> {
179180

180181
template <class T>
181182
struct PtrToArg<const T *> {
183+
static_assert(std::is_base_of<Object, T>::value, "Cannot encode non-Object value as an Object");
182184
_FORCE_INLINE_ static const T *convert(const void *p_ptr) {
183185
return reinterpret_cast<const T *>(godot::internal::get_object_instance_binding(*reinterpret_cast<GDExtensionObjectPtr *>(const_cast<void *>(p_ptr))));
184186
}

0 commit comments

Comments
 (0)