bpo-35059: Convert _PyObject_GC_TRACK() to inline function (GH-10643) · python/cpython@271753a · GitHub
Skip to content

Commit 271753a

Browse files
authored
bpo-35059: Convert _PyObject_GC_TRACK() to inline function (GH-10643)
* Add _PyObject_ASSERT_FROM() and _PyObject_ASSERT_FAILED_MSG() macros. * PyObject_GC_Track() now calls _PyObject_ASSERT_FAILED_MSG(), instead of Py_FatalError(), if the object is already tracked, to dump more information on error. * _PyObject_GC_TRACK() no longer checks if the object is already tracked at runtime, use an assertion instead for best performances; PyObject_GC_Track() still checks at runtime. * pycore_object.h now includes pycore_pystate.h. * Convert _PyObject_GC_TRACK() and _PyObject_GC_UNTRACK() macros to inline functions.
1 parent f1d002c commit 271753a

3 files changed

Lines changed: 68 additions & 42 deletions

File tree

Include/internal/pycore_object.h

Lines changed: 46 additions & 24 deletions

Include/object.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ _PyObject_DebugTypeStats(FILE *out);
11361136

11371137
#ifndef Py_LIMITED_API
11381138
/* Define a pair of assertion macros:
1139-
_PyObject_ASSERT_WITH_MSG() and _PyObject_ASSERT().
1139+
_PyObject_ASSERT_FROM(), _PyObject_ASSERT_WITH_MSG() and _PyObject_ASSERT().
11401140
11411141
These work like the regular C assert(), in that they will abort the
11421142
process with a message on stderr if the given condition fails to hold,
@@ -1151,21 +1151,24 @@ _PyObject_DebugTypeStats(FILE *out);
11511151
will attempt to print to stderr, after the object dump. */
11521152
#ifdef NDEBUG
11531153
/* No debugging: compile away the assertions: */
1154-
# define _PyObject_ASSERT_WITH_MSG(obj, expr, msg) ((void)0)
1154+
# define _PyObject_ASSERT_FROM(obj, expr, msg, filename, lineno, func) \
1155+
((void)0)
11551156
#else
11561157
/* With debugging: generate checks: */
1157-
# define _PyObject_ASSERT_WITH_MSG(obj, expr, msg) \
1158-
((expr) \
1159-
? (void)(0) \
1160-
: _PyObject_AssertFailed((obj), \
1161-
Py_STRINGIFY(expr), \
1162-
(msg), \
1163-
__FILE__, \
1164-
__LINE__, \
1165-
__func__))
1158+
# define _PyObject_ASSERT_FROM(obj, expr, msg, filename, lineno, func) \
1159+
((expr) \
1160+
? (void)(0) \
1161+
: _PyObject_AssertFailed((obj), Py_STRINGIFY(expr), \
1162+
(msg), (filename), (lineno), (func)))
11661163
#endif
11671164

1168-
#define _PyObject_ASSERT(obj, expr) _PyObject_ASSERT_WITH_MSG(obj, expr, NULL)
1165+
#define _PyObject_ASSERT_WITH_MSG(obj, expr, msg) \
1166+
_PyObject_ASSERT_FROM(obj, expr, msg, __FILE__, __LINE__, __func__)
1167+
#define _PyObject_ASSERT(obj, expr) \
1168+
_PyObject_ASSERT_WITH_MSG(obj, expr, NULL)
1169+
1170+
#define _PyObject_ASSERT_FAILED_MSG(obj, msg) \
1171+
_PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
11691172

11701173
/* Declare and define _PyObject_AssertFailed() even when NDEBUG is defined,
11711174
to avoid causing compiler/linker errors when building extensions without

Modules/gcmodule.c

Lines changed: 7 additions & 6 deletions

0 commit comments

Comments
 (0)