diff -r 812f5c379188 Modules/posixmodule.c --- a/Modules/posixmodule.c Tue Oct 30 02:30:31 2012 +0100 +++ b/Modules/posixmodule.c Tue Oct 30 02:41:06 2012 +0100 @@ -1035,17 +1035,6 @@ win32_error(char* function, const char* } static PyObject * -win32_error_unicode(char* function, wchar_t* filename) -{ - /* XXX - see win32_error for comments on 'function' */ - errno = GetLastError(); - if (filename) - return PyErr_SetFromWindowsErrWithUnicodeFilename(errno, filename); - else - return PyErr_SetFromWindowsErr(errno); -} - -static PyObject * win32_error_object(char* function, PyObject* filename) { /* XXX - see win32_error for comments on 'function' */ @@ -1119,44 +1108,6 @@ posix_1str(const char *func_name, PyObje #ifdef MS_WINDOWS -static PyObject* -win32_1str(PyObject* args, char* func, - char* format, BOOL (__stdcall *funcA)(LPCSTR), - char* wformat, BOOL (__stdcall *funcW)(LPWSTR)) -{ - PyObject *uni; - const char *ansi; - BOOL result; - - if (PyArg_ParseTuple(args, wformat, &uni)) - { - wchar_t *wstr = PyUnicode_AsUnicode(uni); - if (wstr == NULL) - return NULL; - Py_BEGIN_ALLOW_THREADS - result = funcW(wstr); - Py_END_ALLOW_THREADS - if (!result) - return win32_error_object(func, uni); - Py_INCREF(Py_None); - return Py_None; - } - PyErr_Clear(); - - if (!PyArg_ParseTuple(args, format, &ansi)) - return NULL; - if (win32_warn_bytes_api()) - return NULL; - Py_BEGIN_ALLOW_THREADS - result = funcA(ansi); - Py_END_ALLOW_THREADS - if (!result) - return win32_error(func, ansi); - Py_INCREF(Py_None); - return Py_None; - -} - /* This is a reimplementation of the C library's chdir function, but one that produces Win32 errors instead of DOS error codes. chdir is essentially a wrapper around SetCurrentDirectory; however, @@ -2533,7 +2484,8 @@ posix_chmod(PyObject *self, PyObject *ar Py_END_ALLOW_THREADS if (!result) { - return_value = win32_error_object("chmod", path.object); + path.function_name = "chmod"; + return_value = path_error(&path); goto exit; } #else /* MS_WINDOWS */ @@ -2989,11 +2941,13 @@ posix_getcwd(int use_bytes) return NULL; } if (!len) { - if (wbuf2 != wbuf) free(wbuf2); - return win32_error("getcwdu", NULL); + if (wbuf2 != wbuf) + free(wbuf2); + return PyErr_SetFromWindowsErr(0); } resobj = PyUnicode_FromWideChar(wbuf2, len); - if (wbuf2 != wbuf) free(wbuf2); + if (wbuf2 != wbuf) + free(wbuf2); return resobj; } @@ -3101,7 +3055,8 @@ posix_link(PyObject *self, PyObject *arg Py_END_ALLOW_THREADS if (!result) { - return_value = win32_error_object("link", dst.object); + path.function_name = "link"; + return_value = path_error(&dst); goto exit; } #else @@ -3225,8 +3180,8 @@ posix_listdir(PyObject *self, PyObject * if (error == ERROR_FILE_NOT_FOUND) goto exit; Py_DECREF(list); - list = NULL; - win32_error_unicode("FindFirstFileW", wnamebuf); + path.function_name = "FindFirstFileW"; + list = path_error(&path); goto exit; } do { @@ -3255,7 +3210,8 @@ posix_listdir(PyObject *self, PyObject * it got to the end of the directory. */ if (!result && GetLastError() != ERROR_NO_MORE_FILES) { Py_DECREF(list); - list = win32_error_unicode("FindNextFileW", wnamebuf); + path.function_name = "FindNextFileW"; + list = path_error(&path); goto exit; } } while (result == TRUE); @@ -3282,7 +3238,8 @@ posix_listdir(PyObject *self, PyObject * if (error == ERROR_FILE_NOT_FOUND) goto exit; Py_DECREF(list); - list = win32_error("FindFirstFile", namebuf); + path.func = "FindFirstFile"; + list = path_error(&path); goto exit; } do { @@ -3310,7 +3267,8 @@ posix_listdir(PyObject *self, PyObject * it got to the end of the directory. */ if (!result && GetLastError() != ERROR_NO_MORE_FILES) { Py_DECREF(list); - list = win32_error("FindNextFile", namebuf); + path.func = "FindNextFile"; + list = path_error(&path); goto exit; } } while (result == TRUE); @@ -3320,7 +3278,8 @@ exit: if (FindClose(hFindFile) == FALSE) { if (list != NULL) { Py_DECREF(list); - list = win32_error_object("FindClose", path.object); + path.function_name = "FindClose"; + list = path_error(&path); } } } @@ -3569,7 +3528,7 @@ posix__getfileinformation(PyObject *self return posix_error(); if (!GetFileInformationByHandle(hFile, &info)) - return win32_error("_getfileinformation", NULL); + return PyErr_SetFromWindowsErr(0); return Py_BuildValue("iii", info.dwVolumeSerialNumber, info.nFileIndexHigh, @@ -3658,7 +3617,8 @@ posix_mkdir(PyObject *self, PyObject *ar Py_END_ALLOW_THREADS if (!result) { - return_value = win32_error_object("mkdir", path.object); + path.function_name = "mkdir"; + return_value = path_error(&path); goto exit; } #else @@ -3828,7 +3788,8 @@ internal_rename(PyObject *args, PyObject Py_END_ALLOW_THREADS if (!result) { - return_value = win32_error_object(function_name, dst.object); + path.function_name = function_name; + return_value = path_error(&dst); goto exit; } @@ -4484,7 +4445,8 @@ posix_utime(PyObject *self, PyObject *ar FILE_FLAG_BACKUP_SEMANTICS, NULL); Py_END_ALLOW_THREADS if (hFile == INVALID_HANDLE_VALUE) { - win32_error_object("utime", path.object); + path.function_name = "utime"; + path_error(&path); goto exit; } @@ -4493,7 +4455,7 @@ posix_utime(PyObject *self, PyObject *ar GetSystemTime(&now); if (!SystemTimeToFileTime(&now, &mtime) || !SystemTimeToFileTime(&now, &atime)) { - win32_error("utime", NULL); + PyErr_SetFromWindowsErr(0); goto exit; } } @@ -4506,7 +4468,7 @@ posix_utime(PyObject *self, PyObject *ar as that may confuse the user into believing that something is wrong with the file, when it also could be the time stamp that gives a problem. */ - win32_error("utime", NULL); + PyErr_SetFromWindowsErr(0); goto exit; } #else /* MS_WINDOWS */ @@ -6736,7 +6698,8 @@ posix_symlink(PyObject *self, PyObject * Py_END_ALLOW_THREADS if (!result) { - return_value = win32_error_object("symlink", src.object); + path.function_name = "symlink"; + return_value = path_error(&src); goto exit; } @@ -7648,7 +7611,7 @@ posix_fstat(PyObject *self, PyObject *ar Py_END_ALLOW_THREADS if (res != 0) { #ifdef MS_WINDOWS - return win32_error("fstat", NULL); + return PyErr_SetFromWindowsErr(0); #else return posix_error(); #endif @@ -7694,7 +7657,7 @@ posix_pipe(PyObject *self, PyObject *noa BOOL ok; ok = CreatePipe(&read, &write, NULL, 0); if (!ok) - return win32_error("CreatePipe", NULL); + return PyErr_SetFromWindowsErr(0); read_fd = _open_osfhandle((Py_intptr_t)read, 0); write_fd = _open_osfhandle((Py_intptr_t)write, 1); return Py_BuildValue("(ii)", read_fd, write_fd);