Add miscellaneous non-limited PyError API functions#5989
Add miscellaneous non-limited PyError API functions#5989
Conversation
| // skipped PyAttributeErrorObject | ||
| #[repr(C)] | ||
| #[derive(Debug)] | ||
| pub struct PyNameErrorObject { |
There was a problem hiding this comment.
These two structs are not used by any public function. Is it useful to expose them? They are not documented on python.org
There was a problem hiding this comment.
These two are exposed in public headers: https://github.com/python/cpython/blob/ad7d3616c6cc21c5ec032a726e4c5e819628aa6e/Include/cpython/pyerrors.h#L76-L85
Since they aren't prefixed with _, better to expose them
There was a problem hiding this comment.
Why is it better to expose them? If there's not an actual use case, it's just extra code to maintain for no benefit.
There was a problem hiding this comment.
I think if we'd exposed none of the other structs, I would support not adding. But I think now that the ship has sailed it somewhat doesn't hurt to add these for completeness; otherwise some user might eventually start doing something with the raw objects and run into a wall with these ones unexpectedly.
One alternative is to remove the others and support the structures for none of them, but probably too late for now. (Maybe CPython removes the structures in the future.)
Co-authored-by: Thomas Tanon <thomas@pellissier-tanon.fr>
| @@ -188,3 +229,18 @@ pub struct PyStopIterationObject { | |||
| // skipped _Py_FatalErrorFunc | |||
| // skipped _Py_FatalErrorFormat | |||
| // skipped Py_FatalError | |||
There was a problem hiding this comment.
There are a ton of skipped comments above which are now either implemented or no longer in the cpython headers. Would be great to synchronize them.
| end_col_offset: c_int, | ||
| ); | ||
| pub fn PyErr_ProgramTextObject(filename: *mut PyObject, lineno: c_int) -> *mut PyObject; | ||
| pub static PyExc_PythonFinalizationError: *mut PyObject; |
There was a problem hiding this comment.
I think we could implement Py_FatalError as an inline function calling _Py_FatalErrorFunc privately.
| // skipped PyAttributeErrorObject | ||
| #[repr(C)] | ||
| #[derive(Debug)] | ||
| pub struct PyNameErrorObject { |
There was a problem hiding this comment.
I think if we'd exposed none of the other structs, I would support not adding. But I think now that the ship has sailed it somewhat doesn't hurt to add these for completeness; otherwise some user might eventually start doing something with the raw objects and run into a wall with these ones unexpectedly.
One alternative is to remove the others and support the structures for none of them, but probably too late for now. (Maybe CPython removes the structures in the future.)
| @@ -0,0 +1 @@ | |||
| Add PyNameErrorObject and PyAttributeErrorObject structs, and miscellaneous API functions | |||
There was a problem hiding this comment.
Please list the full set of public API structs / functions added.
Removed several skipped error handling functions from pyerrors.rs.
Added new structs and several API functions related to error handling.
|
void _Py_NO_RETURN
_Py_FatalErrorFunc(const char *func, const char *msg)
{
fatal_error(fileno(stderr), 1, func, msg, -1);
}and the latter's implementation is this: https://github.com/python/cpython/blob/main/Python/pylifecycle.c#L3621-L3701 |
Merging this PR will not alter performance
Comparing Footnotes
|
No description provided.