Skip to content

Commit 60d6379

Browse files
committed
logic simplification
1 parent a4efb0a commit 60d6379

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

Include/internal/pycore_pyerrors.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,7 @@ extern int _PyUnicodeError_GetParams(
196196
Py_ssize_t *objlen,
197197
Py_ssize_t *start,
198198
Py_ssize_t *end,
199-
Py_ssize_t *len,
200-
int as_bytes);
201-
202-
/* Specialization of _PyUnicodeError_GetParams(self, NULL, NULL, ...). */
203-
extern int _PyUnicodeError_GetSliceParams(
204-
PyObject *self,
205-
Py_ssize_t *start,
206-
Py_ssize_t *end,
207-
Py_ssize_t *len,
199+
Py_ssize_t *slen,
208200
int as_bytes);
209201

210202
#ifdef __cplusplus

Objects/exceptions.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,7 +3079,7 @@ assert_adjusted_unicode_error_len(Py_ssize_t ranlen, Py_ssize_t objlen)
30793079
* objlen The 'object' length.
30803080
* start The clipped 'start' attribute.
30813081
* end The clipped 'end' attribute.
3082-
* len The length of the slice described by the clipped 'start'
3082+
* slen The length of the slice described by the clipped 'start'
30833083
* and 'end' values. It always lies in [0, objlen].
30843084
*
30853085
* An output parameter can be NULL to indicate that
@@ -3096,7 +3096,7 @@ assert_adjusted_unicode_error_len(Py_ssize_t ranlen, Py_ssize_t objlen)
30963096
int
30973097
_PyUnicodeError_GetParams(PyObject *self,
30983098
PyObject **obj, Py_ssize_t *objlen,
3099-
Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t *len,
3099+
Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t *slen,
31003100
int as_bytes)
31013101
{
31023102
assert(self != NULL);
@@ -3113,7 +3113,7 @@ _PyUnicodeError_GetParams(PyObject *self,
31133113
}
31143114

31153115
Py_ssize_t start_value = -1;
3116-
if (start != NULL || len != NULL) {
3116+
if (start != NULL || slen != NULL) {
31173117
start_value = unicode_error_adjust_start(exc->start, n);
31183118
}
31193119
if (start != NULL) {
@@ -3122,17 +3122,17 @@ _PyUnicodeError_GetParams(PyObject *self,
31223122
}
31233123

31243124
Py_ssize_t end_value = -1;
3125-
if (end != NULL || len != NULL) {
3125+
if (end != NULL || slen != NULL) {
31263126
end_value = unicode_error_adjust_end(exc->end, n);
31273127
}
31283128
if (end != NULL) {
31293129
assert_adjusted_unicode_error_end(end_value, n);
31303130
*end = end_value;
31313131
}
31323132

3133-
if (len != NULL) {
3134-
*len = unicode_error_adjust_len(start_value, end_value, n);
3135-
assert_adjusted_unicode_error_len(*len, n);
3133+
if (slen != NULL) {
3134+
*slen = unicode_error_adjust_len(start_value, end_value, n);
3135+
assert_adjusted_unicode_error_len(*slen, n);
31363136
}
31373137

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

31473147

3148-
inline int
3149-
_PyUnicodeError_GetSliceParams(
3150-
PyObject *self,
3151-
Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t *len,
3152-
int as_bytes
3153-
) {
3154-
return _PyUnicodeError_GetParams(self, NULL, NULL, start, end, len,
3155-
as_bytes);
3156-
}
3157-
31583148
// --- PyUnicodeEncodeObject: 'encoding' getters ------------------------------
31593149
// Note: PyUnicodeTranslateError does not have an 'encoding' attribute.
31603150

@@ -3212,7 +3202,9 @@ static inline int
32123202
unicode_error_get_start_impl(PyObject *self, Py_ssize_t *start, int as_bytes)
32133203
{
32143204
assert(self != NULL);
3215-
return _PyUnicodeError_GetSliceParams(self, start, NULL, NULL, as_bytes);
3205+
return _PyUnicodeError_GetParams(self, NULL, NULL,
3206+
start, NULL, NULL,
3207+
as_bytes);
32163208
}
32173209

32183210

@@ -3278,7 +3270,9 @@ static inline int
32783270
unicode_error_get_end_impl(PyObject *self, Py_ssize_t *end, int as_bytes)
32793271
{
32803272
assert(self != NULL);
3281-
return _PyUnicodeError_GetSliceParams(self, NULL, end, NULL, as_bytes);
3273+
return _PyUnicodeError_GetParams(self, NULL, NULL,
3274+
NULL, end, NULL,
3275+
as_bytes);
32823276
}
32833277

32843278

0 commit comments

Comments
 (0)