Skip to content

Commit 5cdc2fc

Browse files
authored
Merge pull request #1214 from dsnopek/ptrtoarg-native-struct
Ensure that PtrToArg specializations for native structs are used
2 parents adcc955 + 3cd3f24 commit 5cdc2fc

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
@@ -1179,6 +1179,12 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
11791179
else:
11801180
fully_used_classes.add("Wrapped")
11811181

1182+
# In order to ensure that PtrToArg specializations for native structs are
1183+
# always used, let's move any of them into 'fully_used_classes'.
1184+
for type_name in used_classes:
1185+
if is_struct_type(type_name) and not is_included_struct_type(type_name):
1186+
fully_used_classes.add(type_name)
1187+
11821188
for type_name in fully_used_classes:
11831189
if type_name in used_classes:
11841190
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)