Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
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
27 changes: 16 additions & 11 deletions 27 Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,25 +461,30 @@ static inline void _Py_INCREF(PyObject *op)

#define Py_INCREF(op) _Py_INCREF(_PyObject_CAST(op))

#ifdef Py_REF_DEBUG
static inline void _Py_DECREF(const char *filename, int lineno,
PyObject *op)
{
(void)filename; /* may be unused, shut up -Wunused-parameter */
(void)lineno; /* may be unused, shut up -Wunused-parameter */
_Py_DEC_REFTOTAL;
if (--op->ob_refcnt != 0) {
#ifdef Py_REF_DEBUG
if (op->ob_refcnt < 0) {
_Py_NegativeRefcount(filename, lineno, op);
}
#endif
_Py_RefTotal--;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this _Py_DEC_REFTOTAL would be converted in your plan?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_Py_DEC_REFTOTAL = _Py_RefTotal-- when Py_REF_DEBUG is defined. I prefer to put directly the real code, it may help debugging. It avoids the indirection of the preprocessor.

if (--op->ob_refcnt == 0) {
_Py_Dealloc(op);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code dupe irks me. Can't you make the REF_DEBUG version call the regular version instead?

}
else {
else if (op->ob_refcnt < 0) {
_Py_NegativeRefcount(filename, lineno, op);
}
}

# define Py_DECREF(op) _Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op))
#else
static inline void _Py_DECREF(PyObject *op)
{
if (--op->ob_refcnt == 0) {
_Py_Dealloc(op);
}
}

#define Py_DECREF(op) _Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op))
# define Py_DECREF(op) _Py_DECREF(_PyObject_CAST(op))
#endif /* !Py_REF_DEBUG */


/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.