Skip to content

Commit 7713d57

Browse files
committed
Merge remote-tracking branch 'upstream/master' into tests
2 parents e28baec + fbc9539 commit 7713d57

32 files changed

Lines changed: 379 additions & 164 deletions

.github/workflows/static_checks.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,3 @@ jobs:
3535
uses: pre-commit/action@v3.0.1
3636
with:
3737
extra_args: --files ${{ env.CHANGED_FILES }}
38-
39-
- name: Class reference schema checks
40-
run: |
41-
sudo apt-get update
42-
sudo apt-get install libxml2-utils
43-
xmllint --quiet --noout --schema doc/class.xsd doc/classes/*.xml modules/*/doc_classes/*.xml platform/*/doc_classes/*.xml

.pre-commit-config.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,6 @@ repos:
6464
files: ^core/extension/gdextension_interface\.json$
6565
args: ["--schemafile", "core/extension/gdextension_interface.schema.json"]
6666

67-
### Requires Docker; look into alternative implementation.
68-
# - repo: https://github.com/comkieffer/pre-commit-xmllint.git
69-
# rev: 1.0.0
70-
# hooks:
71-
# - id: xmllint
72-
# language: docker
73-
# types_or: [text]
74-
# files: ^(doc/classes|.*/doc_classes)/.*\.xml$
75-
# args: [--schema, doc/class.xsd]
76-
7767
- repo: local
7868
hooks:
7969
- id: make-rst
@@ -99,6 +89,13 @@ repos:
9989
pass_filenames: false
10090
files: ^(gles3|glsl)_builders\.py$
10191

92+
- id: validate-xml
93+
name: validate-xml
94+
language: python
95+
entry: python misc/scripts/validate_xml.py
96+
files: ^(doc/classes|.*/doc_classes)/.*\.xml$
97+
additional_dependencies: [xmlschema]
98+
10299
- id: eslint
103100
name: eslint
104101
language: node

core/extension/gdextension.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ void GDExtension::_register_extension_class_internal(GDExtensionClassLibraryPtr
491491
}
492492
#endif
493493

494+
extension->gdextension.create_gdtype();
495+
494496
ClassDB::register_extension_class(&extension->gdextension);
495497

496498
if (p_extension_funcs->icon_path != nullptr) {
@@ -970,6 +972,8 @@ void GDExtension::_clear_extension(Extension *p_extension) {
970972

971973
obj->clear_internal_extension();
972974
}
975+
976+
p_extension->gdextension.destroy_gdtype();
973977
}
974978

