summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-11-21 22:53:44 (GMT)
committerGitHub <noreply@github.com>2018-11-21 22:53:44 (GMT)
commitf1d002c1e094922b0f17a820f90ff102d68ab253 (patch)
tree4f9b4d17b8465d0b9b2fbd1f8da4491011a8e00d /Objects
parentbcda8f1d42a98d9022736dd52d855be8e220fe15 (diff)
downloadcpython-f1d002c1e094922b0f17a820f90ff102d68ab253.zip
cpython-f1d002c1e094922b0f17a820f90ff102d68ab253.tar.gz
cpython-f1d002c1e094922b0f17a820f90ff102d68ab253.tar.bz2
bpo-35059: Enhance _PyObject_AssertFailed() (GH-10642)
Enhance _PyObject_AssertFailed() * Exchange 'expr' and 'msg' parameters * 'expr' and 'func' arguments can now be NULL
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 801b205..9d2614b 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -205,8 +205,7 @@ void _Py_dec_count(PyTypeObject *tp)
void
_Py_NegativeRefcount(const char *filename, int lineno, PyObject *op)
{
- _PyObject_AssertFailed(op, "object has negative ref count",
- "op->ob_refcnt >= 0",
+ _PyObject_AssertFailed(op, NULL, "object has negative ref count",
filename, lineno, __func__);
}
@@ -2219,20 +2218,25 @@ _PyTrash_thread_destroy_chain(void)
void
-_PyObject_AssertFailed(PyObject *obj, const char *msg, const char *expr,
+_PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg,
const char *file, int line, const char *function)
{
- fprintf(stderr,
- "%s:%d: %s: Assertion \"%s\" failed",
- file, line, function, expr);
+ fprintf(stderr, "%s:%d: ", file, line);
+ if (function) {
+ fprintf(stderr, "%s: ", function);
+ }
fflush(stderr);
-
- if (msg) {
- fprintf(stderr, "; %s.\n", msg);
+ if (expr) {
+ fprintf(stderr, "Assertion \"%s\" failed", expr);
}
else {
- fprintf(stderr, ".\n");
+ fprintf(stderr, "Assertion failed");
+ }
+ fflush(stderr);
+ if (msg) {
+ fprintf(stderr, ": %s", msg);
}
+ fprintf(stderr, "\n");
fflush(stderr);
if (obj == NULL) {