Mercurial > cpython-lru_cache-weakref
diff Objects/typeobject.c @ 67962:788eafaef7dc
#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.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sat, 19 Feb 2011 21:47:02 +0000 |
| parents | aca91c55f38d |
| children | 7b011cf64f90 |
line wrap: on
line diff
--- a/Objects/typeobject.c Sat Feb 19 18:46:02 2011 +0000 +++ b/Objects/typeobject.c Sat Feb 19 21:47:02 2011 +0000 @@ -2347,6 +2347,17 @@ 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;
