Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/sage/matrix/args.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from cpython.object cimport PyObject
from cpython.ref cimport _Py_REFCNT
from sage.structure.element cimport Element, Matrix
from sage.structure.parent cimport Parent

Expand Down Expand Up @@ -64,7 +65,7 @@ cdef class MatrixArgs:
Can we safely return self.entries without making a copy?
A refcount of 1 means that self.entries is the only reference.
"""
return (<PyObject*>self.entries).ob_refcnt == 1
return _Py_REFCNT(<PyObject*>self.entries) == 1

cdef inline bint need_to_convert(self, x) noexcept:
"""Is ``x`` not an element of ``self.base``?"""
Expand Down
5 changes: 4 additions & 1 deletion src/sage/rings/integer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ new_gen_from_integer = None
cdef extern from *:
int unlikely(int) nogil # Defined by Cython

cdef extern from "Python.h":
void Py_SET_REFCNT(PyObject*, Py_ssize_t) nogil

cdef object numpy_long_interface = {'typestr': '=i4' if sizeof(long) == 4 else '=i8'}
cdef object numpy_int64_interface = {'typestr': '=i8'}
cdef object numpy_object_interface = {'typestr': '|O'}
Expand Down Expand Up @@ -7724,7 +7727,7 @@ cdef PyObject* fast_tp_new(type t, args, kwds) except NULL:
# Objects from the pool have reference count zero, so this
# needs to be set in this case.

new.ob_refcnt = 1
Py_SET_REFCNT(<PyObject*>new, 1)

return new

Expand Down
5 changes: 4 additions & 1 deletion src/sage/rings/real_double.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ from libc.string cimport memcpy
from cpython.object cimport *
from cpython.float cimport *

cdef extern from "Python.h":
void Py_SET_REFCNT(PyObject*, Py_ssize_t) nogil

from sage.ext.stdsage cimport PY_NEW
from sage.cpython.python_debug cimport if_Py_TRACE_REFS_then_PyObject_INIT

Expand Down Expand Up @@ -2157,7 +2160,7 @@ cdef PyObject* fast_tp_new(type t, args, kwds) noexcept:
# Objects from the pool have reference count zero, so this
# needs to be set in this case.

new.ob_refcnt = 1
Py_SET_REFCNT(<PyObject*>new, 1)

return new

Expand Down
4 changes: 2 additions & 2 deletions src/sage/symbolic/ginac/numeric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@

#define Py_INCREF(op) ( \
_Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
((PyObject*)(op))->ob_refcnt++) ; \
Py_SET_REFCNT((PyObject*)(op), Py_REFCNT(op) + 1)) ; \
std::cerr << "+ " << long(op) << ", " << Py_REFCNT(op) << ", " << Py_TYPE(op)->tp_name << std::endl; std::cerr.flush();

#define Py_DECREF(op) \
do { \
std::cerr << "- " << long(op) << ", " << Py_REFCNT(op) << ", " << Py_TYPE(op)->tp_name << std::endl; std::cerr.flush(); \
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
--((PyObject*)(op))->ob_refcnt != 0) \
(Py_SET_REFCNT((PyObject*)(op), Py_REFCNT(op) - 1), Py_REFCNT(op) != 0)) \
_Py_CHECK_REFCNT(op) \
else \
_Py_Dealloc((PyObject *)(op)); \
Expand Down
Loading