From 7ff9b4d8e67b83c0f779cbfde9fdd410819a22b7 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 26 Mar 2023 14:21:30 +0200 Subject: [PATCH] [consider merging] more consistent behavior of RBA/pya: enum classes are properly made available (was for example RBA::Qt::Qt_Keys instead of RBA::Qt_Keys and pya.Qt.Keys was no fully initialized type object) --- src/gsi/gsi/gsiClassBase.cc | 19 +++++++++++++++++-- src/pya/pya/pyaModule.cc | 2 +- src/rba/rba/rba.cc | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/gsi/gsi/gsiClassBase.cc b/src/gsi/gsi/gsiClassBase.cc index 600c11ab8..2d7696c28 100644 --- a/src/gsi/gsi/gsiClassBase.cc +++ b/src/gsi/gsi/gsiClassBase.cc @@ -651,11 +651,26 @@ static void collect_classes (const gsi::ClassBase *cls, std::list::const_iterator cc = cls->begin_child_classes (); cc != cls->end_child_classes (); ++cc) { + for (auto cc = cls->begin_child_classes (); cc != cls->end_child_classes (); ++cc) { collect_classes (cc.operator-> (), unsorted_classes); } } +static bool all_parts_available (const gsi::ClassBase *cls, const std::set &taken) +{ + if (cls->declaration () && cls->declaration () != cls && taken.find (cls->declaration ()) == taken.end ()) { + return false; + } + + for (auto cc = cls->begin_child_classes (); cc != cls->end_child_classes (); ++cc) { + if (! all_parts_available (cc.operator-> (), taken)) { + return false; + } + } + + return true; +} + std::list ClassBase::classes_in_definition_order (const char *mod_name) { @@ -687,7 +702,7 @@ ClassBase::classes_in_definition_order (const char *mod_name) continue; } - if ((*c)->declaration () && (*c)->declaration () != *c && taken.find ((*c)->declaration ()) == taken.end ()) { + if (! all_parts_available (*c, taken)) { // can't produce this class yet - it's a reference to another class which is not produced yet. more_classes.push_back (*c); continue; diff --git a/src/pya/pya/pyaModule.cc b/src/pya/pya/pyaModule.cc index e8fbc559a..7a1e83c1d 100644 --- a/src/pya/pya/pyaModule.cc +++ b/src/pya/pya/pyaModule.cc @@ -337,7 +337,7 @@ public: for (auto cc = cls->begin_child_classes (); cc != cls->end_child_classes (); ++cc) { if (! cc->name ().empty ()) { - PyTypeObject *child_class = make_class (cc.operator-> (), as_static); + PyTypeObject *child_class = make_class (cc->declaration (), as_static); PythonRef attr ((PyObject *) child_class, false /*borrowed*/); set_type_attr (type, cc->name ().c_str (), attr); } diff --git a/src/rba/rba/rba.cc b/src/rba/rba/rba.cc index d11eca094..b3327b218 100644 --- a/src/rba/rba/rba.cc +++ b/src/rba/rba/rba.cc @@ -1654,7 +1654,7 @@ public: for (auto cc = cls->begin_child_classes (); cc != cls->end_child_classes (); ++cc) { if (! cc->name ().empty ()) { if (! is_registered (cc->declaration (), false)) { - make_class (cc->declaration (), false, klass, cc->declaration ()); + make_class (cc->declaration (), false, klass, cls); } else { VALUE child_class = ruby_cls (cc->declaration (), false); rb_define_const (klass, cc->name ().c_str (), child_class);