8000 gh-127787: allow to retrieved the clipped slice length in `_PyUnicodeError_GetParams` by picnixz · Pull Request #128980 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-127787: allow to retrieved the clipped slice length in _PyUnicodeError_GetParams #128980

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

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
logic simplification
  • Loading branch information
picnixz committed Jan 20, 2025
commit 60d637917740a1a6757cc7d53109e947e15d9953
10 changes: 1 addition & 9 deletions Include/internal/pycore_pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,7 @@ extern int _PyUnicodeError_GetParams(
Py_ssize_t *objlen,
Py_ssize_t *start,
Py_ssize_t *end,
Py_ssize_t *len,
int as_bytes);

/* Specialization of _PyUnicodeError_GetParams(self, NULL, NULL, ...). */
extern int _PyUnicodeError_GetSliceParams(
PyObject *self,
Py_ssize_t *start,
Py_ssize_t *end,
Py_ssize_t *len,
Py_ssize_t *slen,
int as_bytes);

#ifdef __cplusplus
Expand Down
32 changes: 13 additions & 19 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3079,7 +3079,7 @@ assert_adjusted_unicode_error_len(Py_ssize_t ranlen, Py_ssize_t objlen)
* objlen The 'object' length.
* start The clipped 'start' attribute.
* end The clipped 'end' attribute.
* len The length of the slice described by the clipped 'start'
* slen The length of the slice described by the clipped 'start'
* and 'end' values. It always lies in [0, objlen].
*
* An output parameter can be NULL to indicate that
Expand All @@ -3096,7 +3096,7 @@ assert_adjusted_unicode_error_len(Py_ssize_t ranlen, Py_ssize_t objlen)
int
_PyUnicodeError_GetParams(PyObject *self,
PyObject **obj, Py_ssize_t *objlen,
Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t *len,
Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t *slen,
int as_bytes)
{
assert(self != NULL);
Expand All @@ -3113,7 +3113,7 @@ _PyUnicodeError_GetParams(PyObject *self,
}

Py_ssize_t start_value = -1;
if (start != NULL || len != NULL) {
if (start != NULL || slen != NULL) {
start_value = unicode_error_adjust_start(exc->start, n);
}
if (start != NULL) {
Expand All @@ -3122,17 +3122,17 @@ _PyUnicodeError_GetParams(PyObject *self,
}

Py_ssize_t end_value = -1;
if (end != NULL || len != NULL) {
if (end != NULL || slen != NULL) {
end_value = unicode_error_adjust_end(exc->end, n);
}
if (end != NULL) {
assert_adjusted_unicode_error_end(end_value, n);
*end = end_value;
}

if (len != NULL) {
*len = unicode_error_adjust_len(start_value, end_value, n);
assert_adjusted_unicode_error_len(*len, n);
if (slen != NULL) {
*slen = unicode_error_adjust_len(start_value, end_value, n);
assert_adjusted_unicode_error_len(*slen, n);
}

if (obj != NULL) {
Expand All @@ -3145,16 +3145,6 @@ _PyUnicodeError_GetParams(PyObject *self,
}


inline int
_PyUnicodeError_GetSliceParams(
PyObject *self,
Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t *len,
int as_bytes
) {
return _PyUnicodeError_GetParams(self, NULL, NULL, start, end, len,
as_bytes);
}

// --- PyUnicodeEncodeObject: 'encoding' getters ------------------------------
// Note: PyUnicodeTranslateError does not have an 'encoding' attribute.

Expand Down Expand Up @@ -3212,7 +3202,9 @@ static inline int
unicode_error_get_start_impl(PyObject *self, Py_ssize_t *start, int as_bytes)
{
assert(self != NULL);
return _PyUnicodeError_GetSliceParams(self, start, NULL, NULL, as_bytes);
return _PyUnicodeError_GetParams(self, NULL, NULL,
start, NULL, NULL,
as_bytes);
}


Expand Down Expand Up @@ -3278,7 +3270,9 @@ static inline int
unicode_error_get_end_impl(PyObject *self, Py_ssize_t *end, int as_bytes)
{
assert(self != NULL);
return _PyUnicodeError_GetSliceParams(self, NULL, end, NULL, as_bytes);
return _PyUnicodeError_GetParams(self, NULL, NULL,
NULL, end, NULL,
as_bytes);
}


Expand Down
Loading
0