Skip to content

Commit fa985be

Browse files
authored
gh-127787: refactor helpers for PyUnicodeErrorObject internal interface (GH-127789)
- Unify `get_unicode` and `get_string` in a single function. - Allow to retrieve the underlying `object` attribute, its size, and the adjusted 'start' and 'end', all at once. Add a new `_PyUnicodeError_GetParams` internal function for this. (In `exceptions.c`, it's somewhat common to not need all the attributes, but the compiler has opportunity to inline the function and optimize unneeded work away. Outside that file, we'll usually need all or most of them at once.) - Use a common implementation for the following functions: - `PyUnicode{Decode,Encode}Error_GetEncoding` - `PyUnicode{Decode,Encode,Translate}Error_GetObject` - `PyUnicode{Decode,Encode,Translate}Error_{Get,Set}Reason` - `PyUnicode{Decode,Encode,Translate}Error_{Get,Set}{Start,End}`
1 parent 8abd6ce commit fa985be

File tree

2 files changed

+293
-155
lines changed

2 files changed

+293
-155
lines changed

Include/cpython/pyerrors.h

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);
9494

9595
/* In exceptions.c */
9696

97+
PyAPI_FUNC(int) _PyUnicodeError_GetParams(
98+
PyObject *self,
99+
PyObject **obj, Py_ssize_t *objlen,
100+
Py_ssize_t *start, Py_ssize_t *end,
101+
int as_bytes);
102+
97103
PyAPI_FUNC(PyObject*) PyUnstable_Exc_PrepReraiseStar(
98104
PyObject *orig,
99105
PyObject *excs);

0 commit comments

Comments
 (0)