cpython: 123f2dc08b3e (original) (raw)

--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -46,10 +46,6 @@ OF OR IN CONNECTION WITH THE USE OR PERF #include <windows.h> #endif -#ifdef Py_DEBUG -# define DONT_MAKE_RESULT_READY -#endif - /* Endianness switches; defaults to little endian */ #ifdef WORDS_BIGENDIAN @@ -118,11 +114,6 @@ extern "C" { 0 : [](#l1.15) _PyUnicode_Ready(op))) -#define _PyUnicode_READY_REPLACE(p_obj) [](#l1.18)

- #define _PyUnicode_SHARE_UTF8(op) [](#l1.23) (assert(_PyUnicode_CHECK(op)), [](#l1.24) assert(!PyUnicode_IS_COMPACT_ASCII(op)), [](#l1.25) @@ -232,9 +223,6 @@ static void copy_characters( PyObject *to, Py_ssize_t to_start, PyObject *from, Py_ssize_t from_start, Py_ssize_t how_many); -#ifdef Py_DEBUG -static int unicode_is_singleton(PyObject *unicode); -#endif static PyObject * unicode_fromascii(const unsigned char s, Py_ssize_t size); @@ -425,6 +413,90 @@ int } #endif +static PyObject +unicode_result_wchar(PyObject *unicode) +{ +#ifndef Py_DEBUG

+

+

+

+

+#else

+#endif

+} + +static PyObject* +unicode_result_ready(PyObject *unicode) +{

+

+

+

+} + +static PyObject* +unicode_result(PyObject *unicode) +{

+} + #ifdef HAVE_MBCS static OSVERSIONINFOEX winver; #endif @@ -1271,10 +1343,9 @@ find_maxchar_surrogates(const wchar_t *b static int unicode_ready_calls = 0; #endif -static int -unicode_ready(PyObject **p_obj, int replace) -{

