From 8aa9cdf783e926e9d9a5543b77a54d3a34e90782 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Fri, 1 Mar 2019 13:10:43 +0100 Subject: Fix Refcounting Bug Shown By __doc__ Handling There was a bug in the signature function 'GetClassOfFunc' since last November (sha1 2533dab013455bf94da2d4766e54abaf4d735e1e). A type was returned without Py_INCREF. That happens because types are often looked up, only, but here a normal return needed a ref. Change-Id: I3e0956b341d2b0753da2e33dd9f557b6a693098d Fixes: PYSIDE-928 Fixes: PYSIDE-937 Fixes: PYSIDE-943 Reviewed-by: Friedemann Kleint --- sources/shiboken2/libshiboken/signature.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sources') diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index 61a097771..cd00a1482 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -167,8 +167,11 @@ _get_class_of_descr(PyObject *ob) static PyObject * GetClassOfFunc(PyObject *ob) { - if (PyType_Check(ob)) + if (PyType_Check(ob)) { + // PySide-928: The type case must do refcounting like the others as well. + Py_INCREF(ob); return ob; + } if (PyType_IsSubtype(Py_TYPE(ob), &PyCFunction_Type)) return _get_class_of_cf(ob); if (Py_TYPE(ob) == PepStaticMethod_TypePtr) @@ -535,6 +538,10 @@ error: static int _fixup_getset(PyTypeObject *type, const char *name, PyGetSetDef *new_gsp) { + /* + * This function pre-fills all fields of the new gsp. We then + * insert the changed values. + */ PyGetSetDef *gsp = type->tp_getset; if (gsp != nullptr) { for (; gsp->name != NULL; gsp++) { @@ -542,7 +549,7 @@ _fixup_getset(PyTypeObject *type, const char *name, PyGetSetDef *new_gsp) new_gsp->set = gsp->set; new_gsp->doc = gsp->doc; new_gsp->closure = gsp->closure; - return 1; + return 1; // success } } } -- cgit v1.2.3