summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2016-09-06 22:50:29 (GMT)
committerBrett Cannon <brett@python.org>2016-09-06 22:50:29 (GMT)
commitec6ce879c7d55d3905240a855444ac83e08c6583 (patch)
tree6658bf68003b9858f50e92713876b23cb6657463 /Objects/unicodeobject.c
parentdc5a3fe4efee222dd8512fd63d9445ae5de42fc1 (diff)
downloadcpython-ec6ce879c7d55d3905240a855444ac83e08c6583.zip
cpython-ec6ce879c7d55d3905240a855444ac83e08c6583.tar.gz
cpython-ec6ce879c7d55d3905240a855444ac83e08c6583.tar.bz2
Issue #26027: Support path-like objects in PyUnicode-FSConverter().
This is to add support for os.exec*() and os.spawn*() functions. Part of PEP 519.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 86f23c9..b96333c 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)) {