Skip to content

Commit

Permalink
pythongh-127787: refactor helpers for PyUnicodeErrorObject internal…
Browse files Browse the repository at this point in the history
… interface (pythonGH-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}`
  • Loading branch information
picnixz authored Jan 3, 2025
1 parent 8abd6ce commit fa985be
Show file tree
Hide file tree
Showing 2 changed files with 293 additions and 155 deletions.
6 changes: 6 additions & 0 deletions Include/cpython/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);

/* In exceptions.c */

PyAPI_FUNC(int) _PyUnicodeError_GetParams(
PyObject *self,
PyObject **obj, Py_ssize_t *objlen,
Py_ssize_t *start, Py_ssize_t *end,
int as_bytes);

PyAPI_FUNC(PyObject*) PyUnstable_Exc_PrepReraiseStar(
PyObject *orig,
PyObject *excs);
Expand Down
Loading

0 comments on commit fa985be

Please sign in to comment.