Unverified Kaydet (Commit) 3ec9af75 authored tarafından Victor Stinner's avatar Victor Stinner Kaydeden (comit) GitHub

bpo-9263: _Py_NegativeRefcount() use _PyObject_AssertFailed() (GH-10109)

_Py_NegativeRefcount() now uses _PyObject_AssertFailed() to dump the
object to help debugging.
üst c89a9327
...@@ -329,8 +329,9 @@ class CAPITest(unittest.TestCase): ...@@ -329,8 +329,9 @@ class CAPITest(unittest.TestCase):
""") """)
rc, out, err = assert_python_failure('-c', code) rc, out, err = assert_python_failure('-c', code)
self.assertRegex(err, self.assertRegex(err,
br'_testcapimodule\.c:[0-9]+ object at .* ' br'_testcapimodule\.c:[0-9]+: '
br'has negative ref count', err) br'_Py_NegativeRefcount: Assertion ".*" failed; '
br'object has negative ref count')
class TestPendingCalls(unittest.TestCase): class TestPendingCalls(unittest.TestCase):
......
...@@ -205,13 +205,9 @@ void dec_count(PyTypeObject *tp) ...@@ -205,13 +205,9 @@ void dec_count(PyTypeObject *tp)
void void
_Py_NegativeRefcount(const char *filename, int lineno, PyObject *op) _Py_NegativeRefcount(const char *filename, int lineno, PyObject *op)
{ {
char buf[300]; _PyObject_AssertFailed(op, "object has negative ref count",
"op->ob_refcnt >= 0",
PyOS_snprintf(buf, sizeof(buf), filename, lineno, __func__);
"%s:%i object at %p has negative ref count "
"%" PY_FORMAT_SIZE_T "d",
filename, lineno, op, op->ob_refcnt);
Py_FatalError(buf);
} }
#endif /* Py_REF_DEBUG */ #endif /* Py_REF_DEBUG */
...@@ -356,13 +352,14 @@ PyObject_Print(PyObject *op, FILE *fp, int flags) ...@@ -356,13 +352,14 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
else { else {
if (op->ob_refcnt <= 0) if (op->ob_refcnt <= 0) {
/* XXX(twouters) cast refcount to long until %zd is /* XXX(twouters) cast refcount to long until %zd is
universally available */ universally available */
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
fprintf(fp, "<refcnt %ld at %p>", fprintf(fp, "<refcnt %ld at %p>",
(long)op->ob_refcnt, op); (long)op->ob_refcnt, op);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
}
else { else {
PyObject *s; PyObject *s;
if (flags & Py_PRINT_RAW) if (flags & Py_PRINT_RAW)
......
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