Skip to content
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
24 changes: 21 additions & 3 deletions core/extension/gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ void GDExtension::_register_extension_class(GDExtensionClassLibraryPtr p_library
p_extension_funcs->get_rid_func, // GDExtensionClassGetRID get_rid;
p_extension_funcs->get_virtual_func, // GDExtensionClassGetVirtual get_virtual_func;
nullptr,
false, // p_creation_is_with_refcount
};
_register_extension_class_internal(p_library, p_class_name, p_parent_class_name, &class_info5, &legacy);
}
Expand Down Expand Up @@ -313,6 +314,7 @@ void GDExtension::_register_extension_class2(GDExtensionClassLibraryPtr p_librar
p_extension_funcs->get_rid_func, // GDExtensionClassGetRID get_rid;
p_extension_funcs->get_virtual_func, // GDExtensionClassGetVirtual get_virtual_func;
p_extension_funcs->get_virtual_call_data_func, // GDExtensionClassGetVirtual get_virtual_func;
false, // p_creation_is_with_refcount
};
_register_extension_class_internal(p_library, p_class_name, p_parent_class_name, &class_info5, &legacy);
}
Expand Down Expand Up @@ -352,6 +354,7 @@ void GDExtension::_register_extension_class3(GDExtensionClassLibraryPtr p_librar
p_extension_funcs->get_rid_func, // GDExtensionClassGetRID get_rid;
p_extension_funcs->get_virtual_func, // GDExtensionClassGetVirtual get_virtual_func;
p_extension_funcs->get_virtual_call_data_func, // GDExtensionClassGetVirtual get_virtual_func;
false, // p_creation_is_with_refcount
};
_register_extension_class_internal(p_library, p_class_name, p_parent_class_name, &class_info5, &legacy);
}
Expand All @@ -366,12 +369,19 @@ void GDExtension::_register_extension_class4(GDExtensionClassLibraryPtr p_librar
nullptr, // GDExtensionClassGetRID get_rid;
nullptr, // GDExtensionClassGetVirtual get_virtual_func;
nullptr, // GDExtensionClassGetVirtual get_virtual_func;
false, // p_creation_is_with_refcount
};
_register_extension_class_internal(p_library, p_class_name, p_parent_class_name, &class_info5, &legacy);
}
#endif // DISABLE_DEPRECATED

void GDExtension::_register_extension_class5(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo5 *p_extension_funcs) {
ClassCreationDeprecatedInfo legacy = {};
legacy.p_creation_is_with_refcount = false;
_register_extension_class_internal(p_library, p_class_name, p_parent_class_name, p_extension_funcs, &legacy);
}
#endif // DISABLE_DEPRECATED

void GDExtension::_register_extension_class6(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo6 *p_extension_funcs) {
_register_extension_class_internal(p_library, p_class_name, p_parent_class_name, p_extension_funcs);
}

