Skip to content

Commit 90e3518

Browse files
authored
bpo-29941: Assert fixes (#886) (#955)
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 a71a3ad commit 90e3518

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Include/unicodeobject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,10 @@ PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy(
23092309
PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
23102310
PyObject *op,
23112311
int check_content);
2312+
#elif !defined(NDEBUG)
2313+
/* For asserts that call _PyUnicode_CheckConsistency(), which would
2314+
* otherwise be a problem when building with asserts but without Py_DEBUG. */
2315+
#define _PyUnicode_CheckConsistency(op, check_content) PyUnicode_Check(op)
23122316
#endif
23132317

23142318
#ifndef Py_LIMITED_API

Objects/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static PyObject *empty_values[1] = { NULL };
436436
/* #define DEBUG_PYDICT */
437437

438438

439-
#ifdef Py_DEBUG
439+
#ifndef NDEBUG
440440
static int
441441
_PyDict_CheckConsistency(PyDictObject *mp)
442442
{

Objects/obmalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
12271227

12281228
_Py_AllocatedBlocks++;
12291229

1230-
assert(nelem <= PY_SSIZE_T_MAX / elsize);
1230+
assert(elsize == 0 || nelem <= PY_SSIZE_T_MAX / elsize);
12311231
nbytes = nelem * elsize;
12321232

12331233
#ifdef WITH_VALGRIND

0 commit comments

Comments
 (0)