Index: Lib/test/test_posix.py =================================================================== --- Lib/test/test_posix.py (revision 73420) +++ Lib/test/test_posix.py (working copy) @@ -175,10 +175,15 @@ posix.chdir(os.curdir) self.assertRaises(OSError, posix.chdir, test_support.TESTFN) - def test_lsdir(self): - if hasattr(posix, 'lsdir'): - self.assert_(test_support.TESTFN in posix.lsdir(os.curdir)) + def test_listdir(self): + if hasattr(posix, 'listdir'): + self.assert_(test_support.TESTFN in posix.listdir(os.curdir)) + def test_listdir_default(self): + # When listdir is called without argument, it's the same as listdir(os.curdir) + if hasattr(posix, 'listdir'): + self.assert_(test_support.TESTFN in posix.listdir()) + def test_access(self): if hasattr(posix, 'access'): self.assert_(posix.access(test_support.TESTFN, os.R_OK)) Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 73420) +++ Modules/posixmodule.c (working copy) @@ -2190,8 +2190,13 @@ /* If on wide-character-capable OS see if argument is Unicode and if so use wide API. */ if (unicode_file_names()) { - PyObject *po; - if (PyArg_ParseTuple(args, "U:listdir", &po)) { + PyObject *po = NULL; + if (PyArg_ParseTuple(args, "|U:listdir", &po)) { + if (po == NULL) { // Default arg: "." + po = PyUnicode_FromWideChar(L".", 1 * sizeof(wchar_t)); + } else { + Py_INCREF(po); + } WIN32_FIND_DATAW wFileData; Py_UNICODE *wnamebuf; /* Overallocate for \\*.*\0 */ @@ -2202,6 +2207,7 @@ return NULL; } wcscpy(wnamebuf, PyUnicode_AS_UNICODE(po)); + Py_DECREF(po); if (len > 0) { Py_UNICODE wch = wnamebuf[len-1]; if (wch != L'/' && wch != L'\\' && wch != L':') @@ -2409,12 +2415,16 @@ int arg_is_unicode = 1; errno = 0; - if (!PyArg_ParseTuple(args, "U:listdir", &v)) { + if (!PyArg_ParseTuple(args, "|U:listdir", &v)) { arg_is_unicode = 0; PyErr_Clear(); } - if (!PyArg_ParseTuple(args, "et:listdir", Py_FileSystemDefaultEncoding, &name)) + if (!PyArg_ParseTuple(args, "|et:listdir", Py_FileSystemDefaultEncoding, &name)) return NULL; + if (name == NULL) { // Default arg: "." + name = (char *)PyMem_Malloc(2); // "." + \0 + strcpy(name, "."); + } if ((dirp = opendir(name)) == NULL) { return posix_error_with_allocated_filename(name); }