Expand Down Expand Up @@ -471,7 +481,14 @@ void GDExtension::_register_extension_class_internal(GDExtensionClassLibraryPtr
extension->gdextension.reference = p_extension_funcs->reference_func;
extension->gdextension.unreference = p_extension_funcs->unreference_func;
extension->gdextension.class_userdata = p_extension_funcs->class_userdata;
extension->gdextension.create_instance2 = p_extension_funcs->create_instance_func;
#ifndef DISABLE_DEPRECATED
if (p_deprecated_funcs && !p_deprecated_funcs->p_creation_is_with_refcount) {
extension->gdextension.create_instance2 = p_extension_funcs->create_instance_func;
} else
#endif
{
extension->gdextension.create_instance3 = p_extension_funcs->create_instance_func;
}
extension->gdextension.free_instance = p_extension_funcs->free_instance_func;
extension->gdextension.recreate_instance = p_extension_funcs->recreate_instance_func;
extension->gdextension.get_virtual2 = p_extension_funcs->get_virtual_func;
Expand Down Expand Up @@ -824,8 +841,9 @@ void GDExtension::initialize_gdextensions() {
register_interface_function("classdb_register_extension_class2", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class2);
register_interface_function("classdb_register_extension_class3", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class3);
register_interface_function("classdb_register_extension_class4", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class4);
#endif // DISABLE_DEPRECATED
register_interface_function("classdb_register_extension_class5", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class5);
#endif // DISABLE_DEPRECATED
register_interface_function("classdb_register_extension_class6", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class6);
register_interface_function("classdb_register_extension_class_method", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class_method);
register_interface_function("classdb_register_extension_class_virtual_method", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class_virtual_method);
register_interface_function("classdb_register_extension_class_integer_constant", (GDExtensionInterfaceFunctionPtr)&GDExtension::_register_extension_class_integer_constant);
Expand Down
4 changes: 3 additions & 1 deletion core/extension/gdextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class GDExtension : public Resource {
GDExtensionClassGetRID get_rid_func = nullptr;
GDExtensionClassGetVirtual get_virtual_func = nullptr;
GDExtensionClassGetVirtualCallData get_virtual_call_data_func = nullptr;
bool p_creation_is_with_refcount = true;
#endif // DISABLE_DEPRECATED
};

Expand All @@ -80,8 +81,9 @@ class GDExtension : public Resource {
static void _register_extension_class2(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo2 *p_extension_funcs);
static void _register_extension_class3(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo3 *p_extension_funcs);
static void _register_extension_class4(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo4 *p_extension_funcs);
#endif // DISABLE_DEPRECATED
static void _register_extension_class5(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo5 *p_extension_funcs);
#endif // DISABLE_DEPRECATED
static void _register_extension_class6(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo6 *p_extension_funcs);
static void _register_extension_class_internal(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo5 *p_extension_funcs, const ClassCreationDeprecatedInfo *p_deprecated_funcs = nullptr);
static void _register_extension_class_method(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionClassMethodInfo *p_method_info);
static void _register_extension_class_virtual_method(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionClassVirtualMethodInfo *p_method_info);
Expand Down
10 changes: 8 additions & 2 deletions core/extension/gdextension_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,12 +1652,17 @@ static GDExtensionObjectPtr gdextension_classdb_construct_object(GDExtensionCons
const StringName classname = *reinterpret_cast<const StringName *>(p_classname);
return (GDExtensionObjectPtr)ClassDB::instantiate_no_placeholders(classname);
}
#endif

static GDExtensionObjectPtr gdextension_classdb_construct_object2(GDExtensionConstStringNamePtr p_classname) {
const StringName classname = *reinterpret_cast<const StringName *>(p_classname);
return (GDExtensionObjectPtr)ClassDB::instantiate_without_postinitialization(classname);
}
#endif

static GDExtensionObjectPtr gdextension_classdb_construct_object3(GDExtensionConstStringNamePtr p_classname) {
const StringName classname = *reinterpret_cast<const StringName *>(p_classname);
return (GDExtensionObjectPtr)ClassDB::instantiate_without_postinitialization_with_refcount(classname);
}

static void *gdextension_classdb_get_class_tag(GDExtensionConstStringNamePtr p_classname) {
const StringName classname = *reinterpret_cast<const StringName *>(p_classname);
Expand Down Expand Up @@ -1856,8 +1861,9 @@ void gdextension_setup_interface() {
REGISTER_INTERFACE_FUNC(callable_custom_get_userdata);
#ifndef DISABLE_DEPRECATED
REGISTER_INTERFACE_FUNC(classdb_construct_object);
#endif // DISABLE_DEPRECATED
REGISTER_INTERFACE_FUNC(classdb_construct_object2);
#endif // DISABLE_DEPRECATED
REGISTER_INTERFACE_FUNC(classdb_construct_object3);
REGISTER_INTERFACE_FUNC(classdb_get_method_bind);
REGISTER_INTERFACE_FUNC(classdb_get_class_tag);
REGISTER_INTERFACE_FUNC(editor_add_plugin);
Expand Down
109 changes: 102 additions & 7 deletions core/extension/gdextension_interface.json
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,23 @@
}
]
},
{
"name": "GDExtensionClassCreateInstance3",
"kind": "function",
"return_value": {
"type": "GDExtensionObjectPtr"
},
"arguments": [
{
"name": "p_class_userdata",
"type": "void*"
},
{
"name": "p_notify_postinitialize",
"type": "GDExtensionBool"
}
]
},
{
"name": "GDExtensionClassFreeInstance",
"kind": "function",
Expand Down Expand Up @@ -1778,6 +1795,11 @@
"kind": "alias",
"type": "GDExtensionClassCreationInfo4"
},
{
"name": "GDExtensionClassCreationInfo6",
"kind": "alias",
"type": "GDExtensionClassCreationInfo5"
},
Comment on lines +1798 to +1802
Copy link
Copy Markdown
Contributor

@Yarwin Yarwin Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't make any difference – but should it really be set as an alias for GDExtensionClassCreationInfo4?

GDExtensionClassCreationInfo4 defines create_instance_func as:

                {
                    "name": "create_instance_func",
                    "type": "GDExtensionClassCreateInstance2",
                    "description": [
                        "(Default) constructor; mandatory. If the class is not instantiable, consider making it virtual or abstract."
                    ]
                },

while GDExtensionClassCreationInfo6 uses GDExtensionClassCreateInstance3.
As I said it makes no difference - same signature, different semantics, you set it accordingly ( extension->gdextension.create_instance3 = p_extension_funcs->create_instance_func;) if caller uses classdb_register_extension_class6, so effectively it is a nitpick

{
"name": "GDExtensionClassLibraryPtr",
"kind": "handle"
Expand Down Expand Up @@ -8242,7 +8264,7 @@
"since": "4.1",
"deprecated": {
"since": "4.4",
"replace_with": "classdb_construct_object2"
"replace_with": "classdb_construct_object3"
}
},
{
Expand All @@ -8268,7 +8290,37 @@
"",
"\"NOTIFICATION_POSTINITIALIZE\" must be sent after construction."
],
"since": "4.4"
"since": "4.4",
"deprecated": {
"since": "4.6",
"replace_with": "classdb_construct_object3"
}
},
{
"name": "classdb_construct_object3",
"return_value": {
"type": "GDExtensionObjectPtr",
"description": [
"A pointer to the newly created Object."
]
},
"arguments": [
{
"name": "p_classname",
"type": "GDExtensionConstStringNamePtr",
"description": [
"A pointer to a StringName with the class name."
]
}
],
"description": [
"Constructs an Object of the requested class.",
"The passed class must be a built-in godot class, or an already-registered extension class. In both cases, object_set_instance() should be called to fully initialize the object.",
"If the type is a subtype of RefCounted, it already has a refcount of 1. The caller must take ownership the refcount and is responsible for decrementing it again when the object is no longer needed.",
"",
"\"NOTIFICATION_POSTINITIALIZE\" must be sent after construction."
],
"since": "4.6"
},
{
"name": "classdb_get_method_bind",
Expand Down Expand Up @@ -8367,7 +8419,7 @@
"since": "4.1",
"deprecated": {
"since": "4.2",
"replace_with": "classdb_register_extension_class5"
"replace_with": "classdb_register_extension_class6"
}
},
{
Expand Down Expand Up @@ -8409,7 +8461,7 @@
"since": "4.2",
"deprecated": {
"since": "4.3",
"replace_with": "classdb_register_extension_class5"
"replace_with": "classdb_register_extension_class6"
}
},
{
Expand Down Expand Up @@ -8451,7 +8503,7 @@
"since": "4.3",
"deprecated": {
"since": "4.4",
"replace_with": "classdb_register_extension_class5"
"replace_with": "classdb_register_extension_class6"
}
},
{
Expand Down Expand Up @@ -8493,7 +8545,7 @@
"since": "4.4",
"deprecated": {
"since": "4.5",
"replace_with": "classdb_register_extension_class5"
"replace_with": "classdb_register_extension_class6"
}
},
{
Expand Down Expand Up @@ -8532,7 +8584,50 @@
"Registers an extension class in the ClassDB.",
"Provided struct can be safely freed once the function returns."
],
"since": "4.5"
"since": "4.5",
"deprecated": {
"since": "4.6",
"replace_with": "classdb_register_extension_class6"
}
},
{
"name": "classdb_register_extension_class6",
"arguments": [
{
"name": "p_library",
"type": "GDExtensionClassLibraryPtr",
"description": [
"A pointer the library received by the GDExtension's entry point function."
]
},
{
"name": "p_class_name",
"type": "GDExtensionConstStringNamePtr",
"description": [
"A pointer to a StringName with the class name."
]
},
{
"name": "p_parent_class_name",
"type": "GDExtensionConstStringNamePtr",
"description": [
"A pointer to a StringName with the parent class name."
]
},
{
"name": "p_extension_funcs",
"type": "const GDExtensionClassCreationInfo6*",
"description": [
"A pointer to a GDExtensionClassCreationInfo6 struct.",
"In contrast to GDExtensionClassCreationInfo5, the creation function must return RefCounted subtypes with a refcount of 1."
]
}
],
"description": [
"Registers an extension class in the ClassDB.",
"Provided struct can be safely freed once the function returns."
],
"since": "4.6"
},
{
"name": "classdb_register_extension_class_method",
Expand Down
Loading