Skip to content

Commit 31c5107

Browse files
Changes
1 parent 1c9e55a commit 31c5107

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

Modules/_codecsmodule.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,30 +1048,19 @@ _codecs__normalize_encoding_impl(PyObject *module, PyObject *encoding)
10481048
return NULL;
10491049
}
10501050

1051-
PyUnicodeWriter *writer = PyUnicodeWriter_Create(len + 1);
1052-
if (writer == NULL) {
1053-
return NULL;
1054-
}
1055-
10561051
char *normalized = PyMem_Malloc(len + 1);
10571052
if (normalized == NULL) {
1058-
PyUnicodeWriter_Discard(writer);
10591053
return PyErr_NoMemory();
10601054
}
10611055

10621056
if (!_Py_normalize_encoding(cstr, normalized, len + 1, 0)) {
10631057
PyMem_Free(normalized);
1064-
PyUnicodeWriter_Discard(writer);
10651058
return NULL;
10661059
}
10671060

1068-
if (PyUnicodeWriter_WriteUTF8(writer, normalized, (Py_ssize_t)strlen(normalized)) < 0) {
1069-
PyUnicodeWriter_Discard(writer);
1070-
PyMem_Free(normalized);
1071-
return NULL;
1072-
}
1061+
PyObject *result = PyUnicode_FromString(normalized);
10731062
PyMem_Free(normalized);
1074-
return PyUnicodeWriter_Finish(writer);
1063+
return result;
10751064
}
10761065

10771066
/* --- Module API --------------------------------------------------------- */

0 commit comments

Comments
 (0)