8000 bpo-29941: Assert fixes (#886) (#956) · python/cpython@553275d · GitHub
[go: up one dir, main page]

Skip to content

Commit 553275d

Browse files
authored
bpo-29941: Assert fixes (#886) (#956)
Make a non-Py_DEBUG, asserts-enabled build of CPython possible. This means making sure helper functions are defined when NDEBUG is not defined, not just when Py_DEBUG is defined. Also fix a division-by-zero in obmalloc.c that went unnoticed because in Py_DEBUG mode, elsize is never zero. (cherry picked from commit a00c3fd and 06bb487)
1 parent 51fc7e3 commit 553275d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Include/unicodeobject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,10 @@ PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy(
22632263
PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
22642264
PyObject *op,
22652265
int check_content);
2266+
#elif !defined(NDEBUG)
2267+
/* For asserts that call _PyUnicode_CheckConsistency(), which would
2268+
* otherwise be a problem when building with asserts but without Py_DEBUG. */
2269+
#define _PyUnicode_CheckConsistency(op, check_content) PyUnicode_Check(op)
22662270
#endif
22672271

22682272
/* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/

Objects/obmalloc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
11761176

11771177
_Py_AllocatedBlocks++;
11781178

1179- assert(nelem <= PY_SSIZE_T_MAX / elsize);
1179+
assert(elsize == 0 || nelem <= PY_SSIZE_T_MAX / elsize);
11801180
nbytes = nelem * elsize;
11811181

11821182
#ifdef WITH_VALGRIND
@@ -2233,7 +2233,9 @@ _PyObject_DebugMallocStats(FILE *out)
22332233

22342234
if (p->ref.count == 0) {
22352235
/* currently unused */
2236+
#ifdef Py_DEBUG
22362237
assert(pool_is_in_list(p, arenas[i].freepools));
2238+
#endif
22372239
continue;
22382240
}
22392241
++numpools[sz];

0 commit comments

Comments
 (0)
0