Commit adce1635 authored by Victor Stinner's avatar Victor Stinner

Use Py_TYPE() and __Pyx_SET_SIZE() functions

Replace direct access to PyObject members with functions like
Py_TYPE() and __Pyx_SET_SIZE().
parent cedbd584
...@@ -1166,7 +1166,7 @@ static void __Pyx_Coroutine_dealloc(PyObject *self) { ...@@ -1166,7 +1166,7 @@ static void __Pyx_Coroutine_dealloc(PyObject *self) {
if (unlikely(PyObject_CallFinalizerFromDealloc(self))) if (unlikely(PyObject_CallFinalizerFromDealloc(self)))
#else #else
Py_TYPE(gen)->tp_del(self); Py_TYPE(gen)->tp_del(self);
if (unlikely(self->ob_refcnt > 0)) if (unlikely(Py_REFCNT(self) > 0))
#endif #endif
{ {
// resurrected. :( // resurrected. :(
...@@ -1200,7 +1200,7 @@ static void __Pyx_Coroutine_del(PyObject *self) { ...@@ -1200,7 +1200,7 @@ static void __Pyx_Coroutine_del(PyObject *self) {
#if !CYTHON_USE_TP_FINALIZE #if !CYTHON_USE_TP_FINALIZE
// Temporarily resurrect the object. // Temporarily resurrect the object.
assert(self->ob_refcnt == 0); assert(self->ob_refcnt == 0);
self->ob_refcnt = 1; __Pyx_SET_REFCNT(self, 1);
#endif #endif
__Pyx_PyThreadState_assign __Pyx_PyThreadState_assign
...@@ -1281,7 +1281,7 @@ static void __Pyx_Coroutine_del(PyObject *self) { ...@@ -1281,7 +1281,7 @@ static void __Pyx_Coroutine_del(PyObject *self) {
#if !CYTHON_USE_TP_FINALIZE #if !CYTHON_USE_TP_FINALIZE
// Undo the temporary resurrection; can't use DECREF here, it would // Undo the temporary resurrection; can't use DECREF here, it would
// cause a recursive call. // cause a recursive call.
assert(self->ob_refcnt > 0); assert(Py_REFCNT(self) > 0);
if (likely(--self->ob_refcnt == 0)) { if (likely(--self->ob_refcnt == 0)) {
// this is the normal path out // this is the normal path out
return; return;
...@@ -1290,12 +1290,12 @@ static void __Pyx_Coroutine_del(PyObject *self) { ...@@ -1290,12 +1290,12 @@ static void __Pyx_Coroutine_del(PyObject *self) {
// close() resurrected it! Make it look like the original Py_DECREF // close() resurrected it! Make it look like the original Py_DECREF
// never happened. // never happened.
{ {
Py_ssize_t refcnt = self->ob_refcnt; Py_ssize_t refcnt = Py_REFCNT(self);
_Py_NewReference(self); _Py_NewReference(self);
self->ob_refcnt = refcnt; __Pyx_SET_REFCNT(self, refcnt);
} }
#if CYTHON_COMPILING_IN_CPYTHON #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); _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
// If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so // If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
......
...@@ -2273,7 +2273,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg ...@@ -2273,7 +2273,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
PyObject *result; PyObject *result;
ternaryfunc call = func->ob_type->tp_call; ternaryfunc call = Py_TYPE(func)->tp_call;
if (unlikely(!call)) if (unlikely(!call))
return PyObject_Call(func, arg, kw); return PyObject_Call(func, arg, kw);
......
...@@ -88,7 +88,7 @@ static CYTHON_INLINE PyObject * newarrayobject(PyTypeObject *type, Py_ssize_t si ...@@ -88,7 +88,7 @@ static CYTHON_INLINE PyObject * newarrayobject(PyTypeObject *type, Py_ssize_t si
op->ob_descr = descr; op->ob_descr = descr;
op->allocated = size; op->allocated = size;
op->weakreflist = NULL; op->weakreflist = NULL;
op->ob_size = size; __Pyx_SET_SIZE(op, size);
if (size <= 0) { if (size <= 0) {
op->data.ob_item = NULL; op->data.ob_item = NULL;
} }
...@@ -116,7 +116,7 @@ static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) { ...@@ -116,7 +116,7 @@ static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) {
return -1; return -1;
} }
self->data.ob_item = (char*) items; self->data.ob_item = (char*) items;
self->ob_size = n; __Pyx_SET_SIZE(self, n);
self->allocated = n; self->allocated = n;
return 0; return 0;
} }
...@@ -126,7 +126,7 @@ static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) { ...@@ -126,7 +126,7 @@ static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) {
void *items = (void*) self->data.ob_item; void *items = (void*) self->data.ob_item;
Py_ssize_t newsize; Py_ssize_t newsize;
if (n < self->allocated && n*4 > self->allocated) { if (n < self->allocated && n*4 > self->allocated) {
self->ob_size = n; __Pyx_SET_SIZE(self, n);
return 0; return 0;
} }
newsize = n + (n / 2) + 1; newsize = n + (n / 2) + 1;
...@@ -140,7 +140,7 @@ static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) { ...@@ -140,7 +140,7 @@ static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) {
return -1; return -1;
} }
self->data.ob_item = (char*) items; self->data.ob_item = (char*) items;
self->ob_size = n; __Pyx_SET_SIZE(self, n);
self->allocated = newsize; self->allocated = newsize;
return 0; return 0;
} }
......
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