[Python-checkins] bpo-46417: Use _PyType_CAST() in Objects directory (GH-30764)

vstinner webhook-mailer at python.org
Fri Jan 21 17:33:58 EST 2022


https://github.com/python/cpython/commit/ac1f152421fab3ac854fe4565c575b306e2bb4b5
commit: ac1f152421fab3ac854fe4565c575b306e2bb4b5
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-01-21T23:33:43+01:00
summary:

bpo-46417: Use _PyType_CAST() in Objects directory (GH-30764)

files:
M Objects/complexobject.c
M Objects/dictobject.c
M Objects/enumobject.c
M Objects/exceptions.c
M Objects/floatobject.c
M Objects/listobject.c
M Objects/setobject.c
M Objects/structseq.c
M Objects/tupleobject.c

diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index f658dbf336dbf..e0766de258805 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -846,7 +846,7 @@ complex_from_string_inner(const char *s, Py_ssize_t len, void *type)
     if (s-start != len)
         goto parse_error;
 
-    return complex_subtype_from_doubles((PyTypeObject *)type, x, y);
+    return complex_subtype_from_doubles(_PyType_CAST(type), x, y);
 
   parse_error:
     PyErr_SetString(PyExc_ValueError,
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 7ce4b9069f77e..39be189e12000 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -3450,13 +3450,12 @@ static PyObject *
 dict_vectorcall(PyObject *type, PyObject * const*args,
                 size_t nargsf, PyObject *kwnames)
 {
-    assert(PyType_Check(type));
     Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
     if (!_PyArg_CheckPositional("dict", nargs, 0, 1)) {
         return NULL;
     }
 
-    PyObject *self = dict_new((PyTypeObject *)type, NULL, NULL);
+    PyObject *self = dict_new(_PyType_CAST(type), NULL, NULL);
     if (self == NULL) {
         return NULL;
     }
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index 8fbf4fd6e470b..36f592d7c239c 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -88,8 +88,7 @@ static PyObject *
 enumerate_vectorcall(PyObject *type, PyObject *const *args,
                      size_t nargsf, PyObject *kwnames)
 {
-    assert(PyType_Check(type));
-    PyTypeObject *tp = (PyTypeObject *)type;
+    PyTypeObject *tp = _PyType_CAST(type);
     Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
     Py_ssize_t nkwargs = 0;
     if (nargs == 0) {
@@ -373,8 +372,6 @@ static PyObject *
 reversed_vectorcall(PyObject *type, PyObject * const*args,
                 size_t nargsf, PyObject *kwnames)
 {
-    assert(PyType_Check(type));
-
     if (!_PyArg_NoKwnames("reversed", kwnames)) {
         return NULL;
     }
@@ -384,7 +381,7 @@ reversed_vectorcall(PyObject *type, PyObject * const*args,
         return NULL;
     }
 
-    return reversed_new_impl((PyTypeObject *)type, args[0]);
+    return reversed_new_impl(_PyType_CAST(type), args[0]);
 }
 
 static void
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 403d2d4a3fddf..22a47131aa12c 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -1775,8 +1775,7 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
             PyObject *newtype;
             newtype = PyDict_GetItemWithError(state->errnomap, myerrno);
             if (newtype) {
-                assert(PyType_Check(newtype));
-                type = (PyTypeObject *) newtype;
+                type = _PyType_CAST(newtype);
             }
             else if (PyErr_Occurred())
                 goto error;
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 68be7acaa2e72..79fbdabce9608 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1686,7 +1686,7 @@ float_vectorcall(PyObject *type, PyObject * const*args,
     }
 
     PyObject *x = nargs >= 1 ? args[0] : NULL;
-    return float_new_impl((PyTypeObject *)type, x);
+    return float_new_impl(_PyType_CAST(type), x);
 }
 
 
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 29f5d70f1dbd3..0ce58b240327f 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2858,8 +2858,7 @@ list_vectorcall(PyObject *type, PyObject * const*args,
         return NULL;
     }
 
-    assert(PyType_Check(type));
-    PyObject *list = PyType_GenericAlloc((PyTypeObject *)type, 0);
+    PyObject *list = PyType_GenericAlloc(_PyType_CAST(type), 0);
     if (list == NULL) {
         return NULL;
     }
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 6e110ef196c82..ca3cfe8196467 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1001,7 +1001,7 @@ make_new_frozenset(PyTypeObject *type, PyObject *iterable)
         Py_INCREF(iterable);
         return iterable;
     }
-    return make_new_set((PyTypeObject *)type, iterable);
+    return make_new_set(type, iterable);
 }
 
 static PyObject *
@@ -1036,7 +1036,7 @@ frozenset_vectorcall(PyObject *type, PyObject * const*args,
     }
 
     PyObject *iterable = (nargs ? args[0] : NULL);
-    return make_new_frozenset((PyTypeObject *)type, iterable);
+    return make_new_frozenset(_PyType_CAST(type), iterable);
 }
 
 static PyObject *
@@ -1974,10 +1974,10 @@ set_vectorcall(PyObject *type, PyObject * const*args,
     }
 
     if (nargs) {
-        return make_new_set((PyTypeObject *)type, args[0]);
+        return make_new_set(_PyType_CAST(type), args[0]);
     }
 
-    return make_new_set((PyTypeObject *)type, NULL);
+    return make_new_set(_PyType_CAST(type), NULL);
 }
 
 static PySequenceMethods set_as_sequence = {
diff --git a/Objects/structseq.c b/Objects/structseq.c
index dfefae8928eb6..cded877300d9e 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -108,10 +108,9 @@ static void
 structseq_dealloc(PyStructSequence *obj)
 {
     Py_ssize_t i, size;
-    PyTypeObject *tp;
     PyObject_GC_UnTrack(obj);
 
-    tp = (PyTypeObject *) Py_TYPE(obj);
+    PyTypeObject *tp = Py_TYPE(obj);
     size = REAL_SIZE(obj);
     for (i = 0; i < size; ++i) {
         Py_XDECREF(obj->ob_item[i]);
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 2051c1812efe2..86f541a96a5a1 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -817,7 +817,7 @@ tuple_vectorcall(PyObject *type, PyObject * const*args,
     }
 
     if (nargs) {
-        return tuple_new_impl((PyTypeObject *)type, args[0]);
+        return tuple_new_impl(_PyType_CAST(type), args[0]);
     }
     else {
         return tuple_get_empty();



More information about the Python-checkins mailing list