diff options
author | Christian Tismer <tismer@stackless.com> | 2021-04-18 18:58:18 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2021-12-03 10:12:21 +0100 |
commit | e85db57ecf9e998206eefe93433ee58c6f8c1f47 (patch) | |
tree | 2cf89e0b03b87500f96ee4e4690b89cacd7c5737 /sources/shiboken6/generator/shiboken/cppgenerator.cpp | |
parent | 79ec52558acc48b0c368738bf1fcc5195921cafb (diff) |
PyPySide: Avoid direct access to `op->ob_dict` in PyPy
PyPy treats `op->ob_dict` specially. When you use PyObject_SetAttr
and look later for the attribute in the object's dict, you cannot
find it. PySide uses direct access to `ob_dict` which has this side
effect and was a major obstacle until the PyPy people explained the
undocumented behavior.
We either need to use a different attribute name than "ob_dict", or use
the C API for dict access. The second, simpler solution turned out to be
sufficient. Since the used function is in the Stable ABI in version
Python 3.10 only, we implemented a replacement function in basewrapper.
This change was crucial and led to the first public version.
[ChangeLog][shiboken6] PyPySide: Direct access to `op->ob_dict` needed
to be avoided in PyPy. This important change took the project far
enough to publish it as a preview and to produce wheels.
Task-number: PYSIDE-535
Change-Id: I09c59e7ebf78837868912cfd19330256eea71237
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index eb48b1b10..f5d677bc6 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -6103,16 +6103,12 @@ void CppGenerator::writeGetattroFunction(TextStream &s, AttroCheck attroCheck, if (attroCheck.testFlag(AttroCheckFlag::GetattroOverloads)) { s << "// Search the method in the instance dict\n" - << "if (auto ob_dict = reinterpret_cast<SbkObject *>(self)->ob_dict) {\n"; + << "auto ob_dict = SbkObject_GetDict(self);\n"; + s << "if (auto meth = PyDict_GetItem(ob_dict, name)) {\n"; { Indentation indent(s); - s << "if (auto meth = PyDict_GetItem(ob_dict, name)) {\n"; - { - Indentation indent(s); - s << "Py_INCREF(meth);\n" - << "return meth;\n"; - } - s << "}\n"; + s << "Py_INCREF(meth);\n" + << "return meth;\n"; } s << "}\n" << "// Search the method in the type dict\n" |