Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e30aa5

Browse files
author
Victor Stinner
committed
Fix misuse of PyUnicode_GET_SIZE() => PyUnicode_GET_LENGTH()
And PyUnicode_GetSize() => PyUnicode_GetLength()
1 parent f3ae620 commit 9e30aa5

10 files changed

Lines changed: 18 additions & 19 deletions

File tree

Modules/_csv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
207207
*target = '\0';
208208
if (src != Py_None) {
209209
Py_ssize_t len;
210-
len = PyUnicode_GetSize(src);
210+
len = PyUnicode_GetLength(src);
211211
if (len > 1) {
212212
PyErr_Format(PyExc_TypeError,
213213
"\"%s\" must be an 1-character string",

Modules/_datetimemodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ make_Zreplacement(PyObject *object, PyObject *tzinfoarg)
10801080
PyObject *tzinfo = get_tzinfo_member(object);
10811081
PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0);
10821082
_Py_IDENTIFIER(replace);
1083-
1083+
10841084
if (Zreplacement == NULL)
10851085
return NULL;
10861086
if (tzinfo == Py_None || tzinfo == NULL)
@@ -2673,7 +2673,7 @@ date_format(PyDateTime_Date *self, PyObject *args)
26732673
return NULL;
26742674

26752675
/* if the format is zero length, return str(self) */
2676-
if (PyUnicode_GetSize(format) == 0)
2676+
if (PyUnicode_GetLength(format) == 0)
26772677
return PyObject_Str((PyObject *)self);
26782678

26792679
return _PyObject_CallMethodId((PyObject *)self, &PyId_strftime, "O", format);

Modules/_gestalt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int
3333
convert_to_OSType(PyObject *v, OSType *pr)
3434
{
3535
uint32_t tmp;
36-
if (!PyUnicode_Check(v) || PyUnicode_GetSize(v) != 4) {
36+
if (!PyUnicode_Check(v) || PyUnicode_GetLength(v) != 4) {
3737
PyErr_SetString(PyExc_TypeError,
3838
"OSType arg must be string of 4 chars");
3939
return 0;

Modules/_io/stringio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ stringio_init(stringio *self, PyObject *args, PyObject *kwds)
730730
and copy it */
731731
self->string_size = 0;
732732
if (value && value != Py_None)
733-
value_len = PyUnicode_GetSize(value);
733+
value_len = PyUnicode_GetLength(value);
734734
else
735735
value_len = 0;
736736
if (value_len > 0) {

Modules/_io/textio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,7 @@ textiowrapper_seek(textio *self, PyObject *args)
21442144
textiowrapper_set_decoded_chars(self, decoded);
21452145

21462146
/* Skip chars_to_skip of the decoded characters. */
2147-
if (PyUnicode_GetSize(self->decoded_chars) < cookie.chars_to_skip) {
2147+
if (PyUnicode_GetLength(self->decoded_chars) < cookie.chars_to_skip) {
21482148
PyErr_SetString(PyExc_IOError, "can't restore logical file position");
21492149
goto fail;
21502150
}
@@ -2208,7 +2208,7 @@ textiowrapper_tell(textio *self, PyObject *args)
22082208
goto fail;
22092209

22102210
if (self->decoder == NULL || self->snapshot == NULL) {
2211-
assert (self->decoded_chars == NULL || PyUnicode_GetSize(self->decoded_chars) == 0);
2211+
assert (self->decoded_chars == NULL || PyUnicode_GetLength(self->decoded_chars) == 0);
22122212
return posobj;
22132213
}
22142214

Objects/bytesobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,7 @@ _PyBytes_FormatLong(PyObject *val, int flags, int prec, int type,
29412941
PyErr_BadInternalCall();
29422942
return NULL;
29432943
}
2944-
llen = PyUnicode_GetSize(result);
2944+
llen = PyUnicode_GetLength(result);
29452945
if (llen > INT_MAX) {
29462946
PyErr_SetString(PyExc_ValueError,
29472947
"string too large in _PyBytes_FormatLong");

Objects/exceptions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start)
12731273
if (!obj)
12741274
return -1;
12751275
*start = ((PyUnicodeErrorObject *)exc)->start;
1276-
size = PyUnicode_GET_SIZE(obj);
1276+
size = PyUnicode_GET_LENGTH(obj);
12771277
if (*start<0)
12781278
*start = 0; /*XXX check for values <0*/
12791279
if (*start>=size)
@@ -1341,7 +1341,7 @@ PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
13411341
if (!obj)
13421342
return -1;
13431343
*end = ((PyUnicodeErrorObject *)exc)->end;
1344-
size = PyUnicode_GET_SIZE(obj);
1344+
size = PyUnicode_GET_LENGTH(obj);
13451345
if (*end<1)
13461346
*end = 1;
13471347
if (*end>size)

Objects/unicodeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4784,7 +4784,7 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
47844784
if (PyBytes_Check(rep))
47854785
repsize = PyBytes_GET_SIZE(rep);
47864786
else
4787-
repsize = PyUnicode_GET_SIZE(rep);
4787+
repsize = PyUnicode_GET_LENGTH(rep);
47884788

47894789
if (repsize > 4) {
47904790
Py_ssize_t offset;
@@ -8187,7 +8187,7 @@ charmap_encoding_error(
81878187
Py_DECREF(repunicode);
81888188
return -1;
81898189
}
8190-
repsize = PyUnicode_GET_SIZE(repunicode);
8190+
repsize = PyUnicode_GET_LENGTH(repunicode);
81918191
data = PyUnicode_DATA(repunicode);
81928192
kind = PyUnicode_KIND(repunicode);
81938193
for (index = 0; index < repsize; index++) {

PC/import_nt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ _PyWin_FindRegisteredModule(PyObject *moduleName,
8686
suffix = PyUnicode_FromString(fdp->suffix);
8787
if (suffix == NULL)
8888
return NULL;
89-
wsuffix = PyUnicode_AsUnicode(suffix);
89+
wsuffix = PyUnicode_AsUnicodeAndSize(suffix, &extLen);
9090
if (wsuffix == NULL) {
9191
Py_DECREF(suffix);
9292
return NULL;
9393
}
94-
extLen = PyUnicode_GET_SIZE(suffix);
9594
if ((Py_ssize_t)modNameSize > extLen &&
9695
_wcsnicmp(pathBuf + ((Py_ssize_t)modNameSize-extLen-1),
9796
wsuffix,

Python/_warnings.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ normalize_module(PyObject *filename)
203203

204204
mod_str = _PyUnicode_AsString(filename);
205205
if (mod_str == NULL)
206-
return NULL;
207-
len = PyUnicode_GetSize(filename);
206+
return NULL;
207+
len = PyUnicode_GetLength(filename);
208208
if (len < 0)
209209
return NULL;
210210
if (len >= 3 &&
211211
strncmp(mod_str + (len - 3), ".py", 3) == 0) {
212-
module = PyUnicode_FromStringAndSize(mod_str, len-3);
212+
module = PyUnicode_Substring(filename, 0, len-3);
213213
}
214214
else {
215215
module = filename;
@@ -506,7 +506,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
506506
if (PyUnicode_READY(*filename))
507507
goto handle_error;
508508

509-
len = PyUnicode_GetSize(*filename);
509+
len = PyUnicode_GetLength(*filename);
510510
kind = PyUnicode_KIND(*filename);
511511
data = PyUnicode_DATA(*filename);
512512

@@ -690,7 +690,7 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
690690
}
691691

692692
/* Split the source into lines. */
693-
source_list = PyObject_CallMethodObjArgs(source,
693+
source_list = PyObject_CallMethodObjArgs(source,
694694
PyId_splitlines.object,
695695
NULL);
696696
Py_DECREF(source);

0 commit comments

Comments
 (0)