+int +_PyUnicode_Ready(PyObject *unicode) +{ wchar_t *end; Py_UCS4 maxchar = 0; Py_ssize_t num_surrogates; @@ -1282,9 +1353,6 @@ unicode_ready(PyObject **p_obj, int repl Py_ssize_t length_wo_surrogates; #endif

- /* _PyUnicode_Ready() is only intended for old-style API usage where strings were created using _PyObject_New() and where no canonical representation (the str field) has been set yet aka strings @@ -1301,32 +1369,6 @@ unicode_ready(PyObject **p_obj, int repl ++unicode_ready_calls; #endif -#ifdef Py_DEBUG

-#else

-#endif

- end = _PyUnicode_WSTR(unicode) + _PyUnicode_WSTR_LENGTH(unicode); if (find_maxchar_surrogates(_PyUnicode_WSTR(unicode), end, &maxchar, &num_surrogates) == -1) @@ -1430,18 +1472,6 @@ unicode_ready(PyObject **p_obj, int repl return 0; } -int -_PyUnicode_ReadyReplace(PyObject **op) -{

-} - -int -_PyUnicode_Ready(PyObject *op) -{

-} - static void unicode_dealloc(register PyObject *unicode) { @@ -1681,8 +1711,7 @@ PyUnicode_FromUnicode(const Py_UNICODE * assert(0 && "Impossible state"); }

} PyObject @@ -1755,6 +1784,8 @@ void } } +/ Internal function, don't check maximum character / + static PyObject unicode_fromascii(const unsigned char* s, Py_ssize_t size) { @@ -1795,11 +1826,16 @@ static PyObject* _PyUnicode_FromUCS1(const unsigned char* u, Py_ssize_t size) { PyObject *res;

-

+

+ max_char = ucs1lib_find_max_char(u, u + size); res = PyUnicode_New(size, max_char); if (!res) @@ -1813,11 +1849,16 @@ static PyObject* _PyUnicode_FromUCS2(const Py_UCS2 *u, Py_ssize_t size) { PyObject *res;

-

+

+ max_char = ucs2lib_find_max_char(u, u + size); res = PyUnicode_New(size, max_char); if (!res) @@ -1836,11 +1877,16 @@ static PyObject* _PyUnicode_FromUCS4(const Py_UCS4 *u, Py_ssize_t size) { PyObject *res;

-

+

+ max_char = ucs4lib_find_max_char(u, u + size); res = PyUnicode_New(size, max_char); if (!res) @@ -2640,8 +2686,7 @@ PyUnicode_FromFormatV(const char *format PyObject_Free(callresults); if (numberresults) PyObject_Free(numberresults);

fail: if (callresults) { PyObject **callresult2 = callresults; @@ -2936,14 +2981,7 @@ PyUnicode_Decode(const char *s, goto onError; } Py_DECREF(buffer); -#ifndef DONT_MAKE_RESULT_READY

-#endif

onError: Py_XDECREF(buffer); @@ -2969,8 +3007,7 @@ PyUnicode_AsDecodedObject(PyObject *unic v = PyCodec_Decode(unicode, encoding, errors); if (v == NULL) goto onError;

onError: return NULL; @@ -3002,8 +3039,7 @@ PyUnicode_AsDecodedUnicode(PyObject *uni Py_DECREF(v); goto onError; }

onError: return NULL; @@ -4002,14 +4038,7 @@ utf7Error: Py_XDECREF(errorHandler); Py_XDECREF(exc); -#ifndef DONT_MAKE_RESULT_READY

-#endif

onError: Py_XDECREF(errorHandler); @@ -4358,18 +4387,26 @@ PyUnicode_DecodeUTF8Stateful(const char return (PyObject *)PyUnicode_New(0, 0); } maxchar = utf8_max_char_size_and_char_count(s, size, &unicode_size);

+

+ /* In case of errors, maxchar and size computation might be incorrect; code below refits and resizes as necessary. */ unicode = PyUnicode_New(unicode_size, maxchar); if (!unicode) return NULL;

-#endif

onError: Py_DECREF(unicode); @@ -5423,8 +5453,7 @@ PyUnicode_DecodeUTF16Stateful(const char Py_XDECREF(errorHandler); Py_XDECREF(exc);

onError: Py_DECREF(unicode); @@ -5843,14 +5872,7 @@ PyUnicode_DecodeUnicodeEscape(const char goto onError; Py_XDECREF(errorHandler); Py_XDECREF(exc); -#ifndef DONT_MAKE_RESULT_READY

-#endif

ucnhashError: PyErr_SetString( @@ -6111,8 +6133,7 @@ PyUnicode_DecodeRawUnicodeEscape(const c goto onError; Py_XDECREF(errorHandler); Py_XDECREF(exc);

onError: Py_XDECREF(v); @@ -6301,8 +6322,7 @@ PyObject * goto onError; Py_XDECREF(errorHandler); Py_XDECREF(exc);

onError: Py_XDECREF(v); @@ -6686,6 +6706,11 @@ PyUnicode_DecodeASCII(const char *s, PyObject *errorHandler = NULL; PyObject *exc = NULL;

+ /* ASCII is equivalent to the first 128 ordinals in Unicode. */ if (size == 1 && (unsigned char)s[0] < 128) return get_latin1_char((unsigned char)s[0]); @@ -7115,14 +7140,7 @@ decode_code_page_stateful(int code_page, size -= converted; } while (!done); -#ifndef DONT_MAKE_RESULT_READY

-#endif

} PyObject * @@ -7723,8 +7741,7 @@ PyUnicode_DecodeCharmap(const char *s, goto onError; Py_XDECREF(errorHandler); Py_XDECREF(exc);

onError: Py_XDECREF(errorHandler); @@ -8658,8 +8675,12 @@ PyObject * repunicode = unicode_translate_call_errorhandler(errors, &errorHandler, reason, input, &exc, collstart, collend, &newpos);

@@ -8812,8 +8833,7 @@ PyUnicode_TransformDecimalToASCII(Py_UNI } PyUnicode_WRITE(kind, data, i, ch); }

} /* --- Decimal Encoder ---------------------------------------------------- */ @@ -10801,8 +10821,7 @@ PyUnicode_Append(PyObject **p_left, PyOb if (!(PyUnicode_IS_ASCII(left) && !PyUnicode_IS_ASCII(right))) { unicode_append_inplace(p_left, right);

-#endif

overflow: PyErr_SetString(PyExc_OverflowError, "new string is too long"); @@ -13876,9 +13888,9 @@ int _PyUnicode_Init(void) /* Init the implementation */ unicode_empty = PyUnicode_New(0, 0);

for (i = 0; i < 256; i++) unicode_latin1[i] = NULL; @@ -13946,11 +13958,6 @@ PyUnicode_InternInPlace(PyObject **p) return; if (PyUnicode_CHECK_INTERNED(s)) return;