Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions 8 Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -1158,8 +1158,8 @@ _PyObject_DebugTypeStats(FILE *out);
((expr) \
? (void)(0) \
: _PyObject_AssertFailed((obj), \
(msg), \
Py_STRINGIFY(expr), \
(msg), \
__FILE__, \
__LINE__, \
__func__))
Expand All @@ -1169,11 +1169,13 @@ _PyObject_DebugTypeStats(FILE *out);

/* 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);
Expand Down
2 changes: 1 addition & 1 deletion 2 Lib/test/test_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def test_negative_refcount(self):
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')


Expand Down
24 changes: 14 additions & 10 deletions 24 Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
}

Expand Down Expand Up @@ -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) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.