diff options
author | Georg Brandl <georg@python.org> | 2009-03-31 04:16:10 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-03-31 04:16:10 (GMT) |
commit | ab6f2f6eb680c40750f05de4bc7cf8964b733b74 (patch) | |
tree | 77f3d4c83191b1cc077683af03a94681ce917cdb /Doc/c-api | |
parent | 71095ea4ce1b8584d89047f2256b183d40cc9d35 (diff) | |
download | cpython-ab6f2f6eb680c40750f05de4bc7cf8964b733b74.zip cpython-ab6f2f6eb680c40750f05de4bc7cf8964b733b74.tar.gz cpython-ab6f2f6eb680c40750f05de4bc7cf8964b733b74.tar.bz2 |
Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Diffstat (limited to 'Doc/c-api')
-rw-r--r-- | Doc/c-api/exceptions.rst | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index f650cfd..819e22e 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -400,6 +400,52 @@ in various ways. There is a separate error indicator for each thread. the warning message. +Exception Objects +================= + +.. cfunction:: PyObject* PyException_GetTraceback(PyObject *ex) + + Return the traceback associated with the exception as a new reference, as + accessible from Python through :attr:`__traceback__`. If there is no + traceback associated, this returns *NULL*. + + +.. cfunction:: int PyException_SetTraceback(PyObject *ex, PyObject *tb) + + Set the traceback associated with the exception to *tb*. Use ``Py_None`` to + clear it. + + +.. cfunction:: PyObject* PyException_GetContext(PyObject *ex) + + Return the context (another exception instance during whose handling *ex* was + raised) associated with the exception as a new reference, as accessible from + Python through :attr:`__context__`. If there is no context associated, this + returns *NULL*. + + +.. cfunction:: void PyException_SetContext(PyObject *ex, PyObject *ctx) + + Set the context associated with the exception to *ctx*. Use *NULL* to clear + it. There is no type check to make sure that *ctx* is an exception instance. + This steals a reference to *ctx*. + + +.. cfunction:: PyObject* PyException_GetCause(PyObject *ex) + + Return the cause (another exception instance set by ``raise ... from ...``) + associated with the exception as a new reference, as accessible from Python + through :attr:`__cause__`. If there is no cause associated, this returns + *NULL*. + + +.. cfunction:: void PyException_SetCause(PyObject *ex, PyObject *ctx) + + Set the cause associated with the exception to *ctx*. Use *NULL* to clear + it. There is no type check to make sure that *ctx* is an exception instance. + This steals a reference to *ctx*. + + .. _standardexceptions: Standard Exceptions |