diff options
| author | Benjamin Peterson <benjamin@python.org> | 2016-09-06 15:57:48 -0700 | 
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2016-09-06 15:57:48 -0700 | 
| commit | 7103ff94eb3401d8da729258a14bd8470b465f81 (patch) | |
| tree | d73c1c2bee3821b99670b24531da33dc615aebd4 /Objects/unicodeobject.c | |
| parent | 0cf223873e568e40ebf813bb4d5d78536bf53338 (diff) | |
| parent | 581139cb34e63f08b52a32cf2401d2d719effefb (diff) | |
| download | cpython-git-7103ff94eb3401d8da729258a14bd8470b465f81.tar.gz | |
merge heads
Diffstat (limited to 'Objects/unicodeobject.c')
| -rw-r--r-- | Objects/unicodeobject.c | 25 | 
1 files changed, 13 insertions, 12 deletions
| diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 86f23c9c7c..b96333ce47 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3842,6 +3842,7 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)  int  PyUnicode_FSConverter(PyObject* arg, void* addr)  { +    PyObject *path = NULL;      PyObject *output = NULL;      Py_ssize_t size;      void *data; @@ -3850,22 +3851,22 @@ PyUnicode_FSConverter(PyObject* arg, void* addr)          *(PyObject**)addr = NULL;          return 1;      } -    if (PyBytes_Check(arg)) { -        output = arg; -        Py_INCREF(output); +    path = PyOS_FSPath(arg); +    if (path == NULL) { +        return 0;      } -    else if (PyUnicode_Check(arg)) { -        output = PyUnicode_EncodeFSDefault(arg); -        if (!output) +    if (PyBytes_Check(path)) { +        output = path; +    } +    else {  // PyOS_FSPath() guarantees its returned value is bytes or str. +        output = PyUnicode_EncodeFSDefault(path); +        Py_DECREF(path); +        if (!output) {              return 0; +        }          assert(PyBytes_Check(output));      } -    else { -        PyErr_Format(PyExc_TypeError, -                     "must be str or bytes, not %.100s", -                     Py_TYPE(arg)->tp_name); -        return 0; -    } +      size = PyBytes_GET_SIZE(output);      data = PyBytes_AS_STRING(output);      if ((size_t)size != strlen(data)) { | 
