summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2020-09-02 16:29:06 (GMT)
committerGitHub <noreply@github.com>2020-09-02 16:29:06 (GMT)
commit3940333637b98a2781869977b077552514784529 (patch)
tree3b2c264f2acccc540076922a08d7e45e477ad4b1 /Objects
parent5a4a963a6c798fa9207a9998618a9c0ec3b6b6d7 (diff)
downloadcpython-3940333637b98a2781869977b077552514784529.zip
cpython-3940333637b98a2781869977b077552514784529.tar.gz
cpython-3940333637b98a2781869977b077552514784529.tar.bz2
closes bpo-41689: Preserve text signature from tp_doc in C heap type creation. (GH-22058)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index c66f8fc..7404075 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -3018,15 +3018,14 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
else if (slot->slot == Py_tp_doc) {
/* For the docstring slot, which usually points to a static string
literal, we need to make a copy */
- const char *old_doc = _PyType_DocWithoutSignature(type->tp_name, slot->pfunc);
- size_t len = strlen(old_doc)+1;
+ size_t len = strlen(slot->pfunc)+1;
char *tp_doc = PyObject_MALLOC(len);
if (tp_doc == NULL) {
type->tp_doc = NULL;
PyErr_NoMemory();
goto fail;
}
- memcpy(tp_doc, old_doc, len);
+ memcpy(tp_doc, slot->pfunc, len);
type->tp_doc = tp_doc;
}
else if (slot->slot == Py_tp_members) {
@@ -3058,6 +3057,16 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
res->ht_cached_keys = _PyDict_NewKeysForClass();
}
+ if (type->tp_doc) {
+ PyObject *__doc__ = PyUnicode_FromString(_PyType_DocWithoutSignature(type->tp_name, type->tp_doc));
+ if (!__doc__)
+ goto fail;
+ int ret = _PyDict_SetItemId(type->tp_dict, &PyId___doc__, __doc__);
+ Py_DECREF(__doc__);
+ if (ret < 0)
+ goto fail;
+ }
+
if (weaklistoffset) {
type->tp_weaklistoffset = weaklistoffset;
if (PyDict_DelItemString((PyObject *)type->tp_dict, "__weaklistoffset__") < 0)