diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-06-27 11:35:09 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-06-27 11:53:50 +0200 |
commit | 71d97ff54ba2ea225d4fb215b3dbbf7feeab489a (patch) | |
tree | d7284b86d7eae07826d79076cc2c99697fc66cad /sources | |
parent | a09a1db8391243e6bb290ee66bb6e3afbb114c61 (diff) |
libshiboken: Remove old code paths for static strings
PyUnicode_InternFromString() should be used unconditionally.
Amends a09a1db8391243e6bb290ee66bb6e3afbb114c61.
Task-number: PYSIDE-1960
Pick-to: 6.3 6.2
Change-Id: I80837b2b58c9eadbd2aca4279df10e2f03e30450
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources')
-rw-r--r-- | sources/shiboken6/libshiboken/sbkstring.cpp | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/sources/shiboken6/libshiboken/sbkstring.cpp b/sources/shiboken6/libshiboken/sbkstring.cpp index 36fe50369..8f2dc6d52 100644 --- a/sources/shiboken6/libshiboken/sbkstring.cpp +++ b/sources/shiboken6/libshiboken/sbkstring.cpp @@ -5,15 +5,6 @@ #include "sbkstaticstrings_p.h" #include "autodecref.h" -#if PY_VERSION_HEX >= 0x030B0000 || defined(Py_LIMITED_API) -# define USE_INTERN_STRINGS -#endif - -#ifndef USE_INTERN_STRINGS -# include <vector> -# include <unordered_set> -#endif - namespace Shiboken::String { @@ -185,60 +176,10 @@ Py_ssize_t len(PyObject *str) // PyObject *attr = PyObject_GetAttr(obj, name()); // -#ifdef USE_INTERN_STRINGS PyObject *createStaticString(const char *str) { return PyUnicode_InternFromString(str); } -#else - -using StaticStrings = std::unordered_set<PyObject *>; - -static void finalizeStaticStrings(); // forward - -static StaticStrings &staticStrings() -{ - static StaticStrings result; - return result; -} - -static void finalizeStaticStrings() -{ - auto &set = staticStrings(); - for (PyObject *ob : set) { - Py_SET_REFCNT(ob, 1); - Py_DECREF(ob); - } - set.clear(); -} - -PyObject *createStaticString(const char *str) -{ - static bool initialized = false; - if (!initialized) { - Py_AtExit(finalizeStaticStrings); - initialized = true; - } - PyObject *result = PyUnicode_InternFromString(str); - if (result == nullptr) { - // This error is never checked, but also very unlikely. Report and exit. - PyErr_Print(); - Py_FatalError("unexpected error in createStaticString()"); - } - auto it = staticStrings().find(result); - if (it == staticStrings().end()) - staticStrings().insert(result); - /* - * Note: We always add one reference even if we have a new string. - * This makes the strings immortal, and we are safe if someone - * uses AutoDecRef, although the set cannot cope with deletions. - * The exit handler cleans that up, anyway. - */ - Py_INCREF(result); - return result; -} - -#endif // !USE_INTERN_STRINGS /////////////////////////////////////////////////////////////////////// // |