Mercurial > cpython-lru_cache-weakref
diff Objects/exceptions.c @ 75292:b299c4f31ff2
Close issue #6210: Implement PEP 409
| author | Nick Coghlan <ncoghlan@gmail.com> |
|---|---|
| date | Sun, 26 Feb 2012 17:49:52 +1000 |
| parents | f029312764b4 |
| children | 6825fd9b00ed |
line wrap: on
line diff
--- a/Objects/exceptions.c Sun Feb 26 09:39:55 2012 +0200 +++ b/Objects/exceptions.c Sun Feb 26 17:49:52 2012 +1000 @@ -266,7 +266,24 @@ PyObject *res = PyException_GetCause(self); if (res) return res; /* new reference already returned above */ - Py_RETURN_NONE; + Py_INCREF(Py_Ellipsis); + return Py_Ellipsis; +} + +int +_PyException_SetCauseChecked(PyObject *self, PyObject *arg) { + if (arg == Py_Ellipsis) { + arg = NULL; + } else if (arg != Py_None && !PyExceptionInstance_Check(arg)) { + PyErr_SetString(PyExc_TypeError, "exception cause must be None, " + "Ellipsis or derive from BaseException"); + return -1; + } else { + /* PyException_SetCause steals a reference */ + Py_INCREF(arg); + } + PyException_SetCause(self, arg); + return 0; } static int @@ -274,18 +291,8 @@ if (arg == NULL) { PyErr_SetString(PyExc_TypeError, "__cause__ may not be deleted"); return -1; - } else if (arg == Py_None) { - arg = NULL; - } else if (!PyExceptionInstance_Check(arg)) { - PyErr_SetString(PyExc_TypeError, "exception cause must be None " - "or derive from BaseException"); - return -1; - } else { - /* PyException_SetCause steals this reference */ - Py_INCREF(arg); } - PyException_SetCause(self, arg); - return 0; + return _PyException_SetCauseChecked(self, arg); }
