diff options
author | Christian Tismer <tismer@stackless.com> | 2023-02-07 13:07:51 +0100 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2023-02-08 14:02:02 +0100 |
commit | 53dbaf2f87c8f39851bb81e7ebaf66dbcf3f5581 (patch) | |
tree | 4c0899fd06db7566c23ff78ec4d224784af96e6a /sources/shiboken6 | |
parent | bf73772d2c43a71d13a55e9914c631591cd01815 (diff) |
shiboken: Simplify sys module attribute lookup
Task-number: PYSIDE-2221
Change-Id: Ia748ab4da2907ee0d6e1120e0371d523b19d4c5a
Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/shiboken6')
4 files changed, 6 insertions, 15 deletions
diff --git a/sources/shiboken6/libshiboken/pep384_issue33738.cpp b/sources/shiboken6/libshiboken/pep384_issue33738.cpp index 7f3872a58..d91b595e8 100644 --- a/sources/shiboken6/libshiboken/pep384_issue33738.cpp +++ b/sources/shiboken6/libshiboken/pep384_issue33738.cpp @@ -79,9 +79,7 @@ typedef struct _oldtypeobject { static bool is_compatible_version() { - auto *sysmodule = PyImport_AddModule("sys"); - auto *dic = PyModule_GetDict(sysmodule); - auto *version = PyDict_GetItemString(dic, "version_info"); + auto *version = PySys_GetObject("version_info"); auto *major = PyTuple_GetItem(version, 0); auto *minor = PyTuple_GetItem(version, 1); auto number = PyLong_AsLong(major) * 1000 + PyLong_AsLong(minor); diff --git a/sources/shiboken6/libshiboken/sbkenum.cpp b/sources/shiboken6/libshiboken/sbkenum.cpp index 91333a721..9b416886f 100644 --- a/sources/shiboken6/libshiboken/sbkenum.cpp +++ b/sources/shiboken6/libshiboken/sbkenum.cpp @@ -441,8 +441,7 @@ void init_enum() Py_AtExit(cleanupEnumTypes); // PYSIDE-1735: Determine whether we should use the old or the new enum implementation. - static PyObject *sysmodule = PyImport_AddModule("sys"); - static PyObject *option = PyObject_GetAttrString(sysmodule, "pyside63_option_python_enum"); + static PyObject *option = PySys_GetObject("pyside63_option_python_enum"); if (!option || !PyLong_Check(option)) { PyErr_Clear(); option = PyLong_FromLong(0); @@ -973,9 +972,7 @@ static PyTypeObject *recordCurrentEnum(PyObject *scopeOrModule, static bool is_old_version() { - auto *sysmodule = PyImport_AddModule("sys"); - auto *dic = PyModule_GetDict(sysmodule); - auto *version = PyDict_GetItemString(dic, "version_info"); + auto *version = PySys_GetObject("version_info"); auto *major = PyTuple_GetItem(version, 0); auto *minor = PyTuple_GetItem(version, 1); auto number = PyLong_AsLong(major) * 1000 + PyLong_AsLong(minor); diff --git a/sources/shiboken6/libshiboken/sbkfeature_base.cpp b/sources/shiboken6/libshiboken/sbkfeature_base.cpp index 2931a8abd..82d4ad6d3 100644 --- a/sources/shiboken6/libshiboken/sbkfeature_base.cpp +++ b/sources/shiboken6/libshiboken/sbkfeature_base.cpp @@ -60,8 +60,7 @@ void disassembleFrame(const char *marker) fprintf(stdout, "\n%s BEGIN\n", marker); PyObject_CallFunctionObjArgs(disco, f_code.object(), f_lasti.object(), nullptr); fprintf(stdout, "%s END\n\n", marker); - static PyObject *sysmodule = PyImport_ImportModule("sys"); - static PyObject *stdout_file = PyObject_GetAttrString(sysmodule, "stdout"); + static PyObject *stdout_file = PySys_GetObject("stdout"); PyObject_CallMethod(stdout_file, "flush", nullptr); PyErr_Restore(error_type, error_value, error_traceback); } @@ -80,8 +79,7 @@ static int const LOAD_ATTR = 106; static int _getVersion() { - static PyObject *const sysmodule = PyImport_AddModule("sys"); - static PyObject *const version = PyObject_GetAttrString(sysmodule, "version_info"); + static PyObject *const version = PySys_GetObject("version_info"); static PyObject *const major = PyTuple_GetItem(version, 0); static PyObject *const minor = PyTuple_GetItem(version, 1); static auto number = PyLong_AsLong(major) * 1000 + PyLong_AsLong(minor); diff --git a/sources/shiboken6/libshiboken/signature/signature.cpp b/sources/shiboken6/libshiboken/signature/signature.cpp index 9b476520f..dee5008de 100644 --- a/sources/shiboken6/libshiboken/signature/signature.cpp +++ b/sources/shiboken6/libshiboken/signature/signature.cpp @@ -387,9 +387,7 @@ PyObject *PySide_BuildSignatureProps(PyObject *type_key) #ifdef PYPY_VERSION static bool get_lldebug_flag() { - PyObject *sysmodule = PyImport_AddModule("sys"); - auto *dic = PyModule_GetDict(sysmodule); - dic = PyDict_GetItemString(dic, "pypy_translation_info"); + auto *dic = PySys_GetObject("pypy_translation_info"); int lldebug = PyObject_IsTrue(PyDict_GetItemString(dic, "translation.lldebug")); int lldebug0 = PyObject_IsTrue(PyDict_GetItemString(dic, "translation.lldebug0")); return lldebug || lldebug0; |