((expr) \
? (void)(0) \
: _PyObject_AssertFailed((obj), \
- (msg), \
Py_STRINGIFY(expr), \
+ (msg), \
__FILE__, \
__LINE__, \
__func__))
/* Declare and define _PyObject_AssertFailed() even when NDEBUG is defined,
to avoid causing compiler/linker errors when building extensions without
- NDEBUG against a Python built with NDEBUG defined. */
+ NDEBUG against a Python built with NDEBUG defined.
+
+ msg, expr and function can be NULL. */
PyAPI_FUNC(void) _PyObject_AssertFailed(
PyObject *obj,
- const char *msg,
const char *expr,
+ const char *msg,
const char *file,
int line,
const char *function);
rc, out, err = assert_python_failure('-c', code)
self.assertRegex(err,
br'_testcapimodule\.c:[0-9]+: '
- br'_Py_NegativeRefcount: Assertion ".*" failed; '
+ br'_Py_NegativeRefcount: Assertion failed: '
br'object has negative ref count')
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__);
}
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) {