975979
void GDExtension::track_instance_binding(Object *p_object) {

core/object/class_db.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ class PlaceholderExtensionInstance {
196196
obj->_extension = ClassDB::get_placeholder_extension(ti->name);
197197
obj->_extension_instance = memnew(PlaceholderExtensionInstance(ti->name));
198198

199+
obj->_reset_gdtype();
200+
199201
#ifdef TOOLS_ENABLED
200202
if (obj->_extension->track_instance) {
201203
obj->_extension->track_instance(obj->_extension->tracking_userdata, obj);
@@ -756,10 +758,19 @@ ObjectGDExtension *ClassDB::get_placeholder_extension(const StringName &p_class)
756758
placeholder_extension->call_virtual_with_data = nullptr;
757759
placeholder_extension->recreate_instance = &PlaceholderExtensionInstance::placeholder_class_recreate_instance;
758760

761+
placeholder_extension->create_gdtype();
762+
759763
return placeholder_extension;
760764
}
761765
#endif
762766

767+
const GDType *ClassDB::get_gdtype(const StringName &p_class) {
768+
Locker::Lock lock(Locker::STATE_READ);
769+
ClassInfo *type = classes.getptr(p_class);
770+
ERR_FAIL_NULL_V(type, nullptr);
771+
return type->gdtype;
772+
}
773+
763774
void ClassDB::set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance) {
764775
ERR_FAIL_NULL(p_object);
765776
ClassInfo *ti;
@@ -779,6 +790,8 @@ void ClassDB::set_object_extension_instance(Object *p_object, const StringName &
779790
p_object->_extension = ti->gdextension;
780791
p_object->_extension_instance = p_instance;
781792

793+
p_object->_reset_gdtype();
794+
782795
#ifdef TOOLS_ENABLED
783796
if (p_object->_extension->track_instance) {
784797
p_object->_extension->track_instance(p_object->_extension->tracking_userdata, p_object);
@@ -870,17 +883,20 @@ bool ClassDB::is_virtual(const StringName &p_class) {
870883
return scr.is_valid() && scr->is_valid() && scr->is_abstract();
871884
}
872885

873-
void ClassDB::_add_class(const StringName &p_class, const StringName &p_inherits) {
886+
void ClassDB::_add_class(const GDType &p_class, const GDType *p_inherits) {
874887
Locker::Lock lock(Locker::STATE_WRITE);
875888

876-
const StringName &name = p_class;
889+
const StringName &name = p_class.get_name();
877890

878-
ERR_FAIL_COND_MSG(classes.has(name), vformat("Class '%s' already exists.", String(p_class)));
891+
ERR_FAIL_COND_MSG(classes.has(name), vformat("Class '%s' already exists.", name));
879892

880893
classes[name] = ClassInfo();
881894
ClassInfo &ti = classes[name];
882895
ti.name = name;
883-
ti.inherits = p_inherits;
896+
ti.gdtype = &p_class;
897+
if (p_inherits) {
898+
ti.inherits = p_inherits->get_name();
899+
}
884900
ti.api = current_api;
885901

886902
if (ti.inherits) {
@@ -2350,6 +2366,8 @@ void ClassDB::register_extension_class(ObjectGDExtension *p_extension) {
23502366
c.is_runtime = p_extension->is_runtime;
23512367
#endif
23522368

2369+
c.gdtype = p_extension->gdtype;
2370+
23532371
classes[p_extension->class_name] = c;
23542372
}
23552373

core/object/class_db.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class ClassDB {
123123
APIType api = API_NONE;
124124
ClassInfo *inherits_ptr = nullptr;
125125
void *class_ptr = nullptr;
126+
const GDType *gdtype = nullptr;
126127

127128
ObjectGDExtension *gdextension = nullptr;
128129

@@ -218,7 +219,7 @@ class ClassDB {
218219
static APIType current_api;
219220
static HashMap<APIType, uint32_t> api_hashes_cache;
220221

221-
static void _add_class(const StringName &p_class, const StringName &p_inherits);
222+
static void _add_class(const GDType &p_class, const GDType *p_inherits);
222223

223224
static HashMap<StringName, HashMap<StringName, Variant>> default_values;
224225
static HashSet<StringName> default_values_cached;
@@ -334,6 +335,7 @@ class ClassDB {
334335
static void get_extension_class_list(const Ref<GDExtension> &p_extension, List<StringName> *p_classes);
335336
static ObjectGDExtension *get_placeholder_extension(const StringName &p_class);
336337
#endif
338+
static const GDType *get_gdtype(const StringName &p_class);
337339
static void get_inheriters_from_class(const StringName &p_class, LocalVector<StringName> &p_classes);
338340
static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
339341
static StringName get_parent_class_nocheck(const StringName &p_class);

core/object/gdtype.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232

3333
GDType::GDType(const GDType *p_super_type, StringName p_name) :
3434
super_type(p_super_type), name(std::move(p_name)) {
35-
name_hierarchy.push_back(StringName(name, true));
35+
name_hierarchy.push_back(name);
3636

3737
if (super_type) {
3838
for (const StringName &ancestor_name : super_type->name_hierarchy) {
39-
name_hierarchy.push_back(StringName(ancestor_name, true));
39+
name_hierarchy.push_back(ancestor_name);
4040
}
4141
}
4242
}

core/object/object.cpp

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,25 @@ Object::Connection::operator Variant() const {
230230
return d;
231231
}
232232

233+
void ObjectGDExtension::create_gdtype() {
234+
ERR_FAIL_COND(gdtype);
235+
236+
gdtype = memnew(GDType(ClassDB::get_gdtype(parent_class_name), class_name));
237+
}
238+
239+
void ObjectGDExtension::destroy_gdtype() {
240+
ERR_FAIL_COND(!gdtype);
241+
242+
memdelete(const_cast<GDType *>(gdtype));
243+
gdtype = nullptr;
244+
}
245+
246+
ObjectGDExtension::~ObjectGDExtension() {
247+
if (gdtype) {
248+
memdelete(const_cast<GDType *>(gdtype));
249+
}
250+
}
251+
233252
bool Object::Connection::operator<(const Connection &p_conn) const {
234253
if (signal == p_conn.signal) {
235254
return callable < p_conn.callable;
@@ -279,6 +298,7 @@ bool Object::_predelete() {
279298
}
280299
_extension = nullptr;
281300
_extension_instance = nullptr;
301+
// _gdtype_ptr = nullptr; // The pointer already set to nullptr above, no need to do it again.
282302
}
283303
#ifdef TOOLS_ENABLED
284304
else if (_instance_bindings != nullptr) {
@@ -1379,6 +1399,16 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
13791399
return err;
13801400
}
13811401

1402+
void Object::_reset_gdtype() const {
1403+
if (_extension) {
1404+
// Set to extension's type.
1405+
_gdtype_ptr = _extension->gdtype;
1406+
} else {
1407+
// Reset to internal type.
1408+
_gdtype_ptr = &_get_typev();
1409+
}
1410+
}
1411+
13821412
void Object::_add_user_signal(const String &p_name, const Array &p_args) {
13831413
// this version of add_user_signal is meant to be used from scripts or external apis
13841414
// without access to ADD_SIGNAL in bind_methods
@@ -1734,7 +1764,7 @@ void Object::initialize_class() {
17341764
if (initialized) {
17351765
return;
17361766
}
1737-
_add_class_to_classdb(get_class_static(), StringName());
1767+
_add_class_to_classdb(get_gdtype_static(), nullptr);
17381768
_bind_methods();
17391769
_bind_compatibility_methods();
17401770
initialized = true;
@@ -1810,8 +1840,8 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) {
18101840
}
18111841
}
18121842

1813-
void Object::_add_class_to_classdb(const StringName &p_class, const StringName &p_inherits) {
1814-
ClassDB::_add_class(p_class, p_inherits);
1843+
void Object::_add_class_to_classdb(const GDType &p_type, const GDType *p_inherits) {
1844+
ClassDB::_add_class(p_type, p_inherits);
18151845
}
18161846

18171847
void Object::_get_property_list_from_classdb(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
@@ -2128,9 +2158,6 @@ const GDType &Object::get_gdtype() const {
21282158
}
21292159

21302160
bool Object::is_class(const String &p_class) const {
2131-
if (_extension && _extension->is_class(p_class)) {
2132-
return true;
2133-
}
21342161
for (const StringName &name : get_gdtype().get_name_hierarchy()) {
21352162
if (name == p_class) {
21362163
return true;
@@ -2140,11 +2167,6 @@ bool Object::is_class(const String &p_class) const {
21402167
}
21412168

21422169
const StringName &Object::get_class_name() const {
2143-
if (_extension) {
2144-
// Can't put inside the unlikely as constructor can run it.
2145-
return _extension->class_name;
2146-
}
2147-
21482170
return get_gdtype().get_name();
21492171
}
21502172

@@ -2277,6 +2299,8 @@ void Object::clear_internal_extension() {
22772299
}
22782300
_extension = nullptr;
22792301
_extension_instance = nullptr;
2302+
// Reset GDType to internal type.
2303+
_gdtype_ptr = &_get_typev();
22802304

22812305
// Clear the instance bindings.
22822306
_instance_binding_mutex.lock();
@@ -2305,6 +2329,7 @@ void Object::reset_internal_extension(ObjectGDExtension *p_extension) {
23052329
_extension_instance = p_extension->recreate_instance ? p_extension->recreate_instance(p_extension->class_userdata, (GDExtensionObjectPtr)this) : nullptr;
23062330
ERR_FAIL_NULL_MSG(_extension_instance, "Unable to recreate GDExtension instance - does this extension support hot reloading?");
23072331
_extension = p_extension;
2332+
_gdtype_ptr = p_extension->gdtype;
23082333
}
23092334
}
23102335
#endif

core/object/object.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,6 @@ struct ObjectGDExtension {
349349
GDExtensionClassReference unreference;
350350
GDExtensionClassGetRID get_rid;
351351

352-
_FORCE_INLINE_ bool is_class(const String &p_class) const {
353-
const ObjectGDExtension *e = this;
354-
while (e) {
355-
if (p_class == e->class_name.operator String()) {
356-
return true;
357-
}
358-
e = e->parent;
359-
}
360-
return false;
361-
}
362352
void *class_userdata = nullptr;
363353

364354
#ifndef DISABLE_DEPRECATED
@@ -380,6 +370,14 @@ struct ObjectGDExtension {
380370
void (*track_instance)(void *p_userdata, void *p_instance) = nullptr;
381371
void (*untrack_instance)(void *p_userdata, void *p_instance) = nullptr;
382372
#endif
373+
374+
/// A type for this Object extension.
375+
/// This is not exposed through the GDExtension API (yet) so it is inferred from above parameters.
376+
const GDType *gdtype;
377+
void create_gdtype();
378+
void destroy_gdtype();
379+
380+
~ObjectGDExtension();
383381
};
384382

385383
#define GDVIRTUAL_CALL(m_name, ...) _gdvirtual_##m_name##_call(__VA_ARGS__)
@@ -525,7 +523,7 @@ public:
525523
return; \
526524
} \
527525
m_inherits::initialize_class(); \
528-
_add_class_to_classdb(get_class_static(), super_type::get_class_static()); \
526+
_add_class_to_classdb(get_gdtype_static(), &super_type::get_gdtype_static()); \
529527
if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \
530528
_bind_methods(); \
531529
} \
@@ -673,6 +671,7 @@ class Object {
673671
HashMap<StringName, Variant> metadata;
674672
HashMap<StringName, Variant *> metadata_properties;
675673
mutable const GDType *_gdtype_ptr = nullptr;
674+
void _reset_gdtype() const;
676675

677676
void _add_user_signal(const String &p_name, const Array &p_args = Array());
678677
bool _has_user_signal(const StringName &p_name) const;
@@ -793,7 +792,7 @@ class Object {
793792
friend class ::ClassDB;
794793
friend class PlaceholderExtensionInstance;
795794

796-
static void _add_class_to_classdb(const StringName &p_class, const StringName &p_inherits);
795+
static void _add_class_to_classdb(const GDType &p_class, const GDType *p_inherits);
797796
static void _get_property_list_from_classdb(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator);
798797

799798
bool _disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force = false);

core/string/translation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void Translation::_set_messages(const Dictionary &p_messages) {
7777
for (const KeyValue<Variant, Variant> &kv : p_messages) {
7878
switch (kv.key.get_type()) {
7979
// Old version, no context or plural support.
80+
case Variant::STRING:
8081
case Variant::STRING_NAME: {
8182
const MessageKey msg_key = { StringName(), kv.key };
8283
_check_for_incompatibility(msg_key.msgctxt, msg_key.msgid);

core/variant/method_ptrcall.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ struct PtrToArg<const T *> {
273273

274274
template <class T>
275275
struct PtrToArg<RequiredParam<T>> {
276-
typedef typename RequiredParam<T>::ptr_type EncodeT;
276+
typedef typename RequiredParam<T>::persistent_type EncodeT;
277277

278278
_FORCE_INLINE_ static RequiredParam<T> convert(const void *p_ptr) {
279279
if (p_ptr == nullptr) {
@@ -283,7 +283,7 @@ struct PtrToArg<RequiredParam<T>> {
283283
}
284284

285285
_FORCE_INLINE_ static void encode(const RequiredParam<T> &p_var, void *p_ptr) {
286-
*((typename RequiredParam<T>::ptr_type *)p_ptr) = p_var._internal_ptr_dont_use();
286+
*((typename RequiredParam<T>::persistent_type *)p_ptr) = p_var._internal_ptr_dont_use();
287287
}
288288
};
289289

0 commit comments

Comments
 (0)