diff -r 3ebeeed1eb28 Include/unicodeobject.h --- a/Include/unicodeobject.h Fri Apr 10 16:22:14 2015 +0300 +++ b/Include/unicodeobject.h Fri Apr 10 19:35:04 2015 +0300 @@ -2060,12 +2060,6 @@ PyAPI_FUNC(int) PyUnicode_Contains( PyObject *element /* Element string */ ); -/* Checks whether the string contains any NUL characters. */ - -#ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyUnicode_HasNULChars(PyObject *); -#endif - /* Checks whether argument is a valid identifier. */ PyAPI_FUNC(int) PyUnicode_IsIdentifier(PyObject *s); diff -r 3ebeeed1eb28 Modules/_io/fileio.c --- a/Modules/_io/fileio.c Fri Apr 10 16:22:14 2015 +0300 +++ b/Modules/_io/fileio.c Fri Apr 10 19:35:04 2015 +0300 @@ -241,15 +241,14 @@ fileio_init(PyObject *oself, PyObject *a #ifdef MS_WINDOWS if (PyUnicode_Check(nameobj)) { - int rv = _PyUnicode_HasNULChars(nameobj); - if (rv) { - if (rv != -1) - PyErr_SetString(PyExc_ValueError, "embedded null character"); + Py_ssize_t length; + widename = PyUnicode_AsUnicodeAndSize(nameobj, &length); + if (widename == NULL) + return -1; + if (wcslen(widename) != length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); return -1; } - widename = PyUnicode_AsUnicode(nameobj); - if (widename == NULL) - return -1; } else #endif if (fd < 0) diff -r 3ebeeed1eb28 Modules/posixmodule.c --- a/Modules/posixmodule.c Fri Apr 10 16:22:14 2015 +0300 +++ b/Modules/posixmodule.c Fri Apr 10 19:35:04 2015 +0300 @@ -866,6 +866,11 @@ path_converter(PyObject *o, void *p) { Py_DECREF(unicode); return 0; } + if (wcslen(wide) != length) { + FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character"); + Py_DECREF(unicode); + return 0; + } path->wide = wide; path->narrow = NULL; diff -r 3ebeeed1eb28 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Fri Apr 10 16:22:14 2015 +0300 +++ b/Objects/unicodeobject.c Fri Apr 10 19:35:04 2015 +0300 @@ -3607,21 +3607,6 @@ PyUnicode_DecodeFSDefaultAndSize(const c int -_PyUnicode_HasNULChars(PyObject* str) -{ - Py_ssize_t pos; - - if (PyUnicode_READY(str) == -1) - return -1; - pos = findchar(PyUnicode_DATA(str), PyUnicode_KIND(str), - PyUnicode_GET_LENGTH(str), '\0', 1); - if (pos == -1) - return 0; - else - return 1; -} - -int PyUnicode_FSConverter(PyObject* arg, void* addr) { PyObject *output = NULL;