Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Include/unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -2313,6 +2313,10 @@ PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy(
PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
PyObject *op,
int check_content);
#elif !defined(NDEBUG)
/* For asserts that call _PyUnicode_CheckConsistency(), which would
* otherwise be a problem when building with asserts but without Py_DEBUG. */
#define _PyUnicode_CheckConsistency(op, check_content) PyUnicode_Check(op)
#endif

#ifndef Py_LIMITED_API
Expand Down
4 changes: 4 additions & 0 deletions Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ PyObject_GetItem(PyObject *o, PyObject *key)
m = o->ob_type->tp_as_mapping;
if (m && m->mp_subscript) {
PyObject *item = m->mp_subscript(o, key);
#ifdef Py_DEBUG
assert((item != NULL) ^ (PyErr_Occurred() != NULL));
#endif
return item;
}

Expand Down Expand Up @@ -1623,7 +1625,9 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i)
if (m->sq_length) {
Py_ssize_t l = (*m->sq_length)(s);
if (l < 0) {
#ifdef Py_DEBUG
assert(PyErr_Occurred());
#endif
return NULL;
}
i += l;
Expand Down
13 changes: 13 additions & 0 deletions Objects/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ PyObject *
_PyObject_FastCallDict(PyObject *callable, PyObject **args, Py_ssize_t nargs,
PyObject *kwargs)
{
#ifdef Py_DEBUG
/* _PyObject_FastCallDict() must not be called with an exception set,
because it can clear it (directly or indirectly) and so the
caller loses its exception */
assert(!PyErr_Occurred());
#endif

assert(callable != NULL);
assert(nargs >= 0);
Expand Down Expand Up @@ -136,10 +138,12 @@ PyObject *
_PyObject_FastCallKeywords(PyObject *callable, PyObject **stack, Py_ssize_t nargs,
PyObject *kwnames)
{
#ifdef Py_DEBUG
/* _PyObject_FastCallKeywords() must not be called with an exception set,
because it can clear it (directly or indirectly) and so the
caller loses its exception */
assert(!PyErr_Occurred());
#endif

assert(nargs >= 0);
assert(kwnames == NULL || PyTuple_CheckExact(kwnames));
Expand Down Expand Up @@ -214,10 +218,13 @@ PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
ternaryfunc call;
PyObject *result;

#ifdef Py_DEBUG
/* PyObject_Call() must not be called with an exception set,
because it can clear it (directly or indirectly) and so the
caller loses its exception */
assert(!PyErr_Occurred());
#endif

assert(PyTuple_Check(args));
assert(kwargs == NULL || PyDict_Check(kwargs));

Expand Down Expand Up @@ -445,10 +452,12 @@ PyObject *
_PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self, PyObject **args,
Py_ssize_t nargs, PyObject *kwargs)
{
#ifdef Py_DEBUG
/* _PyMethodDef_RawFastCallDict() must not be called with an exception set,
because it can clear it (directly or indirectly) and so the
caller loses its exception */
assert(!PyErr_Occurred());
#endif

assert(method != NULL);
assert(nargs >= 0);
Expand Down Expand Up @@ -579,10 +588,12 @@ PyObject *
_PyMethodDef_RawFastCallKeywords(PyMethodDef *method, PyObject *self, PyObject **args,
Py_ssize_t nargs, PyObject *kwnames)
{
#ifdef Py_DEBUG
/* _PyMethodDef_RawFastCallKeywords() must not be called with an exception set,
because it can clear it (directly or indirectly) and so the
caller loses its exception */
assert(!PyErr_Occurred());
#endif

assert(method != NULL);
assert(nargs >= 0);
Expand Down Expand Up @@ -716,7 +727,9 @@ _PyCFunction_FastCallKeywords(PyObject *func, PyObject **args,
static PyObject *
cfunction_call_varargs(PyObject *func, PyObject *args, PyObject *kwargs)
{
#ifdef Py_DEBUG
assert(!PyErr_Occurred());
#endif

PyCFunction meth = PyCFunction_GET_FUNCTION(func);
PyObject *self = PyCFunction_GET_SELF(func);
Expand Down
2 changes: 1 addition & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ static PyObject *empty_values[1] = { NULL };
/* #define DEBUG_PYDICT */


#ifdef Py_DEBUG
#ifndef NDEBUG
static int
_PyDict_CheckConsistency(PyDictObject *mp)
{
Expand Down
2 changes: 1 addition & 1 deletion Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)

_Py_AllocatedBlocks++;

assert(nelem <= PY_SSIZE_T_MAX / elsize);
assert(elsize == 0 || nelem <= PY_SSIZE_T_MAX / elsize);
nbytes = nelem * elsize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this whole block should go under after line 1242 instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved line 1242 up instead.


#ifdef WITH_VALGRIND
Expand Down
2 changes: 1 addition & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ skip_signature(const char *doc)
return NULL;
}

#ifdef Py_DEBUG
#ifndef NDEBUG
static int
_PyType_CheckConsistency(PyTypeObject *type)
{
Expand Down