From 8aa92c970dd483fbf2a6d6cfa498962d7e385628 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Sun, 27 Aug 2023 18:13:19 +0200 Subject: Signature: Move all initialization into InitSignatureStrings The signature module built its own mapping for static methods. This was a post process after a module was imported. All other mappings worked from alone. Unfortunately, by lazy loading all classes of a module, the final enumeration of all functions comes too early and does no more find anything because the classes and their methods are initialized later. Move this functionality right at the end of InitSignatureStrings. This cleanup is generally a simplification and applicable for earlier versions. Task-number: PYSIDE-2404 Change-Id: Id6af49278fb8c90920eda9f9734e5231a5a2e2bd Reviewed-by: Friedemann Kleint Reviewed-by: Qt CI Bot (cherry picked from commit c0b74a7947b7f342fbf70fce8a5111094c5be0b5) Reviewed-by: Qt Cherry-pick Bot --- .../shiboken6/libshiboken/signature/signature.cpp | 6 +++--- .../libshiboken/signature/signature_helper.cpp | 24 +--------------------- sources/shiboken6/libshiboken/signature_p.h | 1 + 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/sources/shiboken6/libshiboken/signature/signature.cpp b/sources/shiboken6/libshiboken/signature/signature.cpp index 692409214..25bab87d4 100644 --- a/sources/shiboken6/libshiboken/signature/signature.cpp +++ b/sources/shiboken6/libshiboken/signature/signature.cpp @@ -428,8 +428,6 @@ static int PySide_FinishSignatures(PyObject *module, const char *signatures[]) if (PyCFunction_Check(func)) if (PyDict_SetItem(pyside_globals->map_dict, func, module) < 0) return -1; - if (_finish_nested_classes(obdict) < 0) - return -1; // The finish_import function will not work the first time since phase 2 // was not yet run. But that is ok, because the first import is always for // the shiboken module (or a test module). @@ -451,10 +449,12 @@ static int PySide_FinishSignatures(PyObject *module, const char *signatures[]) int InitSignatureStrings(PyTypeObject *type, const char *signatures[]) { + // PYSIDE-2404: This function now also builds the mapping for static methods. + // It was one missing spot to let Lazy import work. init_shibokensupport_module(); auto *ob_type = reinterpret_cast(type); int ret = PySide_BuildSignatureArgs(ob_type, signatures); - if (ret < 0) { + if (ret < 0 || _build_func_to_type(ob_type) < 0) { PyErr_Print(); PyErr_SetNone(PyExc_ImportError); } diff --git a/sources/shiboken6/libshiboken/signature/signature_helper.cpp b/sources/shiboken6/libshiboken/signature/signature_helper.cpp index e0886b85b..15ae7b844 100644 --- a/sources/shiboken6/libshiboken/signature/signature_helper.cpp +++ b/sources/shiboken6/libshiboken/signature/signature_helper.cpp @@ -293,7 +293,7 @@ PyObject *_address_to_stringlist(PyObject *numkey) return res_list; } -static int _build_func_to_type(PyObject *obtype) +int _build_func_to_type(PyObject *obtype) { /* * There is no general way to directly get the type of a static method. @@ -375,26 +375,4 @@ static int _build_func_to_type(PyObject *obtype) return 0; } -int _finish_nested_classes(PyObject *obdict) -{ - PyObject *key, *value, *obtype; - PyTypeObject *subtype; - Py_ssize_t pos = 0; - - if (obdict == nullptr) - return -1; - while (PyDict_Next(obdict, &pos, &key, &value)) { - if (PyType_Check(value)) { - obtype = value; - if (_build_func_to_type(obtype) < 0) - return -1; - // now continue with nested cases - subtype = reinterpret_cast(obtype); - if (_finish_nested_classes(subtype->tp_dict) < 0) - return -1; - } - } - return 0; -} - } // extern "C" diff --git a/sources/shiboken6/libshiboken/signature_p.h b/sources/shiboken6/libshiboken/signature_p.h index 7ea03877a..d7e38ed90 100644 --- a/sources/shiboken6/libshiboken/signature_p.h +++ b/sources/shiboken6/libshiboken/signature_p.h @@ -63,6 +63,7 @@ PyObject *_get_class_of_cf(PyObject *ob_cf); PyObject *_get_class_of_sm(PyObject *ob_sm); PyObject *_get_class_of_descr(PyObject *ob); PyObject *_address_to_stringlist(PyObject *numkey); +int _build_func_to_type(PyObject *obtype); int _finish_nested_classes(PyObject *dict); #ifdef PYPY_VERSION -- cgit v1.2.3