mirror of
https://github.com/python/cpython.git
synced 2025-12-11 11:31:05 +00:00
Change PyUnicode_EncodeUTF7() to return a bytes object.
This commit is contained in:
parent
ce32db3ab5
commit
51ab414627
1 changed files with 7 additions and 4 deletions
|
|
@ -1149,13 +1149,13 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
|
||||||
char * start;
|
char * start;
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return PyString_FromStringAndSize(NULL, 0);
|
return PyBytes_FromStringAndSize(NULL, 0);
|
||||||
|
|
||||||
v = PyString_FromStringAndSize(NULL, cbAllocated);
|
v = PyBytes_FromStringAndSize(NULL, cbAllocated);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
start = out = PyString_AS_STRING(v);
|
start = out = PyBytes_AS_STRING(v);
|
||||||
for (;i < size; ++i) {
|
for (;i < size; ++i) {
|
||||||
Py_UNICODE ch = s[i];
|
Py_UNICODE ch = s[i];
|
||||||
|
|
||||||
|
|
@ -1221,7 +1221,10 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
|
||||||
*out++ = '-';
|
*out++ = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
_PyString_Resize(&v, out - start);
|
if (PyBytes_Resize(v, out - start)) {
|
||||||
|
Py_DECREF(v);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue