-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-25381: Update explanation of exceptions in C. #26838
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
Conversation
This paragraph in extending/extending.rst was unchanged (except for NULL markup) since committed in 2007 Aug 15 for 2.6 alpha.
Doc/extending/extending.rst
Outdated
(usually a ``NULL`` pointer). Exception information is stored in 3 static | ||
global variables inside the interpreter. The first is the exception type, | ||
or ``NULL`` if no exception has occurred. The second is the exception | ||
instance. The third variable contains the stack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd write "three" in words instead of "3".
Technically these are not static global variables, they are members of the thread state nowadays.
If no exception occurred all three are none.
I think there are edge cases where the exception type is set but the instance is still NULL.
I also think the traceback may be NULL even though an exception is set (probably it's NULL until the exception bubbles into a Python frame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'three', 'members', and 'all' done. Otherwise I'm going with the reference to sys.exc_info.
Doc/extending/extending.rst
Outdated
second global variable stores the "associated value" of the exception (the | ||
second argument to :keyword:`raise`). A third variable contains the stack | ||
(usually a ``NULL`` pointer). Exception information is stored in 3 static | ||
global variables inside the interpreter. The first is the exception type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "3 static global variables inside the interpreter" --> "3 fields on the interpreter's thread state" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, using 'members'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur with @iritkatriel, they are not global variables. For example, you can two interpreters, each one has its own exception information.
@terryjreedy wrote "done", but the current PR stil says "3 static global variables".
Doc/extending/extending.rst
Outdated
(usually a ``NULL`` pointer). Exception information is stored in 3 static | ||
global variables inside the interpreter. The first is the exception type, | ||
or ``NULL`` if no exception has occurred. The second is the exception | ||
instance. The third variable contains the stack | ||
traceback in case the error originated in Python code. These three variables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could originate in C but then go to python and get a traceback, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is, actually, routine, as in IndexError originating in the C list code when executing, for instance, '[][1]'. So the author (apparently Georg Brandl) must have meant something else. I'm deleting the statement.
The previous variable by variable discussion was mostly about relating the 3 variables to 2.x raise statements. No member by member discussion is needed now, so I deleted it. What the members might be while an exception is being processed by the interpreter is not relevant to users, certainly not for this entry. Is there a entry that 'thread state' should be linked to? |
section on module :mod:`sys` in the Python Library Reference). It is important | ||
(usually -1 or a ``NULL`` pointer). Exception information is stored in | ||
three members of the interpreter's thread state. These are ``NULL`` if | ||
there is no exception. Otherwise they are the C equivalents of the members |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the second can be NULL or None and the third can be NULL in case of non-normalized exception.
The first is the exception type. NULL if no exception.
The second is either the instance of exception, or argument(s) which will be passed to exception constructor on normalization. NULL or None means no arguments. Tuple means several arguments. Otherwise it is a single argument.
The third is a traceback. Can be NULL for non-normalized exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also PyErr_Fetch
, PyErr_Restore
and PyErr_NormalizeException
. Terminology should be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying that a Python user of sys.exc_info might see these other value, or that the existing claim of C equivalents is incomplete? I presume the latter. If so, how about this, instead of These are...
.
If there is no exception, these are NULL
. For a normalized exception , these are the C equivalents of the members of the Python tuple returned by :meth:sys.exc_info
: the exception type, exception instance, and a traceback object. For a non-normalized exception, the second will be an argument or tuple of arguments that will be passed to the exception on normalization, or NULL
or None, meaning "no arguments". The third argument may then be NULL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems resolved now.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This PR is stale because it has been open for 30 days with no activity. |
section on module :mod:`sys` in the Python Library Reference). It is important | ||
(usually -1 or a ``NULL`` pointer). Exception information is stored in | ||
three members of the interpreter's thread state. These are ``NULL`` if | ||
there is no exception. Otherwise they are the C equivalents of the members |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems resolved now.
Thanks @terryjreedy for the PR, and @willingc for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
* bpo-25381: Update explanation of exception globals This paragraph in extending/extending.rst was unchanged (except for NULL markup) since committed in 2007 Aug 15 for 2.6 alpha. * Respond to reviews and remove duplication. * Update Doc/extending/extending.rst Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> (cherry picked from commit ad43dc0) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-25381: Update explanation of exception globals This paragraph in extending/extending.rst was unchanged (except for NULL markup) since committed in 2007 Aug 15 for 2.6 alpha. * Respond to reviews and remove duplication. * Update Doc/extending/extending.rst Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> (cherry picked from commit ad43dc0) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
GH-29568 is a backport of this pull request to the 3.10 branch. |
GH-29569 is a backport of this pull request to the 3.9 branch. |
* bpo-25381: Update explanation of exception globals This paragraph in extending/extending.rst was unchanged (except for NULL markup) since committed in 2007 Aug 15 for 2.6 alpha. * Respond to reviews and remove duplication. * Update Doc/extending/extending.rst Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This paragraph in extending/extending.rst was unchanged (except for
NULL markup) since committed in 2007 Aug 15 for 2.6 alpha.
Except for there being 3 values, most details have changed.
https://bugs.python.org/issue25381