8000 gh-92536: Remove PyUnicode_READY() calls (#105210) · python/cpython@ef30093 · GitHub
[go: up one dir, main page]

Skip to content

Commit ef30093

Browse files
authored
gh-92536: Remove PyUnicode_READY() calls (#105210)
Since Python 3.12, PyUnicode_READY() does nothing and always returns 0.
1 parent cbb9ba8 commit ef30093

32 files changed

+5
-186
lines changed

Modules/_csv.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ _set_char_or_none(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt
266266
name);
267267
return -1;
268268
}
269-
/* PyUnicode_READY() is called in PyUnicode_GetLength() */
270269
*target = PyUnicode_READ_CHAR(src, 0);
271270
}
272271
}
@@ -296,7 +295,6 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
296295
name);
297296
return -1;
298297
}
299-
/* PyUnicode_READY() is called in PyUnicode_GetLength() */
300298
*target = PyUnicode_READ_CHAR(src, 0);
301299
}
302300
return 0;
@@ -316,8 +314,6 @@ _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
316314
return -1;
317315
}
318316
else {
319-
if (PyUnicode_READY(src) == -1)
320-
return -1;
321317
Py_XSETREF(*target, Py_NewRef(src));
322318
}
323319
}
@@ -904,10 +900,6 @@ Reader_iternext(ReaderObj *self)
904900
Py_DECREF(lineobj);
905901
return NULL;
906902
}
907-
if (PyUnicode_READY(lineobj) == -1) {
908-
Py_DECREF(lineobj);
909-
return NULL;
910-
}
911903
++self->line_num;
912904
kind = PyUnicode_KIND(lineobj);
913905
data = PyUnicode_DATA(lineobj);
@@ -1185,8 +1177,6 @@ join_append(WriterObj *self, PyObject *field, int quoted)
11851177
Py_ssize_t rec_len;
11861178

11871179
if (field != NULL) {
1188-
if (PyUnicode_READY(field) == -1)
1189-
return 0;
11901180
field_kind = PyUnicode_KIND(field);
11911181
field_data = PyUnicode_DATA(field);
11921182
field_len = PyUnicode_GET_LENGTH(field);
@@ -1515,8 +1505,6 @@ csv_register_dialect(PyObject *module, PyObject *args, PyObject *kwargs)
15151505
"dialect name must be a string");
15161506
return NULL;
15171507
}
1518-
if (PyUnicode_READY(name_obj) == -1)
1519-
return NULL;
15201508
dialect = _call_dialect(module_state, dialect_obj, kwargs);
15211509
if (dialect == NULL)
15221510
return NULL;

