changeset: 94321:e124aab5d9a0 user: Victor Stinner date: Mon Jan 26 16:41:32 2015 +0100 files: Misc/ACKS Misc/NEWS Objects/unicodeobject.c description: Issue #15859: PyUnicode_EncodeFSDefault(), PyUnicode_EncodeMBCS() and PyUnicode_EncodeCodePage() now raise an exception if the object is not an Unicode object. For PyUnicode_EncodeFSDefault(), it was already the case on platforms other than Windows. Patch written by Campbell Barton. diff -r 1c0dc8daa280 -r e124aab5d9a0 Misc/ACKS --- a/Misc/ACKS Mon Jan 26 09:23:41 2015 -0500 +++ b/Misc/ACKS Mon Jan 26 16:41:32 2015 +0100 @@ -89,6 +89,7 @@ Cesar Eduardo Barros Des Barry Ulf Bartelt +Campbell Barton Don Bashford Pior Bastida Nick Bastin diff -r 1c0dc8daa280 -r e124aab5d9a0 Misc/NEWS --- a/Misc/NEWS Mon Jan 26 09:23:41 2015 -0500 +++ b/Misc/NEWS Mon Jan 26 16:41:32 2015 +0100 @@ -10,6 +10,11 @@ Core and Builtins ----------------- +- Issue #15859: PyUnicode_EncodeFSDefault(), PyUnicode_EncodeMBCS() and + PyUnicode_EncodeCodePage() now raise an exception if the object is not an + Unicode object. For PyUnicode_EncodeFSDefault(), it was already the case on + platforms other than Windows. Patch written by Campbell Barton. + - Issue #21408: The default __ne__() now returns NotImplemented if __eq__() returned NotImplemented. Original patch by Martin Panter. diff -r 1c0dc8daa280 -r e124aab5d9a0 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Mon Jan 26 09:23:41 2015 -0500 +++ b/Objects/unicodeobject.c Mon Jan 26 16:41:32 2015 +0100 @@ -7431,6 +7431,11 @@ Py_ssize_t offset; int chunk_len, ret, done; + if (!PyUnicode_Check(unicode)) { + PyErr_BadArgument(); + return NULL; + } + if (PyUnicode_READY(unicode) == -1) return NULL; len = PyUnicode_GET_LENGTH(unicode); @@ -7504,10 +7509,6 @@ PyObject * PyUnicode_AsMBCSString(PyObject *unicode) { - if (!PyUnicode_Check(unicode)) { - PyErr_BadArgument(); - return NULL; - } return PyUnicode_EncodeCodePage(CP_ACP, unicode, NULL); }