FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-9263: _Py_NegativeRefcount() use _PyObject_AssertFailed() by vstinner · Pull Request #10109 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 3 additions & 2 deletions Lib/test/test_capi.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,9 @@ def test_negative_refcount(self):
""")
rc, out, err = assert_python_failure('-c', code)
self.assertRegex(err,
br'_testcapimodule\.c:[0-9]+ object at .* '
br'has negative ref count', err)
br'_testcapimodule\.c:[0-9]+: '
br'_Py_NegativeRefcount: Assertion ".*" failed; '
br'object has negative ref count')


class TestPendingCalls(unittest.TestCase):
Expand Down
13 changes: 5 additions & 8 deletions Objects/object.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,9 @@ void dec_count(PyTypeObject *tp)
void
_Py_NegativeRefcount(const char *filename, int lineno, PyObject *op)
{
char buf[300];

PyOS_snprintf(buf, sizeof(buf),
"%s:%i object at %p has negative ref count "
"%" PY_FORMAT_SIZE_T "d",
filename, lineno, op, op->ob_refcnt);
Py_FatalError(buf);
_PyObject_AssertFailed(op, "object has negative ref count",
"op->ob_refcnt >= 0",
filename, lineno, __func__);
}

#endif /* Py_REF_DEBUG */
Expand Down Expand Up @@ -356,13 +352,14 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
Py_END_ALLOW_THREADS
}
else {
if (op->ob_refcnt <= 0)
if (op->ob_refcnt <= 0) {
/* XXX(twouters) cast refcount to long until %zd is
universally available */
Py_BEGIN_ALLOW_THREADS
fprintf(fp, "<refcnt %ld at %p>",
(long)op->ob_refcnt, op);
Py_END_ALLOW_THREADS
}
else {
PyObject *s;
if (flags & Py_PRINT_RAW)
Expand Down

Back | FazBrowse Home | New Git URL