Skip to content

Commit

Permalink
Merge pull request cython#3937 from vstinner/py_set_type_master
Browse files Browse the repository at this point in the history
Use Py_TYPE() and __Pyx_SET_SIZE() functions
  • Loading branch information
robertwb authored Dec 10, 2020
2 parents cedbd58 + adce163 commit 3dce9ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions Cython/Utility/Coroutine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ static void __Pyx_Coroutine_dealloc(PyObject *self) {
if (unlikely(PyObject_CallFinalizerFromDealloc(self)))
#else
Py_TYPE(gen)->tp_del(self);
if (unlikely(self->ob_refcnt > 0))
if (unlikely(Py_REFCNT(self) > 0))
#endif
{
// resurrected. :(
Expand Down Expand Up @@ -1200,7 +1200,7 @@ static void __Pyx_Coroutine_del(PyObject *self) {
#if !CYTHON_USE_TP_FINALIZE
// Temporarily resurrect the object.
assert(self->ob_refcnt == 0);
self->ob_refcnt = 1;
__Pyx_SET_REFCNT(self, 1);
#endif

__Pyx_PyThreadState_assign
Expand Down Expand Up @@ -1281,7 +1281,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 (likely(--self->ob_refcnt == 0)) {
// this is the normal path out
return;
Expand All @@ -1290,12 +1290,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);
self->ob_refcnt = refcnt;
__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
Expand Down
2 changes: 1 addition & 1 deletion Cython/Utility/ObjectHandling.c
Original file line number Diff line number Diff line change
Expand Up @@ -2273,7 +2273,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);
Expand Down
8 changes: 4 additions & 4 deletions Cython/Utility/arrayarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static CYTHON_INLINE PyObject * newarrayobject(PyTypeObject *type, Py_ssize_t si
op->ob_descr = descr;
op->allocated = size;
op->weakreflist = NULL;
op->ob_size = size;
__Pyx_SET_SIZE(op, size);
if (size <= 0) {
op->data.ob_item = NULL;
}
Expand Down Expand Up @@ -116,7 +116,7 @@ static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) {
return -1;
}
self->data.ob_item = (char*) items;
self->ob_size = n;
__Pyx_SET_SIZE(self, n);
self->allocated = n;
return 0;
}
Expand All @@ -126,7 +126,7 @@ static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) {
void *items = (void*) self->data.ob_item;
Py_ssize_t newsize;
if (n < self->allocated && n*4 > self->allocated) {
self->ob_size = n;
__Pyx_SET_SIZE(self, n);
return 0;
}
newsize = n + (n / 2) + 1;
Expand All @@ -140,7 +140,7 @@ static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) {
return -1;
}
self->data.ob_item = (char*) items;
self->ob_size = n;
__Pyx_SET_SIZE(self, n);
self->allocated = newsize;
return 0;
}
Expand Down

0 comments on commit 3dce9ee

Please sign in to comment.