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

Skip to content

Commit a00c3fd

Browse files
authored
bpo-29941: Assert fixes (python#886)
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.
1 parent 164d30e commit a00c3fd

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

Include/unicodeobject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,10 @@ PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy(
23132313
PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
23142314
PyObject *op,
23152315
int check_content);
2316+
#elif !defined(NDEBUG)
2317+
/* For asserts that call _PyUnicode_CheckConsistency(), which would
2318+
* otherwise be a problem when building with asserts but without Py_DEBUG. */
2319+
#define _PyUnicode_CheckConsistency(op, check_content) PyUnicode_Check(op)
23162320
#endif
23172321

23182322
#ifndef Py_LIMITED_API

Objects/dictobject.c

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

439439

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

Objects/obmalloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,9 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
12271227

12281228
_Py_AllocatedBlocks++;
12291229

1230+
if (nelem == 0 || elsize == 0)
1231+
goto redirect;
1232+
12301233
assert(nelem <= PY_SSIZE_T_MAX / elsize);
12311234
nbytes = nelem * elsize;
12321235

@@ -1237,9 +1240,6 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
12371240
goto redirect;
12381241
#endif
12391242

1240-
if (nelem == 0 || elsize == 0)
1241-
goto redirect;
1242-
12431243
if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) {
12441244
LOCK();
12451245
/*

Objects/typeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ skip_signature(const char *doc)
128128
return NULL;
129129
}
130130

131-
#ifdef Py_DEBUG
131+
#ifndef NDEBUG
132132
static int
133133
_PyType_CheckConsistency(PyTypeObject *type)
134134
{

0 commit comments

Comments
 (0)
0