bpo-46417: Add _PyType_CAST() macro#30760
bpo-46417: Add _PyType_CAST() macro#30760vstinner merged 1 commit intopython:mainfrom vstinner:type_cast
Conversation
In debug mode, the macro makes sure that its argument is a type using an assertion.
erlend-aasland
left a comment
There was a problem hiding this comment.
I see you left some ordinary type casts. Was that deliberate, or did you miss some _PyType_CASTs?
| type->tp_name, Py_TYPE(ob)->tp_name); | ||
| return -1; | ||
| } | ||
| PyTypeObject *base = (PyTypeObject*)ob; |
There was a problem hiding this comment.
Use _PyType_CAST here as well?
There was a problem hiding this comment.
We just checked PyType_Check() at runtime (even if assertions are removed by the compiler), using the macro is redundant (it would call PyType_Check() twice in debug mode).
| Py_TYPE(obj)->tp_name); | ||
| return -1; | ||
| } | ||
| PyTypeObject *base = (PyTypeObject*)obj; |
| return NULL; | ||
| } | ||
| base_i = (PyTypeObject *)base_proto; | ||
| PyTypeObject *base_i = (PyTypeObject *)base_proto; |
| Py_TYPE(value)->tp_name); | ||
| return -1; | ||
| } | ||
| PyTypeObject *newto = (PyTypeObject *)value; |
| return NULL; | ||
| } | ||
| type = (PyTypeObject *)self; | ||
| PyTypeObject *type = (PyTypeObject *)self; |
| return NULL; | ||
| } | ||
| subtype = (PyTypeObject *)arg0; | ||
| PyTypeObject *subtype = (PyTypeObject *)arg0; |
| if ((PyObject *)subclass == Py_None) | ||
| PyObject *obj = PyWeakref_GET_OBJECT(ref); | ||
| assert(obj != NULL); | ||
| if (obj == Py_None) { |
There was a problem hiding this comment.
| if (obj == Py_None) { | |
| if (Py_IsNone(obj)) { |
There was a problem hiding this comment.
Trust me, the temptation to refactor everything in this old giant C file is very high :-D But then it leads to PR which is impossible to review :-( I prefer to leave this test unchanged.
I left unchanged the raw type casts which are just after a PyType_Check() test. Locally, I have a local Git branch to cleanup way more casts: I prefer to create a separated PR for these ones :-) |
Ok, I assumed you had a good reason for it :) |
In debug mode, the macro makes sure that its argument is a type using
an assertion.
https://bugs.python.org/issue46417