Modules/_datetimemodule.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,9 +2901,6 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
29012901
}
29022902
}
29032903
else if (PyUnicode_Check(state)) {
2904-
if (PyUnicode_READY(state)) {
2905-
return NULL;
2906-
}
29072904
if (PyUnicode_GET_LENGTH(state) == _PyDateTime_DATE_DATASIZE &&
29082905
MONTH_IS_SANE(PyUnicode_READ_CHAR(state, 2)))
2909 10000 2906
{
@@ -4234,9 +4231,6 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
42344231
}
42354232
}
42364233
else if (PyUnicode_Check(state)) {
4237-
if (PyUnicode_READY(state)) {
4238-
return NULL;
4239-
}
42404234
if (PyUnicode_GET_LENGTH(state) == _PyDateTime_TIME_DATASIZE &&
42414235
(0x7F & PyUnicode_READ_CHAR(state, 0)) < 24)
42424236
{
@@ -4909,9 +4903,6 @@ datetime_new(PyTypeObject *type, PyObject *args, PyObject *kw)
49094903
}
49104904
}
49114905
else if (PyUnicode_Check(state)) {
4912-
if (PyUnicode_READY(state)) {
4913-
return NULL;
4914-
}
49154906
if (PyUnicode_GET_LENGTH(state) == _PyDateTime_DATETIME_DATASIZE &&
49164907
MONTH_IS_SANE(PyUnicode_READ_CHAR(state, 2) & 0x7F))
49174908
{

Modules/_decimal/_decimal.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,10 +1934,6 @@ numeric_as_ascii(PyObject *u, int strip_ws, int ignore_underscores)
19341934
Py_ssize_t j, len;
19351935
int d;
19361936

1937-
if (PyUnicode_READY(u) == -1) {
1938-
return NULL;
1939-
}
1940-
19411937
kind = PyUnicode_KIND(u);
19421938
data = PyUnicode_DATA(u);
19431939
len = PyUnicode_GET_LENGTH(u);

Modules/_elementtree.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,6 @@ _elementtree_Element_iter_impl(ElementObject *self, PyTypeObject *cls,
14481448
/*[clinic end generated code: output=bff29dc5d4566c68 input=f6944c48d3f84c58]*/
14491449
{
14501450
if (PyUnicode_Check(tag)) {
1451-
if (PyUnicode_READY(tag) < 0)
1452-
return NULL;
14531451
if (PyUnicode_GET_LENGTH(tag) == 1 && PyUnicode_READ_CHAR(tag, 0) == '*')
14541452
tag = Py_None;
14551453
}

Modules/_hashopenssl.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,9 +1988,6 @@ _hashlib_compare_digest_impl(PyObject *module, PyObject *a, PyObject *b)
19881988

19891989
/* ASCII unicode string */
19901990
if(PyUnicode_Check(a) && PyUnicode_Check(b)) {
1991-
if (PyUnicode_READY(a) == -1 || PyUnicode_READY(b) == -1) {
1992-
return NULL;
1993-
}
19941991
if (!PyUnicode_IS_ASCII(a) || !PyUnicode_IS_ASCII(b)) {
19951992
PyErr_SetString(PyExc_TypeError,
19961993
"comparing strings with non-ASCII characters is "

Modules/_io/stringio.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ write_str(stringio *self, PyObject *obj)
200200
return -1;
201201

202202
assert(PyUnicode_Check(decoded));
203-
if (PyUnicode_READY(decoded)) {
204-
Py_DECREF(decoded);
205-
return -1;
206-
}
207203
len = PyUnicode_GET_LENGTH(decoded);
208204
assert(len >= 0);
209205

@@ -542,8 +538,6 @@ _io_StringIO_write(stringio *self, PyObject *obj)
542538
Py_TYPE(obj)->tp_name);
543539
return NULL;
544540
}
545-
if (PyUnicode_READY(obj))
546-
return NULL;
547541
CHECK_CLOSED(self);
548542
size = PyUnicode_GET_LENGTH(obj);
549543

Modules/_io/textio.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,6 @@ check_decoded(PyObject *decoded)
288288
Py_DECREF(decoded);
289289
return -1;
290290
}
291-
if (PyUnicode_READY(decoded) < 0) {
292-
Py_DECREF(decoded);
293-
return -1;
294-
}
295291
return 0;
296292
}
297293

@@ -1611,9 +1607,6 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
16111607
int haslf = 0;
16121608
int needflush = 0, text_needflush = 0;
16131609

1614-
if (PyUnicode_READY(text) == -1)
1615-
return NULL;
1616-
16171610
CHECK_ATTACHED(self);
16181611
CHECK_CLOSED(self);
16191612

@@ -1972,8 +1965,6 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
19721965
result = textiowrapper_get_decoded_chars(self, n);
19731966
if (result == NULL)
19741967
goto fail;
1975-
if (PyUnicode_READY(result) == -1)
1976-
goto fail;
19771968
remaining -= PyUnicode_GET_LENGTH(result);
19781969

19791970
/* Keep reading chunks until we have n characters to return */
@@ -2185,8 +2176,6 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
21852176
Py_CLEAR(remaining);
21862177
if (line == NULL)
21872178
goto error;
2188-
if (PyUnicode_READY(line) == -1)
2189-
goto error;
21902179
}
21912180

21922181
ptr = PyUnicode_DATA(line);
@@ -3106,7 +3095,7 @@ textiowrapper_iternext(textio *self)
31063095
}
31073096
}
31083097

3109-
if (line == NULL || PyUnicode_READY(line) == -1)
3098+
if (line == NULL)
31103099
return NULL;
31113100

