Fix fixup() for unchanged unicode subtype
If maxchar_new == 0 and self is a unicode subtype, return u instead of duplicating u.
This commit is contained in:
parent
e6b2d4407a
commit
eaab604829
|
@ -9211,6 +9211,7 @@ fixup(PyObject *self,
|
||||||
{
|
{
|
||||||
PyObject *u;
|
PyObject *u;
|
||||||
Py_UCS4 maxchar_old, maxchar_new = 0;
|
Py_UCS4 maxchar_old, maxchar_new = 0;
|
||||||
|
PyObject *v;
|
||||||
|
|
||||||
u = PyUnicode_Copy(self);
|
u = PyUnicode_Copy(self);
|
||||||
if (u == NULL)
|
if (u == NULL)
|
||||||
|
@ -9222,9 +9223,19 @@ fixup(PyObject *self,
|
||||||
everything is fine. Otherwise we need to change the string kind
|
everything is fine. Otherwise we need to change the string kind
|
||||||
and re-run the fix function. */
|
and re-run the fix function. */
|
||||||
maxchar_new = fixfct(u);
|
maxchar_new = fixfct(u);
|
||||||
if (maxchar_new == 0)
|
|
||||||
/* do nothing, keep maxchar_new at 0 which means no changes. */;
|
if (maxchar_new == 0) {
|
||||||
else if (maxchar_new <= 127)
|
/* no changes */;
|
||||||
|
if (PyUnicode_CheckExact(self)) {
|
||||||
|
Py_DECREF(u);
|
||||||
|
Py_INCREF(self);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxchar_new <= 127)
|
||||||
maxchar_new = 127;
|
maxchar_new = 127;
|
||||||
else if (maxchar_new <= 255)
|
else if (maxchar_new <= 255)
|
||||||
maxchar_new = 255;
|
maxchar_new = 255;
|
||||||
|
@ -9233,21 +9244,12 @@ fixup(PyObject *self,
|
||||||
else
|
else
|
||||||
maxchar_new = MAX_UNICODE;
|
maxchar_new = MAX_UNICODE;
|
||||||
|
|
||||||
if (!maxchar_new && PyUnicode_CheckExact(self)) {
|
if (maxchar_new == maxchar_old)
|
||||||
/* fixfct should return TRUE if it modified the buffer. If
|
|
||||||
FALSE, return a reference to the original buffer instead
|
|
||||||
(to save space, not time) */
|
|
||||||
Py_INCREF(self);
|
|
||||||
Py_DECREF(u);
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
else if (maxchar_new == maxchar_old) {
|
|
||||||
return u;
|
return u;
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* In case the maximum character changed, we need to
|
/* In case the maximum character changed, we need to
|
||||||
convert the string to the new category. */
|
convert the string to the new category. */
|
||||||
PyObject *v = PyUnicode_New(PyUnicode_GET_LENGTH(self), maxchar_new);
|
v = PyUnicode_New(PyUnicode_GET_LENGTH(self), maxchar_new);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
Py_DECREF(u);
|
Py_DECREF(u);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -9263,12 +9265,10 @@ fixup(PyObject *self,
|
||||||
else {
|
else {
|
||||||
copy_characters(v, 0, u, 0, PyUnicode_GET_LENGTH(self));
|
copy_characters(v, 0, u, 0, PyUnicode_GET_LENGTH(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_DECREF(u);
|
Py_DECREF(u);
|
||||||
assert(_PyUnicode_CheckConsistency(v, 1));
|
assert(_PyUnicode_CheckConsistency(v, 1));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static Py_UCS4
|
static Py_UCS4
|
||||||
fixupper(PyObject *self)
|
fixupper(PyObject *self)
|
||||||
|
|
Loading…
Reference in New Issue