diff -r 36af3566b67a Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst Thu Nov 03 15:38:58 2016 +0200 +++ b/Doc/c-api/unicode.rst Sun Nov 06 12:46:58 2016 +0200 @@ -679,8 +679,8 @@ 3.x, but need to be aware that their use string content has been filled before using any of the access macros such as :c:func:`PyUnicode_KIND`. - Please migrate to using :c:func:`PyUnicode_FromKindAndData` or - :c:func:`PyUnicode_New`. + Please migrate to using :c:func:`PyUnicode_FromKindAndData`, + :c:func:`PyUnicode_FromWideChar` or :c:func:`PyUnicode_New`. .. c:function:: Py_UNICODE* PyUnicode_AsUnicode(PyObject *unicode) @@ -694,7 +694,7 @@ 3.x, but need to be aware that their use used in most C functions. Please migrate to using :c:func:`PyUnicode_AsUCS4`, - :c:func:`PyUnicode_Substring`, :c:func:`PyUnicode_ReadChar` or similar new + :c:func:`PyUnicode_AsWideChar`, :c:func:`PyUnicode_ReadChar` or similar new APIs. @@ -1091,7 +1091,8 @@ These are the UTF-8 codec APIs: .. deprecated-removed:: 3.3 4.0 Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using - :c:func:`PyUnicode_AsUTF8String` or :c:func:`PyUnicode_AsUTF8AndSize`. + :c:func:`PyUnicode_AsUTF8String`, :c:func:`PyUnicode_AsUTF8AndSize` or + :c:func:`PyUnicode_AsEncodedString`. UTF-32 Codecs @@ -1164,7 +1165,7 @@ These are the UTF-32 codec APIs: .. deprecated-removed:: 3.3 4.0 Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using - :c:func:`PyUnicode_AsUTF32String`. + :c:func:`PyUnicode_AsUTF32String` or :c:func:`PyUnicode_AsEncodedString`. UTF-16 Codecs @@ -1239,7 +1240,7 @@ These are the UTF-16 codec APIs: .. deprecated-removed:: 3.3 4.0 Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using - :c:func:`PyUnicode_AsUTF16String`. + :c:func:`PyUnicode_AsUTF16String` or :c:func:`PyUnicode_AsEncodedString`. UTF-7 Codecs @@ -1276,9 +1277,8 @@ These are the UTF-7 codec APIs: Python "utf-7" codec. .. deprecated-removed:: 3.3 4.0 - Part of the old-style :c:type:`Py_UNICODE` API. - - .. XXX replace with what? + Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using + :c:func:`PyUnicode_AsEncodedString`. Unicode-Escape Codecs @@ -1341,7 +1341,8 @@ These are the "Raw Unicode Escape" codec .. deprecated-removed:: 3.3 4.0 Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using - :c:func:`PyUnicode_AsRawUnicodeEscapeString`. + :c:func:`PyUnicode_AsRawUnicodeEscapeString` or + :c:func:`PyUnicode_AsEncodedString`. Latin-1 Codecs @@ -1372,7 +1373,8 @@ ordinals and only these are accepted by .. deprecated-removed:: 3.3 4.0 Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using - :c:func:`PyUnicode_AsLatin1String`. + :c:func:`PyUnicode_AsLatin1String` or + :c:func:`PyUnicode_AsEncodedString`. ASCII Codecs @@ -1403,7 +1405,8 @@ codes generate errors. .. deprecated-removed:: 3.3 4.0 Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using - :c:func:`PyUnicode_AsASCIIString`. + :c:func:`PyUnicode_AsASCIIString` or + :c:func:`PyUnicode_AsEncodedString`. Character Map Codecs @@ -1412,76 +1415,77 @@ Character Map Codecs This codec is special in that it can be used to implement many different codecs (and this is in fact what was done to obtain most of the standard codecs included in the :mod:`encodings` package). The codec uses mapping to encode and -decode characters. - -Decoding mappings must map single string characters to single Unicode -characters, integers (which are then interpreted as Unicode ordinals) or ``None`` -(meaning "undefined mapping" and causing an error). - -Encoding mappings must map single Unicode characters to single string -characters, integers (which are then interpreted as Latin-1 ordinals) or ``None`` -(meaning "undefined mapping" and causing an error). - -The mapping objects provided must only support the __getitem__ mapping -interface. - -If a character lookup fails with a LookupError, the character is copied as-is -meaning that its ordinal value will be interpreted as Unicode or Latin-1 ordinal -resp. Because of this, mappings only need to contain those mappings which map -characters to different code points. +decode characters. The mapping objects provided must only support the +:meth:`__getitem__` mapping interface; dictionaries and sequences work well. These are the mapping codec APIs: -.. c:function:: PyObject* PyUnicode_DecodeCharmap(const char *s, Py_ssize_t size, \ +.. c:function:: PyObject* PyUnicode_DecodeCharmap(const char *data, Py_ssize_t size, \ PyObject *mapping, const char *errors) - Create a Unicode object by decoding *size* bytes of the encoded string *s* using - the given *mapping* object. Return *NULL* if an exception was raised by the - codec. If *mapping* is *NULL* latin-1 decoding will be done. Else it can be a - dictionary mapping byte or a unicode string, which is treated as a lookup table. - Byte values greater that the length of the string and U+FFFE "characters" are - treated as "undefined mapping". + Create a Unicode object by decoding *size* bytes of the encoded string *s* + using the given *mapping* object. Return *NULL* if an exception was raised + by the codec. + + If *mapping* is *NULL* Latin-1 decoding will be done. Else it must map + bytes (integers in the range from 0 to 255) to Unicode strings, integers + (which are then interpreted as Unicode ordinals) or ``None``. Unmapped + bytes (ones which cause a :exc:`LookupError`) as well as mapped to + ``None``, ``0xFFFE`` or ``'\ufffe'`` are treated as "undefined mapping" and + cause an error. .. c:function:: PyObject* PyUnicode_AsCharmapString(PyObject *unicode, PyObject *mapping) - Encode a Unicode object using the given *mapping* object and return the result - as Python string object. Error handling is "strict". Return *NULL* if an + Encode a Unicode object using the given *mapping* object and return the + result as a bytes object. Error handling is "strict". Return *NULL* if an exception was raised by the codec. -The following codec API is special in that maps Unicode to Unicode. - - -.. c:function:: PyObject* PyUnicode_TranslateCharmap(const Py_UNICODE *s, Py_ssize_t size, \ - PyObject *table, const char *errors) - - Translate a :c:type:`Py_UNICODE` buffer of the given *size* by applying a - character mapping *table* to it and return the resulting Unicode object. Return - *NULL* when an exception was raised by the codec. - - The *mapping* table must map Unicode ordinal integers to Unicode ordinal - integers or ``None`` (causing deletion of the character). - - Mapping tables need only provide the :meth:`__getitem__` interface; dictionaries - and sequences work well. Unmapped character ordinals (ones which cause a - :exc:`LookupError`) are left untouched and are copied as-is. - - .. deprecated-removed:: 3.3 4.0 - Part of the old-style :c:type:`Py_UNICODE` API. - - .. XXX replace with what? + The *mapping* object must map Unicode ordinal integers to bytes objects, + integers in the range from 0 to 255 or ``None``. Unmapped character + ordinals (ones which cause a :exc:`LookupError`) as well as mapped to + ``None`` are treated as "undefined mapping" and cause an error. .. c:function:: PyObject* PyUnicode_EncodeCharmap(const Py_UNICODE *s, Py_ssize_t size, \ PyObject *mapping, const char *errors) Encode the :c:type:`Py_UNICODE` buffer of the given *size* using the given - *mapping* object and return a Python string object. Return *NULL* if an - exception was raised by the codec. + *mapping* object and return the result as a bytes object. Return *NULL* if + an exception was raised by the codec. .. deprecated-removed:: 3.3 4.0 Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using - :c:func:`PyUnicode_AsCharmapString`. + :c:func:`PyUnicode_AsCharmapString` or + :c:func:`PyUnicode_AsEncodedString`. + + +The following codec API is special in that maps Unicode to Unicode. + +.. c:function:: PyObject* PyUnicode_Translate(PyObject *unicode, \ + PyObject *mapping, const char *errors) + + Translate a Unicode object using the given *mapping* object and return the + resulting Unicode object. Return *NULL* if an exception was raised by the + codec. + + The *mapping* object must map Unicode ordinal integers to Unicode strings, + integers (which are then interpreted as Unicode ordinals) or ``None`` + (causing deletion of the character). Unmapped character ordinals (ones + which cause a :exc:`LookupError`) are left untouched and are copied as-is. + + +.. c:function:: PyObject* PyUnicode_TranslateCharmap(const Py_UNICODE *s, Py_ssize_t size, \ + PyObject *mapping, const char *errors) + + Translate a :c:type:`Py_UNICODE` buffer of the given *size* by applying a + character *mapping* table to it and return the resulting Unicode object. + Return *NULL* when an exception was raised by the codec. + + .. deprecated-removed:: 3.3 4.0 + Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using + :c:func:`PyUnicode_Translate`. or :ref:`generic codec based API + ` MBCS codecs for Windows @@ -1531,7 +1535,8 @@ the user settings on the machine running .. deprecated-removed:: 3.3 4.0 Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using - :c:func:`PyUnicode_AsMBCSString` or :c:func:`PyUnicode_EncodeCodePage`. + :c:func:`PyUnicode_AsMBCSString`, :c:func:`PyUnicode_EncodeCodePage` or + :c:func:`PyUnicode_AsEncodedString`. Methods & Slots diff -r 36af3566b67a Include/abstract.h --- a/Include/abstract.h Thu Nov 03 15:38:58 2016 +0200 +++ b/Include/abstract.h Sun Nov 06 12:46:58 2016 +0200 @@ -549,7 +549,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj, const char **buffer, - Py_ssize_t *buffer_len); + Py_ssize_t *buffer_len) + Py_DEPRECATED(3.0); /* Takes an arbitrary object which must support the (character, @@ -562,7 +563,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx an exception set. */ - PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj); + PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj) + Py_DEPRECATED(3.0); /* Checks whether an arbitrary object supports the (character, @@ -572,7 +574,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj, const void **buffer, - Py_ssize_t *buffer_len); + Py_ssize_t *buffer_len) + Py_DEPRECATED(3.0); /* Same as PyObject_AsCharBuffer() except that this API expects @@ -587,7 +590,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj, void **buffer, - Py_ssize_t *buffer_len); + Py_ssize_t *buffer_len) + Py_DEPRECATED(3.0); /* Takes an arbitrary object which must support the (writable, diff -r 36af3566b67a Include/ceval.h --- a/Include/ceval.h Thu Nov 03 15:38:58 2016 +0200 +++ b/Include/ceval.h Sun Nov 06 12:46:58 2016 +0200 @@ -182,8 +182,8 @@ PyAPI_FUNC(void) PyEval_InitThreads(void #ifndef Py_LIMITED_API PyAPI_FUNC(void) _PyEval_FiniThreads(void); #endif /* !Py_LIMITED_API */ -PyAPI_FUNC(void) PyEval_AcquireLock(void); -PyAPI_FUNC(void) PyEval_ReleaseLock(void); +PyAPI_FUNC(void) PyEval_AcquireLock(void) Py_DEPRECATED(3.2); +PyAPI_FUNC(void) PyEval_ReleaseLock(void) /* Py_DEPRECATED(3.2) */; PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate); PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); PyAPI_FUNC(void) PyEval_ReInitThreads(void); diff -r 36af3566b67a Include/longobject.h --- a/Include/longobject.h Thu Nov 03 15:38:58 2016 +0200 +++ b/Include/longobject.h Sun Nov 06 12:46:58 2016 +0200 @@ -94,7 +94,7 @@ PyAPI_FUNC(long long) PyLong_AsLongLongA PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int); #ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int); +PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int) Py_DEPRECATED(3.3); PyAPI_FUNC(PyObject *) PyLong_FromUnicodeObject(PyObject *u, int base); PyAPI_FUNC(PyObject *) _PyLong_FromBytes(const char *, Py_ssize_t, int); #endif diff -r 36af3566b67a Include/moduleobject.h --- a/Include/moduleobject.h Thu Nov 03 15:38:58 2016 +0200 +++ b/Include/moduleobject.h Sun Nov 06 12:46:58 2016 +0200 @@ -21,7 +21,7 @@ PyAPI_FUNC(PyObject *) PyModule_New( PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *); PyAPI_FUNC(PyObject *) PyModule_GetNameObject(PyObject *); PyAPI_FUNC(const char *) PyModule_GetName(PyObject *); -PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *); +PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *) Py_DEPRECATED(3.2); PyAPI_FUNC(PyObject *) PyModule_GetFilenameObject(PyObject *); #ifndef Py_LIMITED_API PyAPI_FUNC(void) _PyModule_Clear(PyObject *); diff -r 36af3566b67a Include/pyerrors.h --- a/Include/pyerrors.h Thu Nov 03 15:38:58 2016 +0200 +++ b/Include/pyerrors.h Sun Nov 06 12:46:58 2016 +0200 @@ -240,7 +240,7 @@ PyAPI_FUNC(PyObject *) PyErr_SetFromErrn ); #if defined(MS_WINDOWS) && !defined(Py_LIMITED_API) PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename( - PyObject *, const Py_UNICODE *); + PyObject *, const Py_UNICODE *) Py_DEPRECATED(3.3); #endif /* MS_WINDOWS */ PyAPI_FUNC(PyObject *) PyErr_Format( @@ -274,7 +274,7 @@ PyAPI_FUNC(PyObject *) PyErr_SetFromWind #ifndef Py_LIMITED_API /* XXX redeclare to use WSTRING */ PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename( - int, const Py_UNICODE *); + int, const Py_UNICODE *) Py_DEPRECATED(3.3); #endif PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int); PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject( @@ -288,7 +288,7 @@ PyAPI_FUNC(PyObject *) PyErr_SetExcFromW ); #ifndef Py_LIMITED_API PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename( - PyObject *,int, const Py_UNICODE *); + PyObject *,int, const Py_UNICODE *) Py_DEPRECATED(3.3); #endif PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int); #endif /* MS_WINDOWS */ @@ -391,7 +391,7 @@ PyAPI_FUNC(PyObject *) PyUnicodeEncodeEr Py_ssize_t start, Py_ssize_t end, const char *reason /* UTF-8 encoded string */ - ); + ) Py_DEPRECATED(3.3); #endif /* create a UnicodeTranslateError object */ @@ -402,7 +402,7 @@ PyAPI_FUNC(PyObject *) PyUnicodeTranslat Py_ssize_t start, Py_ssize_t end, const char *reason /* UTF-8 encoded string */ - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create( PyObject *object, Py_ssize_t start, diff -r 36af3566b67a Include/unicodeobject.h --- a/Include/unicodeobject.h Thu Nov 03 15:38:58 2016 +0200 +++ b/Include/unicodeobject.h Sun Nov 06 12:46:58 2016 +0200 @@ -90,7 +90,7 @@ Copyright (c) Corporation for National R #ifndef Py_LIMITED_API #define PY_UNICODE_TYPE wchar_t -typedef wchar_t Py_UNICODE; +typedef wchar_t Py_UNICODE /* Py_DEPRECATED(3.3) */; #endif /* If the compiler provides a wchar_t type we try to support it @@ -387,9 +387,11 @@ PyAPI_DATA(PyTypeObject) PyUnicodeIter_T ((void)PyUnicode_AsUnicode((PyObject *)(op)), \ assert(((PyASCIIObject *)(op))->wstr), \ PyUnicode_WSTR_LENGTH(op))) + /* Py_DEPRECATED(3.3) */ #define PyUnicode_GET_DATA_SIZE(op) \ (PyUnicode_GET_SIZE(op) * Py_UNICODE_SIZE) + /* Py_DEPRECATED(3.3) */ /* Alias for PyUnicode_AsUnicode(). This will create a wchar_t/Py_UNICODE representation on demand. Using this macro is very inefficient now, @@ -400,9 +402,11 @@ PyAPI_DATA(PyTypeObject) PyUnicodeIter_T (assert(PyUnicode_Check(op)), \ (((PyASCIIObject *)(op))->wstr) ? (((PyASCIIObject *)(op))->wstr) : \ PyUnicode_AsUnicode((PyObject *)(op))) + /* Py_DEPRECATED(3.3) */ #define PyUnicode_AS_DATA(op) \ ((const char *)(PyUnicode_AS_UNICODE(op))) + /* Py_DEPRECATED(3.3) */ /* --- Flexible String Representation Helper Macros (PEP 393) -------------- */ @@ -688,7 +692,7 @@ PyAPI_FUNC(void) _PyUnicode_FastFill( PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode( const Py_UNICODE *u, /* Unicode buffer */ Py_ssize_t size /* size of buffer */ - ); + ) /* Py_DEPRECATED(3.3) */; #endif /* Similar to PyUnicode_FromUnicode(), but u points to UTF-8 encoded bytes */ @@ -756,7 +760,7 @@ PyAPI_FUNC(Py_UCS4*) PyUnicode_AsUCS4Cop #ifndef Py_LIMITED_API PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode( PyObject *unicode /* Unicode object */ - ); + ) /* Py_DEPRECATED(3.3) */; #endif /* Return a read-only pointer to the Unicode object's internal @@ -768,7 +772,7 @@ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUni PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize( PyObject *unicode, /* Unicode object */ Py_ssize_t *size /* location where to save the length */ - ); + ) /* Py_DEPRECATED(3.3) */; #endif /* Get the length of the Unicode object. */ @@ -782,7 +786,7 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_GetLeng PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize( PyObject *unicode /* Unicode object */ - ); + ) Py_DEPRECATED(3.3); /* Read a character from the string. */ @@ -804,7 +808,7 @@ PyAPI_FUNC(int) PyUnicode_WriteChar( #ifndef Py_LIMITED_API /* Get the maximum ordinal for a Unicode character. */ -PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void); +PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void) Py_DEPRECATED(3.3); #endif /* Resize a Unicode object. The length is the number of characters, except @@ -1205,7 +1209,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_Encode( Py_ssize_t size, /* number of Py_UNICODE chars to encode */ const char *encoding, /* encoding */ const char *errors /* error handling */ - ); + ) Py_DEPRECATED(3.3); #endif /* Encodes a Unicode object and returns the result as Python @@ -1272,7 +1276,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeUT int base64SetO, /* Encode RFC2152 Set O characters in base64 */ int base64WhiteSpace, /* Encode whitespace (sp, ht, nl, cr) in base64 */ const char *errors /* error handling */ - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF7( PyObject *unicode, /* Unicode object */ int base64SetO, /* Encode RFC2152 Set O characters in base64 */ @@ -1309,7 +1313,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeUT const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors /* error handling */ - ); + ) Py_DEPRECATED(3.3); #endif /* --- UTF-32 Codecs ------------------------------------------------------ */ @@ -1385,7 +1389,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeUT Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors, /* error handling */ int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF32( PyObject *object, /* Unicode object */ const char *errors, /* error handling */ @@ -1470,7 +1474,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeUT Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors, /* error handling */ int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF16( PyObject* unicode, /* Unicode object */ const char *errors, /* error handling */ @@ -1505,7 +1509,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUnicod PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to encode */ - ); + ) Py_DEPRECATED(3.3); #endif /* --- Raw-Unicode-Escape Codecs ------------------------------------------ */ @@ -1524,7 +1528,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsRawUni PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape( const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to encode */ - ); + ) Py_DEPRECATED(3.3); #endif /* --- Unicode Internal Codec --------------------------------------------- @@ -1564,7 +1568,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeLa const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ const char *errors /* error handling */ - ); + ) Py_DEPRECATED(3.3); #endif /* --- ASCII Codecs ------------------------------------------------------- @@ -1592,7 +1596,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeAS const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ const char *errors /* error handling */ - ); + ) Py_DEPRECATED(3.3); #endif /* --- Character Map Codecs ----------------------------------------------- @@ -1638,7 +1642,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeCh PyObject *mapping, /* character mapping (unicode ordinal -> char ordinal) */ const char *errors /* error handling */ - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(PyObject*) _PyUnicode_EncodeCharmap( PyObject *unicode, /* Unicode object */ PyObject *mapping, /* character mapping @@ -1666,7 +1670,7 @@ PyAPI_FUNC(PyObject *) PyUnicode_Transla Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ PyObject *table, /* Translate table */ const char *errors /* error handling */ - ); + ) Py_DEPRECATED(3.3); #endif #ifdef MS_WINDOWS @@ -1703,7 +1707,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeMB const Py_UNICODE *data, /* Unicode char buffer */ Py_ssize_t length, /* number of Py_UNICODE chars to encode */ const char *errors /* error handling */ - ); + ) Py_DEPRECATED(3.3); #endif PyAPI_FUNC(PyObject*) PyUnicode_EncodeCodePage( @@ -1744,7 +1748,7 @@ PyAPI_FUNC(int) PyUnicode_EncodeDecimal( Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ char *output, /* Output buffer; must have size >= length */ const char *errors /* error handling */ - ); + ) /* Py_DEPRECATED(3.3) */; #endif /* Transforms code points that have decimal digit property to the @@ -1757,7 +1761,7 @@ PyAPI_FUNC(int) PyUnicode_EncodeDecimal( PyAPI_FUNC(PyObject*) PyUnicode_TransformDecimalToASCII( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to transform */ - ); + ) /* Py_DEPRECATED(3.3) */; #endif /* Similar to PyUnicode_TransformDecimalToASCII(), but takes a PyObject @@ -2161,15 +2165,15 @@ PyAPI_FUNC(int) _PyUnicode_IsLinebreak( PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase( Py_UCS4 ch /* Unicode character */ - ); + ) /* Py_DEPRECATED(3.3) */; PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase( Py_UCS4 ch /* Unicode character */ - ); + ) /* Py_DEPRECATED(3.3) */; PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase( Py_UCS4 ch /* Unicode character */ - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(int) _PyUnicode_ToLowerFull( Py_UCS4 ch, /* Unicode character */ @@ -2233,40 +2237,40 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha( PyAPI_FUNC(size_t) Py_UNICODE_strlen( const Py_UNICODE *u - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy( Py_UNICODE *s1, - const Py_UNICODE *s2); + const Py_UNICODE *s2) Py_DEPRECATED(3.3); PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcat( - Py_UNICODE *s1, const Py_UNICODE *s2); + Py_UNICODE *s1, const Py_UNICODE *s2) Py_DEPRECATED(3.3); PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy( Py_UNICODE *s1, const Py_UNICODE *s2, - size_t n); + size_t n) Py_DEPRECATED(3.3); PyAPI_FUNC(int) Py_UNICODE_strcmp( const Py_UNICODE *s1, const Py_UNICODE *s2 - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(int) Py_UNICODE_strncmp( const Py_UNICODE *s1, const Py_UNICODE *s2, size_t n - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr( const Py_UNICODE *s, Py_UNICODE c - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr( const Py_UNICODE *s, Py_UNICODE c - ); + ) Py_DEPRECATED(3.3); PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int); @@ -2276,7 +2280,7 @@ PyAPI_FUNC(PyObject*) _PyUnicode_FormatL PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy( PyObject *unicode - ); + ) Py_DEPRECATED(3.3); #endif /* Py_LIMITED_API */ #if defined(Py_DEBUG) && !defined(Py_LIMITED_API) diff -r 36af3566b67a Modules/_testcapimodule.c --- a/Modules/_testcapimodule.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Modules/_testcapimodule.c Sun Nov 06 12:46:58 2016 +0200 @@ -1378,11 +1378,9 @@ static PyObject * getargs_u(PyObject *self, PyObject *args) { Py_UNICODE *str; - Py_ssize_t size; if (!PyArg_ParseTuple(args, "u", &str)) return NULL; - size = Py_UNICODE_strlen(str); - return PyUnicode_FromUnicode(str, size); + return PyUnicode_FromWideChar(str, -1); } static PyObject * @@ -1392,19 +1390,17 @@ getargs_u_hash(PyObject *self, PyObject Py_ssize_t size; if (!PyArg_ParseTuple(args, "u#", &str, &size)) return NULL; - return PyUnicode_FromUnicode(str, size); + return PyUnicode_FromWideChar(str, size); } static PyObject * getargs_Z(PyObject *self, PyObject *args) { Py_UNICODE *str; - Py_ssize_t size; if (!PyArg_ParseTuple(args, "Z", &str)) return NULL; if (str != NULL) { - size = Py_UNICODE_strlen(str); - return PyUnicode_FromUnicode(str, size); + return PyUnicode_FromWideChar(str, -1); } else Py_RETURN_NONE; } @@ -1417,7 +1413,7 @@ getargs_Z_hash(PyObject *self, PyObject if (!PyArg_ParseTuple(args, "Z#", &str, &size)) return NULL; if (str != NULL) - return PyUnicode_FromUnicode(str, size); + return PyUnicode_FromWideChar(str, size); else Py_RETURN_NONE; } diff -r 36af3566b67a Modules/arraymodule.c --- a/Modules/arraymodule.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Modules/arraymodule.c Sun Nov 06 12:46:58 2016 +0200 @@ -236,7 +236,7 @@ BB_setitem(arrayobject *ap, Py_ssize_t i static PyObject * u_getitem(arrayobject *ap, Py_ssize_t i) { - return PyUnicode_FromUnicode(&((Py_UNICODE *) ap->ob_item)[i], 1); + return PyUnicode_FromOrdinal(((Py_UNICODE *) ap->ob_item)[i]); } static int @@ -1693,7 +1693,7 @@ array_array_tounicode_impl(arrayobject * "tounicode() may only be called on unicode type arrays"); return NULL; } - return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, Py_SIZE(self)); + return PyUnicode_FromWideChar((Py_UNICODE *) self->ob_item, Py_SIZE(self)); } /*[clinic input] diff -r 36af3566b67a Objects/abstract.c --- a/Objects/abstract.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Objects/abstract.c Sun Nov 06 12:46:58 2016 +0200 @@ -252,14 +252,6 @@ PyObject_DelItemString(PyObject *o, cons cause issues later on. Don't use these functions in new code. */ int -PyObject_AsCharBuffer(PyObject *obj, - const char **buffer, - Py_ssize_t *buffer_len) -{ - return PyObject_AsReadBuffer(obj, (const void **)buffer, buffer_len); -} - -int PyObject_CheckReadBuffer(PyObject *obj) { PyBufferProcs *pb = obj->ob_type->tp_as_buffer; @@ -276,9 +268,8 @@ PyObject_CheckReadBuffer(PyObject *obj) return 1; } -int PyObject_AsReadBuffer(PyObject *obj, - const void **buffer, - Py_ssize_t *buffer_len) +static int +as_read_buffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len) { Py_buffer view; @@ -295,6 +286,21 @@ int PyObject_AsReadBuffer(PyObject *obj, return 0; } +int +PyObject_AsCharBuffer(PyObject *obj, + const char **buffer, + Py_ssize_t *buffer_len) +{ + return as_read_buffer(obj, (const void **)buffer, buffer_len); +} + +int PyObject_AsReadBuffer(PyObject *obj, + const void **buffer, + Py_ssize_t *buffer_len) +{ + return as_read_buffer(obj, buffer, buffer_len); +} + int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len) diff -r 36af3566b67a Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Objects/bytearrayobject.c Sun Nov 06 12:46:58 2016 +0200 @@ -2324,10 +2324,7 @@ bytearrayiter_reduce(bytesiterobject *it return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"), it->it_seq, it->it_index); } else { - PyObject *u = PyUnicode_FromUnicode(NULL, 0); - if (u == NULL) - return NULL; - return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), u); + return Py_BuildValue("N(())", _PyObject_GetBuiltin("iter")); } } diff -r 36af3566b67a Objects/bytesobject.c --- a/Objects/bytesobject.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Objects/bytesobject.c Sun Nov 06 12:46:58 2016 +0200 @@ -3048,10 +3048,7 @@ striter_reduce(striterobject *it) return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"), it->it_seq, it->it_index); } else { - PyObject *u = PyUnicode_FromUnicode(NULL, 0); - if (u == NULL) - return NULL; - return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), u); + return Py_BuildValue("N(())", _PyObject_GetBuiltin("iter")); } } diff -r 36af3566b67a Objects/codeobject.c --- a/Objects/codeobject.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Objects/codeobject.c Sun Nov 06 12:46:58 2016 +0200 @@ -113,7 +113,7 @@ PyCode_New(int argcount, int kwonlyargco /* Check argument types */ if (argcount < 0 || kwonlyargcount < 0 || nlocals < 0 || - code == NULL || + code == NULL || !PyBytes_Check(code) || consts == NULL || !PyTuple_Check(consts) || names == NULL || !PyTuple_Check(names) || varnames == NULL || !PyTuple_Check(varnames) || @@ -121,8 +121,7 @@ PyCode_New(int argcount, int kwonlyargco cellvars == NULL || !PyTuple_Check(cellvars) || name == NULL || !PyUnicode_Check(name) || filename == NULL || !PyUnicode_Check(filename) || - lnotab == NULL || !PyBytes_Check(lnotab) || - !PyObject_CheckReadBuffer(code)) { + lnotab == NULL || !PyBytes_Check(lnotab)) { PyErr_BadInternalCall(); return NULL; } diff -r 36af3566b67a Objects/longobject.c --- a/Objects/longobject.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Objects/longobject.c Sun Nov 06 12:46:58 2016 +0200 @@ -2480,7 +2480,7 @@ PyObject * PyObject * PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base) { - PyObject *v, *unicode = PyUnicode_FromUnicode(u, length); + PyObject *v, *unicode = PyUnicode_FromWideChar(u, length); if (unicode == NULL) return NULL; v = PyLong_FromUnicodeObject(unicode, base); diff -r 36af3566b67a Objects/unicodeobject.c --- a/Objects/unicodeobject.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Objects/unicodeobject.c Sun Nov 06 12:46:58 2016 +0200 @@ -1988,12 +1988,32 @@ unicode_char(Py_UCS4 ch) PyObject * PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size) { + if (u == NULL) + return (PyObject*)_PyUnicode_New(size); + + if (size < 0) { + PyErr_BadInternalCall(); + return NULL; + } + + return PyUnicode_FromWideChar(u, size); +} + +PyObject * +PyUnicode_FromWideChar(const wchar_t *u, Py_ssize_t size) +{ PyObject *unicode; Py_UCS4 maxchar = 0; Py_ssize_t num_surrogates; - if (u == NULL) - return (PyObject*)_PyUnicode_New(size); + if (u == NULL && size != 0) { + PyErr_BadInternalCall(); + return NULL; + } + + if (size == -1) { + size = wcslen(u); + } /* If the Unicode data is known at construction time, we can apply some optimizations which share commonly used objects. */ @@ -2478,27 +2498,6 @@ PyUnicode_AsUCS4Copy(PyObject *string) return as_ucs4(string, NULL, 0, 1); } -#ifdef HAVE_WCHAR_H - -PyObject * -PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size) -{ - if (w == NULL) { - if (size == 0) - _Py_RETURN_UNICODE_EMPTY(); - PyErr_BadInternalCall(); - return NULL; - } - - if (size == -1) { - size = wcslen(w); - } - - return PyUnicode_FromUnicode(w, size); -} - -#endif /* HAVE_WCHAR_H */ - /* maximum number of characters required for output of %lld or %p. We need at most ceil(log10(256)*SIZEOF_LONG_LONG) digits, plus 1 for the sign. 53/22 is an upper bound for log10(256). */ @@ -3296,7 +3295,7 @@ PyUnicode_Encode(const Py_UNICODE *s, { PyObject *v, *unicode; - unicode = PyUnicode_FromUnicode(s, size); + unicode = PyUnicode_FromWideChar(s, size); if (unicode == NULL) return NULL; v = PyUnicode_AsEncodedString(unicode, encoding, errors); @@ -4138,7 +4137,11 @@ PyUnicode_GetSize(PyObject *unicode) PyErr_BadArgument(); goto onError; } - return PyUnicode_GET_SIZE(unicode); + if (_PyUnicode_WSTR(unicode) == NULL) { + if (PyUnicode_AsUnicode(unicode) == NULL) + goto onError; + } + return PyUnicode_WSTR_LENGTH(unicode); onError: return -1; @@ -4824,7 +4827,7 @@ PyUnicode_EncodeUTF7(const Py_UNICODE *s const char *errors) { PyObject *result; - PyObject *tmp = PyUnicode_FromUnicode(s, size); + PyObject *tmp = PyUnicode_FromWideChar(s, size); if (tmp == NULL) return NULL; result = _PyUnicode_EncodeUTF7(tmp, base64SetO, @@ -5180,7 +5183,7 @@ PyUnicode_EncodeUTF8(const Py_UNICODE *s { PyObject *v, *unicode; - unicode = PyUnicode_FromUnicode(s, size); + unicode = PyUnicode_FromWideChar(s, size); if (unicode == NULL) return NULL; v = _PyUnicode_AsUTF8String(unicode, errors); @@ -5505,7 +5508,7 @@ PyUnicode_EncodeUTF32(const Py_UNICODE * int byteorder) { PyObject *result; - PyObject *tmp = PyUnicode_FromUnicode(s, size); + PyObject *tmp = PyUnicode_FromWideChar(s, size); if (tmp == NULL) return NULL; result = _PyUnicode_EncodeUTF32(tmp, errors, byteorder); @@ -5858,7 +5861,7 @@ PyUnicode_EncodeUTF16(const Py_UNICODE * int byteorder) { PyObject *result; - PyObject *tmp = PyUnicode_FromUnicode(s, size); + PyObject *tmp = PyUnicode_FromWideChar(s, size); if (tmp == NULL) return NULL; result = _PyUnicode_EncodeUTF16(tmp, errors, byteorder); @@ -6255,7 +6258,7 @@ PyUnicode_EncodeUnicodeEscape(const Py_U Py_ssize_t size) { PyObject *result; - PyObject *tmp = PyUnicode_FromUnicode(s, size); + PyObject *tmp = PyUnicode_FromWideChar(s, size); if (tmp == NULL) { return NULL; } @@ -6472,7 +6475,7 @@ PyUnicode_EncodeRawUnicodeEscape(const P Py_ssize_t size) { PyObject *result; - PyObject *tmp = PyUnicode_FromUnicode(s, size); + PyObject *tmp = PyUnicode_FromWideChar(s, size); if (tmp == NULL) return NULL; result = PyUnicode_AsRawUnicodeEscapeString(tmp); @@ -6883,7 +6886,7 @@ PyUnicode_EncodeLatin1(const Py_UNICODE const char *errors) { PyObject *result; - PyObject *unicode = PyUnicode_FromUnicode(p, size); + PyObject *unicode = PyUnicode_FromWideChar(p, size); if (unicode == NULL) return NULL; result = unicode_encode_ucs1(unicode, errors, 256); @@ -7024,7 +7027,7 @@ PyUnicode_EncodeASCII(const Py_UNICODE * const char *errors) { PyObject *result; - PyObject *unicode = PyUnicode_FromUnicode(p, size); + PyObject *unicode = PyUnicode_FromWideChar(p, size); if (unicode == NULL) return NULL; result = unicode_encode_ucs1(unicode, errors, 128); @@ -7750,7 +7753,7 @@ PyUnicode_EncodeMBCS(const Py_UNICODE *p const char *errors) { PyObject *unicode, *res; - unicode = PyUnicode_FromUnicode(p, size); + unicode = PyUnicode_FromWideChar(p, size); if (unicode == NULL) return NULL; res = encode_code_page(CP_ACP, unicode, errors); @@ -8598,7 +8601,7 @@ PyUnicode_EncodeCharmap(const Py_UNICODE const char *errors) { PyObject *result; - PyObject *unicode = PyUnicode_FromUnicode(p, size); + PyObject *unicode = PyUnicode_FromWideChar(p, size); if (unicode == NULL) return NULL; result = _PyUnicode_EncodeCharmap(unicode, mapping, errors); @@ -9038,7 +9041,7 @@ PyUnicode_TranslateCharmap(const Py_UNIC const char *errors) { PyObject *result; - PyObject *unicode = PyUnicode_FromUnicode(p, size); + PyObject *unicode = PyUnicode_FromWideChar(p, size); if (!unicode) return NULL; result = _PyUnicode_TranslateCharmap(unicode, mapping, errors); @@ -9166,14 +9169,10 @@ PyUnicode_EncodeDecimal(Py_UNICODE *s, return -1; } - unicode = PyUnicode_FromUnicode(s, length); + unicode = PyUnicode_FromWideChar(s, length); if (unicode == NULL) return -1; - if (PyUnicode_READY(unicode) == -1) { - Py_DECREF(unicode); - return -1; - } kind = PyUnicode_KIND(unicode); data = PyUnicode_DATA(unicode); @@ -15266,7 +15265,7 @@ unicodeiter_reduce(unicodeiterobject *it return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"), it->it_seq, it->it_index); } else { - PyObject *u = PyUnicode_FromUnicode(NULL, 0); + PyObject *u = (PyObject *)_PyUnicode_New(0); if (u == NULL) return NULL; return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), u); @@ -15361,10 +15360,7 @@ unicode_iter(PyObject *seq) size_t Py_UNICODE_strlen(const Py_UNICODE *u) { - int res = 0; - while(*u++) - res++; - return res; + return wcslen(u); } Py_UNICODE* @@ -15389,8 +15385,8 @@ Py_UNICODE* Py_UNICODE_strcat(Py_UNICODE *s1, const Py_UNICODE *s2) { Py_UNICODE *u1 = s1; - u1 += Py_UNICODE_strlen(u1); - Py_UNICODE_strcpy(u1, s2); + u1 += wcslen(u1); + while ((*u1++ = *s2++)); return s1; } @@ -15439,7 +15435,7 @@ Py_UNICODE* Py_UNICODE_strrchr(const Py_UNICODE *s, Py_UNICODE c) { const Py_UNICODE *p; - p = s + Py_UNICODE_strlen(s); + p = s + wcslen(s); while (p != s) { p--; if (*p == c) diff -r 36af3566b67a Python/errors.c --- a/Python/errors.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Python/errors.c Sun Nov 06 12:46:58 2016 +0200 @@ -582,9 +582,7 @@ PyErr_SetFromErrnoWithFilename(PyObject PyObject * PyErr_SetFromErrnoWithUnicodeFilename(PyObject *exc, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : - NULL; + PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL; PyObject *result = PyErr_SetFromErrnoWithFilenameObjects(exc, name, NULL); Py_XDECREF(name); return result; @@ -691,9 +689,7 @@ PyObject *PyErr_SetExcFromWindowsErrWith int ierr, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : - NULL; + PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL; PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObjects(exc, ierr, name, @@ -729,9 +725,7 @@ PyObject *PyErr_SetFromWindowsErrWithUni int ierr, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : - NULL; + PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL; PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObjects( PyExc_OSError, ierr, name, NULL); diff -r 36af3566b67a Python/getargs.c --- a/Python/getargs.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Python/getargs.c Sun Nov 06 12:46:58 2016 +0200 @@ -1027,7 +1027,7 @@ convertsimple(PyObject *arg, const char *p = PyUnicode_AsUnicodeAndSize(arg, &len); if (*p == NULL) RETURN_ERR_OCCURRED; - if (Py_UNICODE_strlen(*p) != (size_t)len) { + if (wcslen(*p) != (size_t)len) { PyErr_SetString(PyExc_ValueError, "embedded null character"); RETURN_ERR_OCCURRED; } @@ -1074,9 +1074,14 @@ convertsimple(PyObject *arg, const char (PyBytes_Check(arg) || PyByteArray_Check(arg))) { s = arg; Py_INCREF(s); - if (PyObject_AsCharBuffer(s, &ptr, &size) < 0) - return converterr("(AsCharBuffer failed)", - arg, msgbuf, bufsize); + if (PyBytes_Check(arg)) { + size = PyBytes_GET_SIZE(s); + ptr = PyBytes_AS_STRING(s); + } + else { + size = PyByteArray_GET_SIZE(s); + ptr = PyByteArray_AS_STRING(s); + } } else if (PyUnicode_Check(arg)) { /* Encode object; use default error handling */ diff -r 36af3566b67a Python/modsupport.c --- a/Python/modsupport.c Thu Nov 03 15:38:58 2016 +0200 +++ b/Python/modsupport.c Sun Nov 06 12:46:58 2016 +0200 @@ -286,8 +286,8 @@ do_mkvalue(const char **p_format, va_lis } else { if (n < 0) - n = Py_UNICODE_strlen(u); - v = PyUnicode_FromUnicode(u, n); + n = wcslen(u); + v = PyUnicode_FromWideChar(u, n); } return v; }