diff options
author | Christian Tismer <tismer@stackless.com> | 2022-01-17 13:20:46 +0100 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2022-02-03 18:18:04 +0100 |
commit | 5a487a6f9f9861fc14458c770e61c66a63019184 (patch) | |
tree | 9af8ca3015ae585905a14bb5597f6309472c7b63 /sources/shiboken6 | |
parent | ac1dbba1798bc72cf4e71142ec6f647b8b6ae25d (diff) |
PyPySide: Rename interface functions and classes to simplify debugging
The names of certain interface functions are not always
following a simple scheme. Especially it is not easy
to see immediately if we are dealing with a method
of SbkObjectType or SbkObject
Do a few renamings to simplify debugging and make the code
easier to understand. When a function is used in a type spec
and there is no other important reason, it should be named
like
{Py_<tpname>: reinterpret_cast<void *>(<TypeName>_<tpname>)},
Rename also all type functions ending on "TypeF()" to end
in "_TypeF()". This is not always the case.
Examples:
SbkObjectTpNew -> SbkObject_tp_new
SbkObjecttypeTpNew -> SbkObjectType_tp_new
PyClassPropertyTypeF -> PyClassProperty_TypeF
Task-number: PYSIDE-535
Change-Id: Icbd118852f2ee732b55d944ed57c7a8ef7d26139
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 8 | ||||
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator_container.cpp | 2 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.cpp | 34 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.h | 4 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/voidptr.cpp | 24 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/voidptr.h | 2 |
6 files changed, 37 insertions, 37 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 09ce927e9..b861ab9d7 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -4363,12 +4363,12 @@ void CppGenerator::writeClassDefinition(TextStream &s, // This is not generally possible, because PySide does not care about // privacy the same way. This worked before the heap types were used, // because inheritance is not really checked for static types. - // Instead, we check this at runtime, see SbkObjectTypeTpNew. + // Instead, we check this at runtime, see SbkObjectType_tp_new. if (metaClass->fullName().startsWith(QLatin1String("PySide6.Qt"))) { // PYSIDE-595: No idea how to do non-inheritance correctly. // Since that is only relevant in shiboken, I used a shortcut for // PySide. - tp_new = QLatin1String("SbkObjectTpNew"); + tp_new = u"SbkObject_tp_new"_qs; } else { tp_new = QLatin1String("SbkDummyNew /* PYSIDE-595: Prevent replacement " @@ -4376,10 +4376,10 @@ void CppGenerator::writeClassDefinition(TextStream &s, } } else if (isQApp) { - tp_new = QLatin1String("SbkQAppTpNew"); // PYSIDE-571: need singleton app + tp_new = u"SbkQApp_tp_new"_qs; // PYSIDE-571: need singleton app } else { - tp_new = QLatin1String("SbkObjectTpNew"); + tp_new = u"SbkObject_tp_new"_qs; } tp_flags.append(QLatin1String("|Py_TPFLAGS_HAVE_GC")); diff --git a/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp b/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp index 4bb3386dd..748644e22 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp @@ -212,7 +212,7 @@ CppGenerator::OpaqueContainerData "Shiboken::PyMagicName::opaque_container(), Py_True);\n" << "return result;\n" << outdent << "}\n\n"; - // typeF() function + // _TypeF() function const QString typeFName = result.name + u"_TypeF"_qs; s << "static PyTypeObject *" << typeFName << "()\n{\n" << indent << "static PyTypeObject *type = " << typeCreationFName diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index 0730e9dad..46d650800 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -92,8 +92,8 @@ void Sbk_object_dealloc(PyObject *self) Py_TYPE(self)->tp_free(self); } -static void SbkObjectTypeDealloc(PyTypeObject *pyType); -static PyTypeObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds); +static void SbkObjectType_tp_dealloc(PyTypeObject *pyType); +static PyTypeObject *SbkObjectType_tp_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds); static DestroyQAppHook DestroyQApplication = nullptr; @@ -147,7 +147,7 @@ type_set_doc(PyTypeObject *type, PyObject *value, void *context) // PYSIDE-908: The function PyType_Modified does not work in PySide, so we need to // explicitly pass __doc__. For __signature__ it _did_ actually work, because // it was not existing before. We add them both for clarity. -static PyGetSetDef SbkObjectType_Type_getsetlist[] = { +static PyGetSetDef SbkObjectType_tp_getset[] = { {const_cast<char *>("__signature__"), reinterpret_cast<getter>(Sbk_TypeGet___signature__), nullptr, nullptr, nullptr}, {const_cast<char *>("__doc__"), reinterpret_cast<getter>(Sbk_TypeGet___doc__), @@ -158,13 +158,13 @@ static PyGetSetDef SbkObjectType_Type_getsetlist[] = { }; static PyType_Slot SbkObjectType_Type_slots[] = { - {Py_tp_dealloc, reinterpret_cast<void *>(SbkObjectTypeDealloc)}, + {Py_tp_dealloc, reinterpret_cast<void *>(SbkObjectType_tp_dealloc)}, {Py_tp_getattro, reinterpret_cast<void *>(mangled_type_getattro)}, {Py_tp_base, static_cast<void *>(&PyType_Type)}, {Py_tp_alloc, reinterpret_cast<void *>(PyType_GenericAlloc)}, - {Py_tp_new, reinterpret_cast<void *>(SbkObjectTypeTpNew)}, + {Py_tp_new, reinterpret_cast<void *>(SbkObjectType_tp_new)}, {Py_tp_free, reinterpret_cast<void *>(PyObject_GC_Del)}, - {Py_tp_getset, reinterpret_cast<void *>(SbkObjectType_Type_getsetlist)}, + {Py_tp_getset, reinterpret_cast<void *>(SbkObjectType_tp_getset)}, {0, nullptr} }; @@ -192,12 +192,12 @@ static PyObject *SbkObjectGetDict(PyObject *pObj, void *) return ret; } -static PyGetSetDef SbkObjectGetSetList[] = { +static PyGetSetDef SbkObject_tp_getset[] = { {const_cast<char *>("__dict__"), SbkObjectGetDict, nullptr, nullptr, nullptr}, {nullptr, nullptr, nullptr, nullptr, nullptr} // Sentinel }; -static int SbkObject_traverse(PyObject *self, visitproc visit, void *arg) +static int SbkObject_tp_traverse(PyObject *self, visitproc visit, void *arg) { auto *sbkSelf = reinterpret_cast<SbkObject *>(self); @@ -225,7 +225,7 @@ static int SbkObject_traverse(PyObject *self, visitproc visit, void *arg) return 0; } -static int SbkObject_clear(PyObject *self) +static int SbkObject_tp_clear(PyObject *self) { auto *sbkSelf = reinterpret_cast<SbkObject *>(self); @@ -245,10 +245,10 @@ static PyType_Slot SbkObject_Type_slots[] = { {Py_tp_getattro, reinterpret_cast<void *>(SbkObject_GenericGetAttr)}, {Py_tp_setattro, reinterpret_cast<void *>(SbkObject_GenericSetAttr)}, {Py_tp_dealloc, reinterpret_cast<void *>(SbkDeallocWrapperWithPrivateDtor)}, - {Py_tp_traverse, reinterpret_cast<void *>(SbkObject_traverse)}, - {Py_tp_clear, reinterpret_cast<void *>(SbkObject_clear)}, + {Py_tp_traverse, reinterpret_cast<void *>(SbkObject_tp_traverse)}, + {Py_tp_clear, reinterpret_cast<void *>(SbkObject_tp_clear)}, // unsupported: {Py_tp_weaklistoffset, (void *)offsetof(SbkObject, weakreflist)}, - {Py_tp_getset, reinterpret_cast<void *>(SbkObjectGetSetList)}, + {Py_tp_getset, reinterpret_cast<void *>(SbkObject_tp_getset)}, // unsupported: {Py_tp_dictoffset, (void *)offsetof(SbkObject, ob_dict)}, {0, nullptr} }; @@ -403,7 +403,7 @@ void SbkDeallocWrapperWithPrivateDtor(PyObject *self) SbkDeallocWrapperCommon(self, false); } -void SbkObjectTypeDealloc(PyTypeObject *sbkType) +void SbkObjectType_tp_dealloc(PyTypeObject *sbkType) { SbkObjectTypePrivate *sotp = PepType_SOTP(sbkType); auto pyObj = reinterpret_cast<PyObject *>(sbkType); @@ -475,7 +475,7 @@ PyObject *MakeQAppWrapper(PyTypeObject *type) return qApp_curr; } -static PyTypeObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds) +static PyTypeObject *SbkObjectType_tp_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) { // Check if all bases are new style before calling type.tp_new // Was causing gc assert errors in test_bug704.py when @@ -590,13 +590,13 @@ static PyObject *_setupNew(SbkObject *self, PyTypeObject *subtype) return obSelf; } -PyObject *SbkObjectTpNew(PyTypeObject *subtype, PyObject *, PyObject *) +PyObject *SbkObject_tp_new(PyTypeObject *subtype, PyObject *, PyObject *) { SbkObject *self = PyObject_GC_New(SbkObject, subtype); return _setupNew(self, subtype); } -PyObject *SbkQAppTpNew(PyTypeObject *subtype, PyObject *, PyObject *) +PyObject *SbkQApp_tp_new(PyTypeObject *subtype, PyObject *, PyObject *) { auto self = reinterpret_cast<SbkObject *>(MakeQAppWrapper(subtype)); if (self == nullptr) @@ -1373,7 +1373,7 @@ PyObject *newObject(PyTypeObject *instanceType, } if (shouldCreate) { - self = reinterpret_cast<SbkObject *>(SbkObjectTpNew(instanceType, nullptr, nullptr)); + self = reinterpret_cast<SbkObject *>(SbkObject_tp_new(instanceType, nullptr, nullptr)); self->d->cptr[0] = cptr; self->d->hasOwnership = hasOwnership; self->d->validCppObject = 1; diff --git a/sources/shiboken6/libshiboken/basewrapper.h b/sources/shiboken6/libshiboken/basewrapper.h index 85556ec61..3126557c0 100644 --- a/sources/shiboken6/libshiboken/basewrapper.h +++ b/sources/shiboken6/libshiboken/basewrapper.h @@ -122,10 +122,10 @@ extern LIBSHIBOKEN_API PyTypeObject *SbkObject_TypeF(void); struct SbkObjectTypePrivate; /// PyTypeObject extended with C++ multiple inheritance information. -LIBSHIBOKEN_API PyObject *SbkObjectTpNew(PyTypeObject *subtype, PyObject *, PyObject *); +LIBSHIBOKEN_API PyObject *SbkObject_tp_new(PyTypeObject *subtype, PyObject *, PyObject *); /// The special case of a switchable singleton Q*Application. -LIBSHIBOKEN_API PyObject *SbkQAppTpNew(PyTypeObject *subtype, PyObject *, PyObject *); +LIBSHIBOKEN_API PyObject *SbkQApp_tp_new(PyTypeObject *subtype, PyObject *, PyObject *); /// Create a new Q*Application wrapper and monitor it. LIBSHIBOKEN_API PyObject *MakeQAppWrapper(PyTypeObject *type); diff --git a/sources/shiboken6/libshiboken/voidptr.cpp b/sources/shiboken6/libshiboken/voidptr.cpp index f0161d282..e2cd4f4ee 100644 --- a/sources/shiboken6/libshiboken/voidptr.cpp +++ b/sources/shiboken6/libshiboken/voidptr.cpp @@ -72,7 +72,7 @@ PyObject *SbkVoidPtrObject_new(PyTypeObject *type, PyObject *args, PyObject *kwd return reinterpret_cast<PyObject *>(self); } -#define SbkVoidPtr_Check(op) (Py_TYPE(op) == SbkVoidPtrTypeF()) +#define SbkVoidPtr_Check(op) (Py_TYPE(op) == SbkVoidPtr_TypeF()) int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) @@ -316,7 +316,7 @@ static PyType_Spec SbkVoidPtrType_spec = { } -PyTypeObject *SbkVoidPtrTypeF(void) +PyTypeObject *SbkVoidPtr_TypeF(void) { static PyTypeObject *type = SbkType_FromSpec_BMDWB(&SbkVoidPtrType_spec, nullptr, nullptr, 0, 0, @@ -330,7 +330,7 @@ static int voidPointerInitialized = false; void init() { - if (PyType_Ready(SbkVoidPtrTypeF()) < 0) + if (PyType_Ready(SbkVoidPtr_TypeF()) < 0) Py_FatalError("[libshiboken] Failed to initialize Shiboken.VoidPtr type."); else voidPointerInitialized = true; @@ -339,9 +339,9 @@ void init() void addVoidPtrToModule(PyObject *module) { if (voidPointerInitialized) { - Py_INCREF(SbkVoidPtrTypeF()); - PyModule_AddObject(module, PepType_GetNameStr(SbkVoidPtrTypeF()), - reinterpret_cast<PyObject *>(SbkVoidPtrTypeF())); + Py_INCREF(SbkVoidPtr_TypeF()); + PyModule_AddObject(module, PepType_GetNameStr(SbkVoidPtr_TypeF()), + reinterpret_cast<PyObject *>(SbkVoidPtr_TypeF())); } } @@ -350,7 +350,7 @@ static PyObject *createVoidPtr(void *cppIn, Py_ssize_t size = 0, bool isWritable if (!cppIn) Py_RETURN_NONE; - SbkVoidPtrObject *result = PyObject_New(SbkVoidPtrObject, SbkVoidPtrTypeF()); + SbkVoidPtrObject *result = PyObject_New(SbkVoidPtrObject, SbkVoidPtr_TypeF()); if (!result) Py_RETURN_NONE; @@ -423,7 +423,7 @@ static PythonToCppFunc PythonBufferToCppIsConvertible(PyObject *pyIn) SbkConverter *createConverter() { - SbkConverter *converter = Shiboken::Conversions::createConverter(SbkVoidPtrTypeF(), toPython); + SbkConverter *converter = Shiboken::Conversions::createConverter(SbkVoidPtr_TypeF(), toPython); Shiboken::Conversions::addPythonToCppValueConversion(converter, VoidPtrToCpp, VoidPtrToCppIsConvertible); @@ -438,28 +438,28 @@ SbkConverter *createConverter() void setSize(PyObject *voidPtr, Py_ssize_t size) { - assert(voidPtr->ob_type == SbkVoidPtrTypeF()); + assert(voidPtr->ob_type == SbkVoidPtr_TypeF()); auto *voidPtrObj = reinterpret_cast<SbkVoidPtrObject *>(voidPtr); voidPtrObj->size = size; } Py_ssize_t getSize(PyObject *voidPtr) { - assert(voidPtr->ob_type == SbkVoidPtrTypeF()); + assert(voidPtr->ob_type == SbkVoidPtr_TypeF()); auto *voidPtrObj = reinterpret_cast<SbkVoidPtrObject *>(voidPtr); return voidPtrObj->size; } bool isWritable(PyObject *voidPtr) { - assert(voidPtr->ob_type == SbkVoidPtrTypeF()); + assert(voidPtr->ob_type == SbkVoidPtr_TypeF()); auto *voidPtrObj = reinterpret_cast<SbkVoidPtrObject *>(voidPtr); return voidPtrObj->isWritable; } void setWritable(PyObject *voidPtr, bool isWritable) { - assert(voidPtr->ob_type == SbkVoidPtrTypeF()); + assert(voidPtr->ob_type == SbkVoidPtr_TypeF()); auto *voidPtrObj = reinterpret_cast<SbkVoidPtrObject *>(voidPtr); voidPtrObj->isWritable = isWritable; } diff --git a/sources/shiboken6/libshiboken/voidptr.h b/sources/shiboken6/libshiboken/voidptr.h index 018f6124e..55a2463ce 100644 --- a/sources/shiboken6/libshiboken/voidptr.h +++ b/sources/shiboken6/libshiboken/voidptr.h @@ -48,7 +48,7 @@ extern "C" { // Void pointer type declaration. -extern LIBSHIBOKEN_API PyTypeObject *SbkVoidPtrTypeF(void); +extern LIBSHIBOKEN_API PyTypeObject *SbkVoidPtr_TypeF(void); } // extern "C" |