From b302b3ffff598905d6811c429f25e2a01d758ea1 Mon Sep 17 00:00:00 2001 From: Andy Lester Date: Mon, 6 Apr 2020 22:36:31 -0500 Subject: [PATCH 1/2] Keep constness of pointer objects. Also moved an auto variable that got consted into its innermost necessary scope. --- Objects/typeobject.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index bdd16af929079f..6e192f17a9d2a7 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2850,19 +2850,19 @@ PyObject * PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) { PyHeapTypeObject *res; - PyMemberDef *memb; PyObject *modname; PyTypeObject *type, *base; - PyType_Slot *slot; + const PyType_Slot *slot; Py_ssize_t nmembers, weaklistoffset, dictoffset; - char *s, *res_start; + const char *s; + char *res_start; nmembers = weaklistoffset = dictoffset = 0; for (slot = spec->slots; slot->slot; slot++) { if (slot->slot == Py_tp_members) { nmembers = 0; - for (memb = slot->pfunc; memb->name != NULL; memb++) { + for (const PyMemberDef *memb = slot->pfunc; memb->name != NULL; memb++) { nmembers++; if (strcmp(memb->name, "__weaklistoffset__") == 0) { // The PyMemberDef must be a Py_ssize_t and readonly @@ -2894,7 +2894,7 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) /* Set the type name and qualname */ s = strrchr(spec->name, '.'); if (s == NULL) - s = (char*)spec->name; + s = spec->name; else s++; From 3bf139900bdd9964d94e8e72cc1b3ef2ff7a9e0b Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 9 Apr 2020 19:46:40 -0500 Subject: [PATCH 2/2] move def --- Objects/typeobject.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 6e192f17a9d2a7..74b8295a14490c 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2855,7 +2855,6 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) const PyType_Slot *slot; Py_ssize_t nmembers, weaklistoffset, dictoffset; - const char *s; char *res_start; nmembers = weaklistoffset = dictoffset = 0; @@ -2892,7 +2891,7 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) } /* Set the type name and qualname */ - s = strrchr(spec->name, '.'); + const char *s = strrchr(spec->name, '.'); if (s == NULL) s = spec->name; else