mirror of
https://github.com/python/cpython.git
synced 2025-10-22 22:53:06 +00:00
Cleanup PyUnicode_Append()
* Check also that right is a Unicode object * call directly resize_compact() instead of unicode_resize() for a more explicit error handling, and to avoid testing some properties twice (ex: unicode_modifiable())
This commit is contained in:
parent
4560f9c63f
commit
f033510fee
1 changed files with 14 additions and 18 deletions
|
@ -10671,7 +10671,8 @@ PyUnicode_Append(PyObject **p_left, PyObject *right)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
left = *p_left;
|
left = *p_left;
|
||||||
if (right == NULL || left == NULL || !PyUnicode_Check(left)) {
|
if (right == NULL || left == NULL
|
||||||
|
|| !PyUnicode_Check(left) || !PyUnicode_Check(right)) {
|
||||||
if (!PyErr_Occurred())
|
if (!PyErr_Occurred())
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -10711,17 +10712,12 @@ PyUnicode_Append(PyObject **p_left, PyObject *right)
|
||||||
&& !(PyUnicode_IS_ASCII(left) && !PyUnicode_IS_ASCII(right)))
|
&& !(PyUnicode_IS_ASCII(left) && !PyUnicode_IS_ASCII(right)))
|
||||||
{
|
{
|
||||||
/* append inplace */
|
/* append inplace */
|
||||||
if (unicode_resize(p_left, new_len) != 0) {
|
res = resize_compact(left, new_len);
|
||||||
/* XXX if _PyUnicode_Resize() fails, 'left' has been
|
if (res == NULL)
|
||||||
* deallocated so it cannot be put back into
|
|
||||||
* 'variable'. The MemoryError is raised when there
|
|
||||||
* is no value in 'variable', which might (very
|
|
||||||
* remotely) be a cause of incompatibilities.
|
|
||||||
*/
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
/* copy 'right' into the newly allocated area of 'left' */
|
/* copy 'right' into the newly allocated area of 'res' (left) */
|
||||||
_PyUnicode_FastCopyCharacters(*p_left, left_len, right, 0, right_len);
|
_PyUnicode_FastCopyCharacters(res, left_len, right, 0, right_len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
maxchar = PyUnicode_MAX_CHAR_VALUE(left);
|
maxchar = PyUnicode_MAX_CHAR_VALUE(left);
|
||||||
|
@ -10735,8 +10731,8 @@ PyUnicode_Append(PyObject **p_left, PyObject *right)
|
||||||
_PyUnicode_FastCopyCharacters(res, 0, left, 0, left_len);
|
_PyUnicode_FastCopyCharacters(res, 0, left, 0, left_len);
|
||||||
_PyUnicode_FastCopyCharacters(res, left_len, right, 0, right_len);
|
_PyUnicode_FastCopyCharacters(res, left_len, right, 0, right_len);
|
||||||
Py_DECREF(left);
|
Py_DECREF(left);
|
||||||
*p_left = res;
|
|
||||||
}
|
}
|
||||||
|
*p_left = res;
|
||||||
assert(_PyUnicode_CheckConsistency(*p_left, 1));
|
assert(_PyUnicode_CheckConsistency(*p_left, 1));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue