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

Skip to content

Commit 62f4598

Browse files
committed
Rename size parameter to nbytes
1 parent 1c78103 commit 62f4598

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

Doc/c-api/unicode.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,19 +341,19 @@ APIs:
341341
.. versionadded:: 3.3
342342
343343
344-
.. c:function:: const void* PyUnicode_Export(PyObject *unicode, uint32_t requested_formats, Py_ssize_t *size, uint32_t *format)
344+
.. c:function:: const void* PyUnicode_Export(PyObject *unicode, uint32_t requested_formats, Py_ssize_t *nbytes, uint32_t *format)
345345
346346
Export the contents of the *unicode* string in one of the requested format
347347
*requested_formats*.
348348
349-
* On success, set *\*size* and *\*format*, and return the contents.
349+
* On success, set *\*nbytes* and *\*format*, and return the contents.
350350
* On error, set an exception and return ``NULL``.
351351
352352
The contents is valid as long as *unicode* is valid.
353353
354354
The export must be released by :c:func:`PyUnicode_ReleaseExport`.
355355
356-
*unicode*, *size* and *format* must not be NULL.
356+
*unicode*, *nbytes* and *format* must not be NULL.
357357
358358
Available formats:
359359
@@ -382,14 +382,14 @@ APIs:
382382
.. versionadded:: 3.14
383383
384384
385-
.. c:function:: PyObject* PyUnicode_Import(const void *data, Py_ssize_t size, uint32_t format)
385+
.. c:function:: PyObject* PyUnicode_Import(const void *data, Py_ssize_t nbytes, uint32_t format)
386386
387387
Import a string from the *format* format.
388388
389389
* Return a reference to a new string object on success.
390390
* Set an exception and return ``NULL`` on error.
391391
392-
*data* must not be NULL. *size* must be positive or zero.
392+
*data* must not be NULL. *nbytes* must be positive or zero.
393393
394394
See :c:func:`PyUnicode_Export` for the available formats.
395395

Include/unicodeobject.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ PyAPI_FUNC(PyObject *) PyUnicode_InternFromString(
255255
#define PyUnicode_FORMAT_UTF8 0x10
256256

257257
// Get the content of a string in the requested format:
258-
// - Return the content, set '*size' and '*format' on success.
258+
// - Return the content, set '*nbytes' and '*format' on success.
259259
// - Set an exception and return NULL on error.
260260
//
261261
// The export must be released by PyUnicode_ReleaseExport().
262262
PyAPI_FUNC(const void*) PyUnicode_Export(
263263
PyObject *unicode,
264264
uint32_t requested_formats,
265-
Py_ssize_t *size,
265+
Py_ssize_t *nbytes,
266266
uint32_t *format);
267267

268268
// Release an export created by PyUnicode_Export().
@@ -276,7 +276,7 @@ PyAPI_FUNC(void) PyUnicode_ReleaseExport(
276276
// - Set an exception and return NULL on error.
277277
PyAPI_FUNC(PyObject*) PyUnicode_Import(
278278
const void *data,
279-
Py_ssize_t size,
279+
Py_ssize_t nbytes,
280280
uint32_t format);
281281

282282
/* --- wchar_t support for platforms which support it --------------------- */

Objects/unicodeobject.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@ _PyUnicode_FromUCS4(const Py_UCS4 *u, Py_ssize_t size)
20992099

21002100
const void*
21012101
PyUnicode_Export(PyObject *unicode, uint32_t requested_formats,
2102-
Py_ssize_t *size, uint32_t *format)
2102+
Py_ssize_t *nbytes, uint32_t *format)
21032103
{
21042104
if (!PyUnicode_Check(unicode)) {
21052105
PyErr_Format(PyExc_TypeError, "must be str, not %T", unicode);
@@ -2112,7 +2112,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats,
21122112
&& (requested_formats & PyUnicode_FORMAT_ASCII))
21132113
{
21142114
*format = PyUnicode_FORMAT_ASCII;
2115-
*size = len;
2115+
*nbytes = len;
21162116
return PyUnicode_1BYTE_DATA(unicode);
21172117
}
21182118

@@ -2122,7 +2122,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats,
21222122
&& (requested_formats & PyUnicode_FORMAT_UCS1))
21232123
{
21242124
*format = PyUnicode_FORMAT_UCS1;
2125-
*size = len;
2125+
*nbytes = len;
21262126
return PyUnicode_1BYTE_DATA(unicode);
21272127
}
21282128

@@ -2131,7 +2131,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats,
21312131
&& (requested_formats & PyUnicode_FORMAT_UCS2))
21322132
{
21332133
*format = PyUnicode_FORMAT_UCS2;
2134-
*size = len * 2;
2134+
*nbytes = len * 2;
21352135
return PyUnicode_2BYTE_DATA(unicode);
21362136
}
21372137

@@ -2152,7 +2152,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats,
21522152
ucs2[len] = 0;
21532153

21542154
*format = PyUnicode_FORMAT_UCS2;
2155-
*size = len * 2;
2155+
*nbytes = len * 2;
21562156
return ucs2;
21572157
}
21582158

@@ -2161,7 +2161,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats,
21612161
&& (requested_formats & PyUnicode_FORMAT_UCS4))
21622162
{
21632163
*format = PyUnicode_FORMAT_UCS4;
2164-
*size = len * 4;
2164+
*nbytes = len * 4;
21652165
return PyUnicode_4BYTE_DATA(unicode);
21662166
}
21672167

@@ -2172,14 +2172,14 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats,
21722172
goto error;
21732173
}
21742174
*format = PyUnicode_FORMAT_UCS4;
2175-
*size = len * 4;
2175+
*nbytes = len * 4;
21762176
return ucs4;
21772177
}
21782178

21792179
// Convert to UTF-8
21802180
if (requested_formats & PyUnicode_FORMAT_UTF8) {
21812181
// Encode UCS1, UCS2 or UCS4 to UTF-8
2182-
const char *utf8 = PyUnicode_AsUTF8AndSize(unicode, size);
2182+
const char *utf8 = PyUnicode_AsUTF8AndSize(unicode, nbytes);
21832183
if (utf8 == NULL) {
21842184
goto error;
21852185
}
@@ -2190,7 +2190,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats,
21902190
PyErr_Format(PyExc_ValueError, "unable to find a matching export format");
21912191

21922192
error:
2193-
*size = 0;
2193+
*nbytes = 0;
21942194
*format = 0;
21952195
return NULL;
21962196
}
@@ -2221,44 +2221,43 @@ PyUnicode_ReleaseExport(PyObject *unicode, const void* data,
22212221
}
22222222

22232223
PyObject*
2224-
PyUnicode_Import(const void *data, Py_ssize_t size,
2224+
PyUnicode_Import(const void *data, Py_ssize_t nbytes,
22252225
uint32_t format)
22262226
{
2227-
if (size < 0) {
2228-
PyErr_SetString(PyExc_ValueError, "Negative size");
2227+
if (nbytes < 0) {
2228+
PyErr_SetString(PyExc_ValueError, "Negative nbytes");
22292229
return NULL;
22302230
}
22312231

22322232
switch (format)
22332233
{
22342234
case PyUnicode_FORMAT_ASCII:
2235-
return PyUnicode_DecodeASCII((const char*)data, size, NULL);
2235+
return PyUnicode_DecodeASCII((const char*)data, nbytes, NULL);
22362236

22372237
case PyUnicode_FORMAT_UCS1:
2238-
return _PyUnicode_FromUCS1(data, size);
2238+
return _PyUnicode_FromUCS1(data, nbytes);
22392239

22402240
case PyUnicode_FORMAT_UCS2:
2241-
if (size % 2) {
2242-
PyErr_Format(PyExc_ValueError, "size must be a multiple of 2: %zd",
2243-
size);
2241+
if (nbytes % 2) {
2242+
PyErr_Format(PyExc_ValueError, "nbytes must be a multiple of 2: %zd",
2243+
nbytes);
22442244
return NULL;
22452245
}
2246-
return _PyUnicode_FromUCS2(data, size / 2);
2246+
return _PyUnicode_FromUCS2(data, nbytes / 2);
22472247

22482248
case PyUnicode_FORMAT_UCS4:
2249-
if (size % 4) {
2250-
PyErr_Format(PyExc_ValueError, "size must be a multiple of 4: %zd",
2251-
size);
2249+
if (nbytes % 4) {
2250+
PyErr_Format(PyExc_ValueError, "nbytes must be a multiple of 4: %zd",
2251+
nbytes);
22522252
return NULL;
22532253
}
2254-
return _PyUnicode_FromUCS4(data, size / 4);
2254+
return _PyUnicode_FromUCS4(data, nbytes / 4);
22552255

22562256
case PyUnicode_FORMAT_UTF8:
2257-
return PyUnicode_DecodeUTF8((const char*)data, size, NULL);
2257+
return PyUnicode_DecodeUTF8((const char*)data, nbytes, NULL);
22582258

22592259
default:
2260-
PyErr_Format(PyExc_ValueError, "unknown format: %i",
2261-
format);
2260+
PyErr_Format(PyExc_ValueError, "unknown format: %i", format);
22622261
return NULL;
22632262
}
22642263
}

0 commit comments

Comments
 (0)