aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2023-06-15 15:50:31 +0200
committerChristian Tismer <tismer@stackless.com>2023-06-21 11:37:58 +0200
commit889949f49fd7727a41b884ccd21202f9d8ce854d (patch)
treefe61e94faa85aa09ac0f5e4d712f7822debb5e14
parent9e1ef5febe2ba7bbd53967e73b88bb28422134aa (diff)
shiboken: Fix an old enum aliasing error that was never found
While removing the old enums, an unsolved problem was solved, which had a heuristic workaround before. A special case needed to be excluded in cppgenerator where an Anonymous Enum was causing a problem in morphLastEnumToPython. Task-number: PYSIDE-1735 Change-Id: Ibd0b8a6194a0005bc49800c12ab5d2626ccf4d8f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 2b75519adf23ba490e32659ca337b48e7ae4ec41) Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp11
-rw-r--r--sources/shiboken6/libshiboken/sbkenum.cpp14
-rw-r--r--sources/shiboken6/libshiboken/sbkenum_p.h1
3 files changed, 8 insertions, 18 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 16044df24..38e37c272 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -5793,9 +5793,14 @@ void CppGenerator::writeEnumInitialization(TextStream &s, const AbstractMetaEnum
break;
}
}
- s << "// PYSIDE-1735: Resolving the whole enum class at the end for API compatibility.\n"
- << "EType = morphLastEnumToPython();\n"
- << enumVarTypeObj << " = EType;\n";
+ if (cppEnum.enumKind() != AnonymousEnum) {
+ s << "// PYSIDE-1735: Resolving the whole enum class at the end for API compatibility.\n"
+ << "EType = morphLastEnumToPython();\n"
+ << enumVarTypeObj << " = EType;\n";
+ } else {
+ s << "// PYSIDE-1735: Skip an Anonymous enum class for Python coercion.\n"
+ << enumVarTypeObj << " = EType;\n";
+ }
if (cppEnum.typeEntry()->flags()) {
s << "// PYSIDE-1735: Mapping the flags class to the same enum class.\n"
<< cpythonTypeNameExt(cppEnum.typeEntry()->flags()) << " =\n"
diff --git a/sources/shiboken6/libshiboken/sbkenum.cpp b/sources/shiboken6/libshiboken/sbkenum.cpp
index 212e6fb73..2cc0b935e 100644
--- a/sources/shiboken6/libshiboken/sbkenum.cpp
+++ b/sources/shiboken6/libshiboken/sbkenum.cpp
@@ -1084,17 +1084,6 @@ PyTypeObject *morphLastEnumToPython()
auto *enumType = lec.enumType;
// This is temporary; SbkEnumType will be removed, soon.
- // PYSIDE-1735: Decide dynamically if new or old enums will be used.
- if (useOldEnum)
- return enumType;
-
- auto *setp = PepType_SETP(reinterpret_cast<SbkEnumType *>(enumType));
- if (setp->replacementType) {
- // For some (yet to fix) reason, initialization of the enums can happen twice.
- // If that happens, use the existing new type to keep type checks correct.
- return setp->replacementType;
- }
-
auto *scopeOrModule = lec.scopeOrModule;
static PyObject *enumName = String::createStaticString("IntEnum");
if (PyType_Check(scopeOrModule)) {
@@ -1180,9 +1169,6 @@ PyTypeObject *morphLastEnumToPython()
}
}
- // Protect against double initialization
- setp->replacementType = newType;
-
// PYSIDE-1735: Old Python versions can't stand the early enum deallocation.
static bool old_python_version = is_old_version();
if (old_python_version)
diff --git a/sources/shiboken6/libshiboken/sbkenum_p.h b/sources/shiboken6/libshiboken/sbkenum_p.h
index d8477b4b3..004f4125f 100644
--- a/sources/shiboken6/libshiboken/sbkenum_p.h
+++ b/sources/shiboken6/libshiboken/sbkenum_p.h
@@ -11,7 +11,6 @@ struct SbkEnumTypePrivate
{
SbkConverter *converter;
const char *cppName;
- PyTypeObject *replacementType;
};
extern "C" {