]> granicus.if.org Git - python/commitdiff
bpo-9263: _Py_NegativeRefcount() use _PyObject_AssertFailed() (GH-10109)
authorVictor Stinner <vstinner@redhat.com>
Fri, 26 Oct 2018 00:12:34 +0000 (02:12 +0200)
committerGitHub <noreply@github.com>
Fri, 26 Oct 2018 00:12:34 +0000 (02:12 +0200)
_Py_NegativeRefcount() now uses _PyObject_AssertFailed() to dump the
object to help debugging.

Lib/test/test_capi.py
Objects/object.c

index a732f4f82f31d63b37d55289d149fb504050e937..b3600ebe993de5ce8864fde39e37997b3de69128 100644 (file)
@@ -329,8 +329,9 @@ class CAPITest(unittest.TestCase):
         """)
         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):
index 2252f98347566f94f370f51139d745fb6fee93b9..d6f27ff9487fd6d6c69be347e6ab3feffc299dcd 100644 (file)
@@ -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 */
@@ -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)