31123101
if (PyUnicode_GET_LENGTH(line) == 0) {

Modules/_json.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ ascii_escape_unicode(PyObject *pystr)
152152
Py_UCS1 *output;
153153
int kind;
154154

155-
if (PyUnicode_READY(pystr) == -1)
156-
return NULL;
157-
158155
input_chars = PyUnicode_GET_LENGTH(pystr);
159156
input = PyUnicode_DATA(pystr);
160157
kind = PyUnicode_KIND(pystr);
@@ -218,9 +215,6 @@ escape_unicode(PyObject *pystr)
218215
int kind;
219216
Py_UCS4 maxchar;
220217

221-
if (PyUnicode_READY(pystr) == -1)
222-
return NULL;
223-
224218
maxchar = PyUnicode_MAX_CHAR_VALUE(pystr);
225219
input_chars = PyUnicode_GET_LENGTH(pystr);
226220
input = PyUnicode_DATA(pystr);
@@ -377,9 +371,6 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
377371
const void *buf;
378372
int kind;
379373

380-
if (PyUnicode_READY(pystr) == -1)
381-
return 0;
382-
383374
_PyUnicodeWriter writer;
384375
_PyUnicodeWriter_Init(&writer);
385376
writer.overallocate = 1;
@@ -675,9 +666,6 @@ _parse_object_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ss
675666
int has_pairs_hook = (s->object_pairs_hook != Py_None);
676667
Py_ssize_t next_idx;
677668

678-
if (PyUnicode_READY(pystr) == -1)
679-
return NULL;
680-
681669
str = PyUnicode_DATA(pystr);
682670
kind = PyUnicode_KIND(pystr);
683671
end_idx = PyUnicode_GET_LENGTH(pystr) - 1;
@@ -801,9 +789,6 @@ _parse_array_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssi
801789
PyObject *rval;
802790
Py_ssize_t next_idx;
803791

804-
if (PyUnicode_READY(pystr) == -1)
805-
return NULL;
806-
807792
rval = PyList_New(0);
808793
if (rval == NULL)
809794
return NULL;
@@ -906,9 +891,6 @@ _match_number_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t start, Py_
906891
PyObject *numstr = NULL;
907892
PyObject *custom_func;
908893

909-
if (PyUnicode_READY(pystr) == -1)
910-
return NULL;
911-
912894
str = PyUnicode_DATA(pystr);
913895
kind = PyUnicode_KIND(pystr);
914896
end_idx = PyUnicode_GET_LENGTH(pystr) - 1;
@@ -1018,9 +1000,6 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
10181000
int kind;
10191001
Py_ssize_t length;
10201002

1021-
if (PyUnicode_READY(pystr) == -1)
1022-
return NULL;
1023-
10241003
str = PyUnicode_DATA(pystr);
10251004
kind = PyUnicode_KIND(pystr);
10261005
length = PyUnicode_GET_LENGTH(pystr);

Modules/_operator.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,6 @@ _operator__compare_digest_impl(PyObject *module, PyObject *a, PyObject *b)
823823

824824
/* ASCII unicode string */
825825
if(PyUnicode_Check(a) && PyUnicode_Check(b)) {
826-
if (PyUnicode_READY(a) == -1 || PyUnicode_READY(b) == -1) {
827-
return NULL;
828-
}
829826
if (!PyUnicode_IS_ASCII(a) || !PyUnicode_IS_ASCII(b)) {
830827
PyErr_SetString(PyExc_TypeError,
831828
"comparing strings with non-ASCII characters is "
@@ -1234,10 +1231,6 @@ attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
12341231
Py_DECREF(attr);
12351232
return NULL;
12361233
}
1237-
if (PyUnicode_READY(item)) {
1238-
Py_DECREF(attr);
1239-
return NULL;
1240-
}
12411234
Py_ssize_t item_len = PyUnicode_GET_LENGTH(item);
12421235
int kind = PyUnicode_KIND(item);
12431236
const void *data = PyUnicode_DATA(item);

Modules/_pickle.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,9 +2602,6 @@ raw_unicode_escape(PyObject *obj)
26022602
int kind;
26032603
_PyBytesWriter writer;
26042604

2605-
if (PyUnicode_READY(obj))
2606-
return NULL;
2607-
26082605
_PyBytesWriter_Init(&writer);
26092606

26102607
size = PyUnicode_GET_LENGTH(obj);
@@ -2674,9 +2671,6 @@ write_unicode_binary(PicklerObject *self, PyObject *obj)
26742671
Py_ssize_t size;
26752672
const char *data;
26762673

2677-
if (PyUnicode_READY(obj))
2678-
return -1;
2679-
26802674
data = PyUnicode_AsUTF8AndSize(obj, &size);
26812675
if (data == NULL) {
26822676
/* Issue #8383: for strings with lone surrogates, fallback on the

Modules/_sre/sre.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ getstring(PyObject* string, Py_ssize_t* p_length,
374374
/* Unicode objects do not support the buffer API. So, get the data
375375
directly instead. */
376376
if (PyUnicode_Check(string)) {
377-
if (PyUnicode_READY(string) == -1)
378-
return NULL;
379377
*p_length = PyUnicode_GET_LENGTH(string);
380378
*p_charsize = PyUnicode_KIND(string);
381379
*p_isbytes = 0;

Modules/_tkinter.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,6 @@ AsObj(PyObject *value)
962962
}
963963

964964
if (PyUnicode_Check(value)) {
965-
if (PyUnicode_READY(value) == -1)
966-
return NULL;
967-
968965
Py_ssize_t size = PyUnicode_GET_LENGTH(value);
969966
if (size == 0) {
970967
return Tcl_NewStringObj("", 0);

Modules/binascii.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ ascii_buffer_converter(PyObject *arg, Py_buffer *buf)
170170
return 1;
171171
}
172172
if (PyUnicode_Check(arg)) {
173-
if (PyUnicode_READY(arg) < 0)
174-
return 0;
175173
if (!PyUnicode_IS_ASCII(arg)) {
176174
PyErr_SetString(PyExc_ValueError,
177175
"string argument should contain only ASCII characters");

Modules/cjkcodecs/multibytecodec.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,6 @@ multibytecodec_encode(const MultibyteCodec *codec,
490490
int kind;
491491
const void *data;
492492

493-
if (PyUnicode_READY(text) < 0)
494-
return NULL;
495493
datalen = PyUnicode_GET_LENGTH(text);
496494

497495
if (datalen == 0 && !(flags & MBENC_RESET))
@@ -603,10 +601,6 @@ _multibytecodec_MultibyteCodec_encode_impl(MultibyteCodecObject *self,
603601
}
604602
}
605603

606-
if (PyUnicode_READY(input) < 0) {
607-
Py_XDECREF(ucvt);
608-
return NULL;
609-
}
610604
datalen = PyUnicode_GET_LENGTH(input);
611605

612606
errorcb = internal_error_callback(errors);
@@ -809,8 +803,6 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
809803

810804
inbuf = Py_NewRef(unistr);
811805
}
812-
if (PyUnicode_READY(inbuf) < 0)
813-
goto errorexit;
814806
inpos = 0;
815807
datalen = PyUnicode_GET_LENGTH(inbuf);
816808< 10000 div class="diff-text-inner">

Modules/pyexpat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ PyUnknownEncodingHandler(void *encodingHandlerData,
11091109
return XML_STATUS_ERROR;
11101110

11111111
u = PyUnicode_Decode((const char*) template_buffer, 256, name, "replace");
1112-
if (u == NULL || PyUnicode_READY(u)) {
1112+
if (u == NULL) {
11131113
Py_XDECREF(u);
11141114
return XML_STATUS_ERROR;
11151115
}

Modules/socketmodule.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,9 +1717,6 @@ idna_converter(PyObject *obj, struct maybe_idna *data)
17171717
len = PyByteArray_Size(obj);
17181718
}
17191719
else if (PyUnicode_Check(obj)) {
1720-
if (PyUnicode_READY(obj) == -1) {
1721-
return 0;
1722-
}
17231720
if (PyUnicode_IS_COMPACT_ASCII(obj)) {
17241721
data->buf = PyUnicode_DATA(obj);
17251722
len = PyUnicode_GET_LENGTH(obj);

Modules/unicodedata.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,10 +864,6 @@ unicodedata_UCD_is_normalized_impl(PyObject *self, PyObject *form,
864864
PyObject *input)
865865
/*[clinic end generated code: output=11e5a3694e723ca5 input=a544f14cea79e508]*/
866866
{
867-
if (PyUnicode_READY(input) == -1) {
868-
return NULL;
869-
}
870-
871867
if (PyUnicode_GET_LENGTH(input) == 0) {
872868
/* special case empty input strings. */
873869
Py_RETURN_TRUE;

Objects/bytesobject.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,8 +2367,6 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray)
23672367
writer.use_bytearray = use_bytearray;
23682368

23692369
assert(PyUnicode_Check(string));
2370-
if (PyUnicode_READY(string))
2371-
return NULL;
23722370
hexlen = PyUnicode_GET_LENGTH(string);
23732371

23742372
if (!PyUnicode_IS_ASCII(string)) {

0 commit comments

Comments
 (0)
0