summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-02-19 21:47:02 (GMT)
committerGeorg Brandl <georg@python.org>2011-02-19 21:47:02 (GMT)
commit032400b2d83ba1c2e4ee1cd33f51e9a598b2cf6c (patch)
tree24056a6b70587d6d6148955f188b159532092a46 /Objects
parente0e824d2ed10fc99b7ed7a2eb19fe95bedcdbc8e (diff)
downloadcpython-032400b2d83ba1c2e4ee1cd33f51e9a598b2cf6c.zip
cpython-032400b2d83ba1c2e4ee1cd33f51e9a598b2cf6c.tar.gz
cpython-032400b2d83ba1c2e4ee1cd33f51e9a598b2cf6c.tar.bz2
#11249: in PyType_FromSpec, copy tp_doc slot since it usually will point to a static string literal which should not be deallocated together with the type.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index e9c7591..b1fe44e 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2347,6 +2347,17 @@ PyObject* PyType_FromSpec(PyType_Spec *spec)
goto fail;
}
*(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc;
+
+ /* need to make a copy of the docstring slot, which usually
+ points to a static string literal */
+ if (slot->slot == Py_tp_doc) {
+ ssize_t len = strlen(slot->pfunc)+1;
+ char *tp_doc = PyObject_MALLOC(len);
+ if (tp_doc == NULL)
+ goto fail;
+ memcpy(tp_doc, slot->pfunc, len);
+ res->ht_type.tp_doc = tp_doc;
+ }
}
return (PyObject*)res;