[Python-Dev] [Python-checkins] cpython: Change decoders to use Unicode API instead of Py_UNICODE. (original) (raw)
Victor Stinner victor.stinner at haypocalc.com
Wed Nov 9 11:15:25 CET 2011
- Previous message: [Python-Dev] unicode_internal codec and the PEP 393
- Next message: [Python-Dev] [SPAM: 3.000] [issue11682] PEP 380 reference implementation for 3.3
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
First of all, thanks for having upgraded this huge part (codecs) to the new Unicode API!
+static int +unicodewiden(PyObject **punicode, int maxchar) +{ + PyObject *result; + assert(PyUnicodeISREADY(*punicode)); + if (maxchar <= PyUnicodeMAXCHARVALUE(*punicode)) + return 0; + result = PyUnicodeNew(PyUnicodeGETLENGTH(*punicode), + maxchar); + if (result == NULL) + return -1; + PyUnicodeCopyCharacters(result, 0, *punicode, 0, + PyUnicodeGETLENGTH(*punicode)); + PyDECREF(*punicode); + *punicode = result; + return 0; +}
PyUnicode_CopyCharacters() result must be checked. If you are sure that the call cannot fail, use copy_characters() which uses assertions in debug mode ( and no check in release mode).
-#ifndef DONTMAKERESULTREADY - if (PyUnicodeREADYREPLACE(&v)) { - PyDECREF(v); - return NULL; - } -#endif
Why did you remove this call from PyUnicode_DecodeRawUnicodeEscape(), _PyUnicode_DecodeUnicodeInternal(), PyUnicode_DecodeASCII() and PyUnicode_DecodeCharmap()? It may reuse latin1 characters singletons to share a little bit more memory (there is already a special case for empty string).
"_PyUnicode_READY_REPLACE" is maybe not the best name :-)
Victor
- Previous message: [Python-Dev] unicode_internal codec and the PEP 393
- Next message: [Python-Dev] [SPAM: 3.000] [issue11682] PEP 380 reference implementation for 3.3
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]