55#include " basewrapper.h"
66#include " pysidestaticstrings.h"
77#include " class_property.h"
8+ #include " pysideglobals_p.h"
89
910#include < autodecref.h>
1011#include < sbkfeature_base.h>
@@ -119,15 +120,17 @@ createDerivedDictType()
119120 return reinterpret_cast <PyTypeObject *>(ChameleonDict);
120121}
121122
122- static PyTypeObject *new_dict_type = nullptr ;
123-
124- static void ensureNewDictType ()
123+ static PyTypeObject *ensureNewDictType ()
125124{
126- if (new_dict_type == nullptr ) {
127- new_dict_type = createDerivedDictType ();
128- if (new_dict_type == nullptr )
125+ auto *globals = PySide::globals ();
126+ if (globals->newFeatureDictType == nullptr ) {
127+ globals->newFeatureDictType = createDerivedDictType ();
128+ if (globals->newFeatureDictType == nullptr ) {
129+ PyErr_Print ();
129130 Py_FatalError (" libshiboken: Problem creating ChameleonDict" );
131+ }
130132 }
133+ return globals->newFeatureDictType ;
131134}
132135
133136static inline PyObject *nextInCircle (PyObject *dict)
@@ -165,9 +168,8 @@ static bool replaceClassDict(PyTypeObject *type)
165168 * Replace the type dict by the derived ChameleonDict.
166169 * This is mandatory for all type dicts when they are touched.
167170 */
168- ensureNewDictType ();
171+ auto *ob_ndt = reinterpret_cast <PyObject *>( ensureNewDictType () );
169172 AutoDecRef dict (PepType_GetDict (type));
170- auto *ob_ndt = reinterpret_cast <PyObject *>(new_dict_type);
171173 auto *new_dict = PyObject_CallObject (ob_ndt, nullptr );
172174 if (new_dict == nullptr || PyDict_Update (new_dict, dict) < 0 )
173175 return false ;
@@ -190,7 +192,7 @@ static bool addNewDict(PyTypeObject *type, int select_id)
190192 */
191193 AutoDecRef dict (PepType_GetDict (type));
192194 AutoDecRef orig_dict (PyObject_GetAttr (dict, PySideName::orig_dict ()));
193- auto *ob_ndt = reinterpret_cast <PyObject *>(new_dict_type );
195+ auto *ob_ndt = reinterpret_cast <PyObject *>(ensureNewDictType () );
194196 auto *new_dict = PyObject_CallObject (ob_ndt, nullptr );
195197 if (new_dict == nullptr )
196198 return false ;
@@ -293,13 +295,16 @@ static inline void SelectFeatureSetSubtype(PyTypeObject *type, int select_id)
293295 }
294296 }
295297
296- static PyObject *cached_globals{};
297- static int last_select_id{};
298-
299298static inline int getFeatureSelectId ()
300299{
301300 static auto *undef = PyLong_FromLong (-1 );
302- static auto *feature_dict = GetFeatureDict ();
301+
302+ auto *libGlobals = PySide::globals ();
303+ PyObject *&feature_dict = PySide::globals ()->featureDict ;
304+ if (feature_dict == nullptr )
305+ feature_dict = GetFeatureDict ();
306+ PyObject *&cached_globals = libGlobals->cachedFeatureGlobals ;
307+ int &last_select_id = libGlobals->lastSelectedFeatureId ;
303308
304309 Shiboken::AutoDecRef globals (PepEval_GetFrameGlobals ());
305310 if (globals.isNull () || globals.object () == cached_globals)
@@ -342,7 +347,7 @@ static inline void SelectFeatureSet(PyTypeObject *type)
342347
343348 int select_id = getFeatureSelectId ();
344349 static int last_select_id{};
345- static PyTypeObject *last_type{} ;
350+ PyTypeObject *& last_type = PySide::globals ()-> lastFeatureType ;
346351
347352 // PYSIDE-2029: Implement a very simple but effective cache that cannot fail.
348353 if (type == last_type && select_id == last_select_id)
@@ -415,9 +420,11 @@ void init()
415420 patch_property_impl ();
416421 is_initialized = true ;
417422 }
418- last_select_id = 0 ;
423+
419424 // Reset the cache. This is called at any "from __feature__ import".
420- cached_globals = nullptr ;
425+ auto *globals = PySide::globals ();
426+ globals->lastSelectedFeatureId = 0 ;
427+ globals->cachedFeatureGlobals = nullptr ;
421428}
422429
423430void Enable (bool enable)
0 commit comments