Skip to content

Commit 784b67e

Browse files
[mypyc] Use Py_TYPE and Py_IsNone (python#12233)
1 parent bd37ab8 commit 784b67e

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

mypyc/lib-rt/dict_ops.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ int CPyDict_UpdateInDisplay(PyObject *dict, PyObject *stuff) {
139139
if (ret < 0) {
140140
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
141141
PyErr_Format(PyExc_TypeError,
142-
"'%.200s' object is not a mapping",
143-
stuff->ob_type->tp_name);
142+
"'%.200s' object is not a mapping",
143+
Py_TYPE(stuff)->tp_name);
144144
}
145145
}
146146
return ret;

mypyc/lib-rt/exc_ops.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static PyObject *CPy_GetTypeName(PyObject *type) {
140140
// Get the type of a value as a string, expanding tuples to include
141141
// all the element types.
142142
static PyObject *CPy_FormatTypeName(PyObject *value) {
143-
if (value == Py_None) {
143+
if (Py_IsNone(value)) {
144144
return PyUnicode_FromString("None");
145145
}
146146

mypyc/lib-rt/generic_ops.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ PyObject *CPyObject_GetAttr3(PyObject *v, PyObject *name, PyObject *defl)
3333

3434
PyObject *CPyIter_Next(PyObject *iter)
3535
{
36-
return (*iter->ob_type->tp_iternext)(iter);
36+
return (*Py_TYPE(iter)->tp_iternext)(iter);
3737
}
3838

3939
PyObject *CPyNumber_Power(PyObject *base, PyObject *index)

mypyc/lib-rt/misc_ops.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
// These are registered in mypyc.primitives.misc_ops.
44

55
#include <Python.h>
6-
#include "pythoncapi_compat.h"
76
#include "CPy.h"
87

98
PyObject *CPy_GetCoro(PyObject *obj)
109
{
1110
// If the type has an __await__ method, call it,
1211
// otherwise, fallback to calling __iter__.
13-
PyAsyncMethods* async_struct = obj->ob_type->tp_as_async;
12+
PyAsyncMethods* async_struct = Py_TYPE(obj)->tp_as_async;
1413
if (async_struct != NULL && async_struct->am_await != NULL) {
1514
return (async_struct->am_await)(obj);
1615
} else {
@@ -25,7 +24,7 @@ PyObject *CPyIter_Send(PyObject *iter, PyObject *val)
2524
// Do a send, or a next if second arg is None.
2625
// (This behavior is to match the PEP 380 spec for yield from.)
2726
_Py_IDENTIFIER(send);
28-
if (val == Py_None) {
27+
if (Py_IsNone(val)) {
2928
return CPyIter_Next(iter);
3029
} else {
3130
return _PyObject_CallMethodIdOneArg(iter, &PyId_send, val);
@@ -640,7 +639,7 @@ CPy_Super(PyObject *builtins, PyObject *self) {
640639
if (!super_type)
641640
return NULL;
642641
PyObject *result = PyObject_CallFunctionObjArgs(
643-
super_type, (PyObject*)self->ob_type, self, NULL);
642+
super_type, (PyObject*)Py_TYPE(self), self, NULL);
644643
Py_DECREF(super_type);
645644
return result;
646645
}

0 commit comments

Comments
 (0)