Commit 019aebdf authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

Use Py_TYPE() and Py_REFCNT() macros (GH-3932)

Don't access directly PyObject.ob_type and PyObject.ob_refcnt members.
parent 602d2827
......@@ -333,7 +333,7 @@ static long __Pyx__PyObject_Ord(PyObject* c) {
} else {
// FIXME: support character buffers - but CPython doesn't support them either
PyErr_Format(PyExc_TypeError,
"ord() expected string of length 1, but %.200s found", c->ob_type->tp_name);
"ord() expected string of length 1, but %.200s found", Py_TYPE(c)->tp_name);
return (long)(Py_UCS4)-1;
}
PyErr_Format(PyExc_TypeError,
......
......@@ -1159,7 +1159,7 @@ static void __Pyx_Coroutine_dealloc(PyObject *self) {
if (PyObject_CallFinalizerFromDealloc(self))
#else
Py_TYPE(gen)->tp_del(self);
if (self->ob_refcnt > 0)
if (Py_REFCNT(self) > 0)
#endif
{
// resurrected. :(
......@@ -1274,7 +1274,7 @@ static void __Pyx_Coroutine_del(PyObject *self) {
#if !CYTHON_USE_TP_FINALIZE
// Undo the temporary resurrection; can't use DECREF here, it would
// cause a recursive call.
assert(self->ob_refcnt > 0);
assert(Py_REFCNT(self) > 0);
if (--self->ob_refcnt == 0) {
// this is the normal path out
return;
......@@ -1283,12 +1283,12 @@ static void __Pyx_Coroutine_del(PyObject *self) {
// close() resurrected it! Make it look like the original Py_DECREF
// never happened.
{
Py_ssize_t refcnt = self->ob_refcnt;
Py_ssize_t refcnt = Py_REFCNT(self);
_Py_NewReference(self);
__Pyx_SET_REFCNT(self, refcnt);
}
#if CYTHON_COMPILING_IN_CPYTHON
assert(PyType_IS_GC(self->ob_type) &&
assert(PyType_IS_GC(Py_TYPE(self)) &&
_Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
// If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
......
......@@ -1136,7 +1136,7 @@ __pyx_FusedFunction_call(PyObject *func, PyObject *args, PyObject *kw)
PyErr_Format(PyExc_TypeError,
"First argument should be of type %.200s, got %.200s.",
((PyTypeObject *) binding_func->type)->tp_name,
self->ob_type->tp_name);
Py_TYPE(self)->tp_name);
goto bad;
} else if (unlikely(is_instance == -1)) {
goto bad;
......
......@@ -1040,7 +1040,7 @@ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
/////////////// CallableCheck.proto ///////////////
#if CYTHON_USE_TYPE_SLOTS && PY_MAJOR_VERSION >= 3
#define __Pyx_PyCallable_Check(obj) ((obj)->ob_type->tp_call != NULL)
#define __Pyx_PyCallable_Check(obj) (Py_TYPE(obj)->tp_call != NULL)
#else
#define __Pyx_PyCallable_Check(obj) PyCallable_Check(obj)
#endif
......@@ -1913,7 +1913,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
PyObject *result;
ternaryfunc call = func->ob_type->tp_call;
ternaryfunc call = Py_TYPE(func)->tp_call;
if (unlikely(!call))
return PyObject_Call(func, arg, kw);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment