Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 66545) +++ Modules/posixmodule.c (working copy) @@ -2323,10 +2323,10 @@ #else char *name = NULL; - PyObject *d, *v; + PyObject *d, *v, *warning; DIR *dirp; struct dirent *ep; - int arg_is_unicode = 1; + int arg_is_unicode = 1, ret; errno = 0; if (!PyArg_ParseTuple(args, "U:listdir", &v)) { @@ -2378,9 +2378,21 @@ v = w; } else { - /* fall back to the original byte string, as - discussed in patch #683592 */ PyErr_Clear(); + warning = PyUnicode_FromFormat( + "Can't decode file name %R; ignoring", + v); + ret = PyErr_WarnEx(PyExc_UnicodeWarning, + _PyUnicode_AsString(warning), + 2); + Py_DECREF(warning); + if (ret < 0) { + Py_DECREF(v); + Py_DECREF(d); + d = NULL; + break; + } + continue; } } if (PyList_Append(d, v) != 0) {