10000 bpo-29941: Assert fixes by Yhg1s · Pull Request #886 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-29941: Assert fixes #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only check for PyErr_Occurred() in asserts when in a Py_DEBUG build. …
…Unlike

other asserts this is easy to trigger indirectly, and the assertion failure
will not point to the actual problem.
  • Loading branch information
Yhg1s committed Mar 29, 2017
commit 73332986f7b4a3335f48135932b5235c97b977f6
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
0