summaryrefslogtreecommitdiffstats
path: root/Modules/_io/fileio.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_io/fileio.c')
-rw-r--r--Modules/_io/fileio.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index f39f8b0..d5b03ee 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -253,34 +253,23 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
}
#ifdef MS_WINDOWS
- if (PyUnicode_Check(nameobj))
+ if (PyUnicode_Check(nameobj)) {
+ int rv = _PyUnicode_HasNULChars(nameobj);
+ if (rv) {
+ if (rv != -1)
+ PyErr_SetString(PyExc_TypeError, "embedded NUL character");
+ return -1;
+ }
widename = PyUnicode_AS_UNICODE(nameobj);
+ }
if (widename == NULL)
#endif
if (fd < 0)
{
- if (PyBytes_Check(nameobj) || PyByteArray_Check(nameobj)) {
- Py_ssize_t namelen;
- if (PyObject_AsCharBuffer(nameobj, &name, &namelen) < 0)
- return -1;
- }
- else {
- PyObject *u = PyUnicode_FromObject(nameobj);
-
- if (u == NULL)
- return -1;
-
- stringobj = PyUnicode_EncodeFSDefault(u);
- Py_DECREF(u);
- if (stringobj == NULL)
- return -1;
- if (!PyBytes_Check(stringobj)) {
- PyErr_SetString(PyExc_TypeError,
- "encoder failed to return bytes");
- goto error;
- }
- name = PyBytes_AS_STRING(stringobj);
+ if (!PyUnicode_FSConverter(nameobj, &stringobj)) {
+ return -1;
}
+ name = PyBytes_AS_STRING(stringobj);
}
s = mode;