[Python-checkins] r73603 - in python/trunk: Misc/NEWS Modules/_io/fileio.c Modules/posixmodule.c Objects/fileobject.c PC/pyconfig.h

hirokazu.yamamoto python-checkins at python.org
Sun Jun 28 12:23:00 CEST 2009


Author: hirokazu.yamamoto
Date: Sun Jun 28 12:23:00 2009
New Revision: 73603

Log:
Issue #4856: Remove checks for win NT.

Modified:
   python/trunk/Misc/NEWS
   python/trunk/Modules/_io/fileio.c
   python/trunk/Modules/posixmodule.c
   python/trunk/Objects/fileobject.c
   python/trunk/PC/pyconfig.h

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Jun 28 12:23:00 2009
@@ -12,6 +12,8 @@
 Core and Builtins
 -----------------
 
+- Issue #4856: Remove checks for win NT.
+
 - Issue #2016: Fixed a crash in a corner case where the dictionary of keyword
   arguments could be modified during the function call setup.
 

Modified: python/trunk/Modules/_io/fileio.c
==============================================================================
--- python/trunk/Modules/_io/fileio.c	(original)
+++ python/trunk/Modules/_io/fileio.c	Sun Jun 28 12:23:00 2009
@@ -224,11 +224,8 @@
 	}
 
 #ifdef MS_WINDOWS
-	if (GetVersion() < 0x80000000) {
-		/* On NT, so wide API available */
-		if (PyUnicode_Check(nameobj))
-			widename = PyUnicode_AS_UNICODE(nameobj);
-	}
+	if (PyUnicode_Check(nameobj))
+		widename = PyUnicode_AS_UNICODE(nameobj);
 	if (widename == NULL)
 #endif
 	if (fd < 0)

Modified: python/trunk/Modules/posixmodule.c
==============================================================================
--- python/trunk/Modules/posixmodule.c	(original)
+++ python/trunk/Modules/posixmodule.c	Sun Jun 28 12:23:00 2009
@@ -700,20 +700,6 @@
 	return Py_None;
 }
 
-#ifdef MS_WINDOWS
-static int
-unicode_file_names(void)
-{
-	static int canusewide = -1;
-	if (canusewide == -1) {
-		/* As per doc for ::GetVersion(), this is the correct test for
-		   the Windows NT family. */
-		canusewide = (GetVersion() < 0x80000000) ? 1 : 0;
-	}
-	return canusewide;
-}
-#endif
-
 static PyObject *
 posix_1str(PyObject *args, char *format, int (*func)(const char*))
 {
@@ -764,18 +750,17 @@
 	PyObject *uni;
 	char *ansi;
 	BOOL result;
-	if (unicode_file_names()) {
-		if (!PyArg_ParseTuple(args, wformat, &uni))
-			PyErr_Clear();
-		else {
-			Py_BEGIN_ALLOW_THREADS
-			result = funcW(PyUnicode_AsUnicode(uni));
-			Py_END_ALLOW_THREADS
-			if (!result)
-				return win32_error_unicode(func, PyUnicode_AsUnicode(uni));
-			Py_INCREF(Py_None);
-			return Py_None;
-		}
+
+	if (!PyArg_ParseTuple(args, wformat, &uni))
+		PyErr_Clear();
+	else {
+		Py_BEGIN_ALLOW_THREADS
+		result = funcW(PyUnicode_AsUnicode(uni));
+		Py_END_ALLOW_THREADS
+		if (!result)
+			return win32_error_unicode(func, PyUnicode_AsUnicode(uni));
+		Py_INCREF(Py_None);
+		return Py_None;
 	}
 	if (!PyArg_ParseTuple(args, format, &ansi))
 		return NULL;
@@ -938,22 +923,6 @@
 	return 0;
 }
 
-/* Emulate GetFileAttributesEx[AW] on Windows 95 */
-static int checked = 0;
-static BOOL (CALLBACK *gfaxa)(LPCSTR, GET_FILEEX_INFO_LEVELS, LPVOID);
-static BOOL (CALLBACK *gfaxw)(LPCWSTR, GET_FILEEX_INFO_LEVELS, LPVOID);
-static void
-check_gfax()
-{
-	HINSTANCE hKernel32;
-	if (checked)
-	    return;
-	checked = 1;
-	hKernel32 = GetModuleHandle("KERNEL32");
-	*(FARPROC*)&gfaxa = GetProcAddress(hKernel32, "GetFileAttributesExA");
-	*(FARPROC*)&gfaxw = GetProcAddress(hKernel32, "GetFileAttributesExW");
-}
-
 static BOOL
 attributes_from_dir(LPCSTR pszFile, LPWIN32_FILE_ATTRIBUTE_DATA pfad)
 {
@@ -1000,12 +969,9 @@
 	/* First try to use the system's implementation, if that is
 	   available and either succeeds to gives an error other than
 	   that it isn't implemented. */
-	check_gfax();
-	if (gfaxa) {
-		result = gfaxa(pszFile, level, pv);
-		if (result || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
-			return result;
-	}
+	result = GetFileAttributesExA(pszFile, level, pv);
+	if (result || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
+		return result;
 	/* It's either not present, or not implemented.
 	   Emulate using FindFirstFile. */
 	if (level != GetFileExInfoStandard) {
@@ -1030,12 +996,9 @@
 	/* First try to use the system's implementation, if that is
 	   available and either succeeds to gives an error other than
 	   that it isn't implemented. */
-	check_gfax();
-	if (gfaxa) {
-		result = gfaxw(pszFile, level, pv);
-		if (result || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
-			return result;
-	}
+	result = GetFileAttributesExW(pszFile, level, pv);
+	if (result || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
+		return result;
 	/* It's either not present, or not implemented.
 	   Emulate using FindFirstFile. */
 	if (level != GetFileExInfoStandard) {
@@ -1553,27 +1516,23 @@
 	PyObject *result;
 
 #ifdef MS_WINDOWS
-	/* If on wide-character-capable OS see if argument
-	   is Unicode and if so use wide API.  */
-	if (unicode_file_names()) {
-		PyUnicodeObject *po;
-		if (PyArg_ParseTuple(args, wformat, &po)) {
-			Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);
+	PyUnicodeObject *po;
+	if (PyArg_ParseTuple(args, wformat, &po)) {
+		Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);
 
-			Py_BEGIN_ALLOW_THREADS
-				/* PyUnicode_AS_UNICODE result OK without
-				   thread lock as it is a simple dereference. */
-			res = wstatfunc(wpath, &st);
-			Py_END_ALLOW_THREADS
+		Py_BEGIN_ALLOW_THREADS
+			/* PyUnicode_AS_UNICODE result OK without
+			   thread lock as it is a simple dereference. */
+		res = wstatfunc(wpath, &st);
+		Py_END_ALLOW_THREADS
 
-			if (res != 0)
-				return win32_error_unicode("stat", wpath);
-			return _pystat_fromstructstat(&st);
-		}
-		/* Drop the argument parsing error as narrow strings
-		   are also valid. */
-		PyErr_Clear();
-	}
+		if (res != 0)
+			return win32_error_unicode("stat", wpath);
+		return _pystat_fromstructstat(&st);
+	}
+	/* Drop the argument parsing error as narrow strings
+	   are also valid. */
+	PyErr_Clear();
 #endif
 
 	if (!PyArg_ParseTuple(args, format,
@@ -1617,23 +1576,21 @@
 	
 #ifdef MS_WINDOWS
 	DWORD attr;
-	if (unicode_file_names()) {
-		PyUnicodeObject *po;
-		if (PyArg_ParseTuple(args, "Ui:access", &po, &mode)) {
-			Py_BEGIN_ALLOW_THREADS
-			/* PyUnicode_AS_UNICODE OK without thread lock as
-			   it is a simple dereference. */
-			attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po));
-			Py_END_ALLOW_THREADS
-			goto finish;
-		}
-		/* Drop the argument parsing error as narrow strings
-		   are also valid. */
-		PyErr_Clear();
+	PyUnicodeObject *po;
+	if (PyArg_ParseTuple(args, "Ui:access", &po, &mode)) {
+		Py_BEGIN_ALLOW_THREADS
+		/* PyUnicode_AS_UNICODE OK without thread lock as
+		   it is a simple dereference. */
+		attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po));
+		Py_END_ALLOW_THREADS
+		goto finish;
 	}
+	/* Drop the argument parsing error as narrow strings
+	   are also valid. */
+	PyErr_Clear();
 	if (!PyArg_ParseTuple(args, "eti:access",
 			      Py_FileSystemDefaultEncoding, &path, &mode))
-		return 0;
+		return NULL;
 	Py_BEGIN_ALLOW_THREADS
 	attr = GetFileAttributesA(path);
 	Py_END_ALLOW_THREADS
@@ -1771,31 +1728,30 @@
 	int res;
 #ifdef MS_WINDOWS
 	DWORD attr;
-	if (unicode_file_names()) {
-		PyUnicodeObject *po;
-		if (PyArg_ParseTuple(args, "Ui|:chmod", &po, &i)) {
-			Py_BEGIN_ALLOW_THREADS
-			attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po));
-			if (attr != 0xFFFFFFFF) {
-				if (i & _S_IWRITE)
-					attr &= ~FILE_ATTRIBUTE_READONLY;
-				else
-					attr |= FILE_ATTRIBUTE_READONLY;
-				res = SetFileAttributesW(PyUnicode_AS_UNICODE(po), attr);
-			}
+	PyUnicodeObject *po;
+	if (PyArg_ParseTuple(args, "Ui|:chmod", &po, &i)) {
+		Py_BEGIN_ALLOW_THREADS
+		attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po));
+		if (attr != 0xFFFFFFFF) {
+			if (i & _S_IWRITE)
+				attr &= ~FILE_ATTRIBUTE_READONLY;
 			else
-				res = 0;
-			Py_END_ALLOW_THREADS
-			if (!res)
-				return win32_error_unicode("chmod",
-						PyUnicode_AS_UNICODE(po));
-			Py_INCREF(Py_None);
-			return Py_None;
+				attr |= FILE_ATTRIBUTE_READONLY;
+			res = SetFileAttributesW(PyUnicode_AS_UNICODE(po), attr);
 		}
-		/* Drop the argument parsing error as narrow strings
-		   are also valid. */
-		PyErr_Clear();
+		else
+			res = 0;
+		Py_END_ALLOW_THREADS
+		if (!res)
+			return win32_error_unicode("chmod",
+					PyUnicode_AS_UNICODE(po));
+		Py_INCREF(Py_None);
+		return Py_None;
 	}
+	/* Drop the argument parsing error as narrow strings
+	   are also valid. */
+	PyErr_Clear();
+
 	if (!PyArg_ParseTuple(args, "eti:chmod", Py_FileSystemDefaultEncoding,
 	                      &path, &i))
 		return NULL;
@@ -2106,33 +2062,31 @@
 
 #ifdef MS_WINDOWS
 	DWORD len;
-	if (unicode_file_names()) {
-		wchar_t wbuf[1026];
-		wchar_t *wbuf2 = wbuf;
-		PyObject *resobj;
-		Py_BEGIN_ALLOW_THREADS
-		len = GetCurrentDirectoryW(sizeof wbuf/ sizeof wbuf[0], wbuf);
-		/* If the buffer is large enough, len does not include the
-		   terminating \0. If the buffer is too small, len includes
-		   the space needed for the terminator. */
-		if (len >= sizeof wbuf/ sizeof wbuf[0]) {
-			wbuf2 = malloc(len * sizeof(wchar_t));
-			if (wbuf2)
-				len = GetCurrentDirectoryW(len, wbuf2);
-		}
-		Py_END_ALLOW_THREADS
-		if (!wbuf2) {
-			PyErr_NoMemory();
-			return NULL;
-		}
-		if (!len) {
-			if (wbuf2 != wbuf) free(wbuf2);
-			return win32_error("getcwdu", NULL);
-		}
-		resobj = PyUnicode_FromWideChar(wbuf2, len);
+	wchar_t wbuf[1026];
+	wchar_t *wbuf2 = wbuf;
+	PyObject *resobj;
+	Py_BEGIN_ALLOW_THREADS
+	len = GetCurrentDirectoryW(sizeof wbuf/ sizeof wbuf[0], wbuf);
+	/* If the buffer is large enough, len does not include the
+	   terminating \0. If the buffer is too small, len includes
+	   the space needed for the terminator. */
+	if (len >= sizeof wbuf/ sizeof wbuf[0]) {
+		wbuf2 = malloc(len * sizeof(wchar_t));
+		if (wbuf2)
+			len = GetCurrentDirectoryW(len, wbuf2);
+	}
+	Py_END_ALLOW_THREADS
+	if (!wbuf2) {
+		PyErr_NoMemory();
+		return NULL;
+	}
+	if (!len) {
 		if (wbuf2 != wbuf) free(wbuf2);
-		return resobj;
+		return win32_error("getcwdu", NULL);
 	}
+	resobj = PyUnicode_FromWideChar(wbuf2, len);
+	if (wbuf2 != wbuf) free(wbuf2);
+	return resobj;
 #endif /* MS_WINDOWS */
 
 	Py_BEGIN_ALLOW_THREADS
@@ -2187,88 +2141,84 @@
 	char *bufptr = namebuf;
 	Py_ssize_t len = sizeof(namebuf)-5; /* only claim to have space for MAX_PATH */
 
-	/* 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)) {
-			WIN32_FIND_DATAW wFileData;
-			Py_UNICODE *wnamebuf;
-			/* Overallocate for \\*.*\0 */
-			len = PyUnicode_GET_SIZE(po);
-			wnamebuf = malloc((len + 5) * sizeof(wchar_t));
-			if (!wnamebuf) {
-				PyErr_NoMemory();
-				return NULL;
-			}
-			wcscpy(wnamebuf, PyUnicode_AS_UNICODE(po));
-			if (len > 0) {
-				Py_UNICODE wch = wnamebuf[len-1];
-				if (wch != L'/' && wch != L'\\' && wch != L':')
-					wnamebuf[len++] = L'\\';
-				wcscpy(wnamebuf + len, L"*.*");
-			}
-			if ((d = PyList_New(0)) == NULL) {
+	PyObject *po;
+	if (PyArg_ParseTuple(args, "U:listdir", &po)) {
+		WIN32_FIND_DATAW wFileData;
+		Py_UNICODE *wnamebuf;
+		/* Overallocate for \\*.*\0 */
+		len = PyUnicode_GET_SIZE(po);
+		wnamebuf = malloc((len + 5) * sizeof(wchar_t));
+		if (!wnamebuf) {
+			PyErr_NoMemory();
+			return NULL;
+		}
+		wcscpy(wnamebuf, PyUnicode_AS_UNICODE(po));
+		if (len > 0) {
+			Py_UNICODE wch = wnamebuf[len-1];
+			if (wch != L'/' && wch != L'\\' && wch != L':')
+				wnamebuf[len++] = L'\\';
+			wcscpy(wnamebuf + len, L"*.*");
+		}
+		if ((d = PyList_New(0)) == NULL) {
+			free(wnamebuf);
+			return NULL;
+		}
+		hFindFile = FindFirstFileW(wnamebuf, &wFileData);
+		if (hFindFile == INVALID_HANDLE_VALUE) {
+			int error = GetLastError();
+			if (error == ERROR_FILE_NOT_FOUND) {
 				free(wnamebuf);
-				return NULL;
+				return d;
 			}
-			hFindFile = FindFirstFileW(wnamebuf, &wFileData);
-			if (hFindFile == INVALID_HANDLE_VALUE) {
-				int error = GetLastError();
-				if (error == ERROR_FILE_NOT_FOUND) {
-					free(wnamebuf);
-					return d;
+			Py_DECREF(d);
+			win32_error_unicode("FindFirstFileW", wnamebuf);
+			free(wnamebuf);
+			return NULL;
+		}
+		do {
+			/* Skip over . and .. */
+			if (wcscmp(wFileData.cFileName, L".") != 0 &&
+			    wcscmp(wFileData.cFileName, L"..") != 0) {
+				v = PyUnicode_FromUnicode(wFileData.cFileName, wcslen(wFileData.cFileName));
+				if (v == NULL) {
+					Py_DECREF(d);
+					d = NULL;
+					break;
 				}
-				Py_DECREF(d);
-				win32_error_unicode("FindFirstFileW", wnamebuf);
-				free(wnamebuf);
-				return NULL;
-			}
-			do {
-				/* Skip over . and .. */
-				if (wcscmp(wFileData.cFileName, L".") != 0 &&
-				    wcscmp(wFileData.cFileName, L"..") != 0) {
-					v = PyUnicode_FromUnicode(wFileData.cFileName, wcslen(wFileData.cFileName));
-					if (v == NULL) {
-						Py_DECREF(d);
-						d = NULL;
-						break;
-					}
-					if (PyList_Append(d, v) != 0) {
-						Py_DECREF(v);
-						Py_DECREF(d);
-						d = NULL;
-						break;
-					}
+				if (PyList_Append(d, v) != 0) {
 					Py_DECREF(v);
+					Py_DECREF(d);
+					d = NULL;
+					break;
 				}
-				Py_BEGIN_ALLOW_THREADS
-				result = FindNextFileW(hFindFile, &wFileData);
-				Py_END_ALLOW_THREADS
-				/* FindNextFile sets error to ERROR_NO_MORE_FILES if
-				   it got to the end of the directory. */
-				if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
-				    Py_DECREF(d);
-				    win32_error_unicode("FindNextFileW", wnamebuf);
-				    FindClose(hFindFile);
-				    free(wnamebuf);
-				    return NULL;
-				}
-			} while (result == TRUE);
-
-			if (FindClose(hFindFile) == FALSE) {
-				Py_DECREF(d);
-				win32_error_unicode("FindClose", wnamebuf);
-				free(wnamebuf);
-				return NULL;
+				Py_DECREF(v);
+			}
+			Py_BEGIN_ALLOW_THREADS
+			result = FindNextFileW(hFindFile, &wFileData);
+			Py_END_ALLOW_THREADS
+			/* FindNextFile sets error to ERROR_NO_MORE_FILES if
+			   it got to the end of the directory. */
+			if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
+			    Py_DECREF(d);
+			    win32_error_unicode("FindNextFileW", wnamebuf);
+			    FindClose(hFindFile);
+			    free(wnamebuf);
+			    return NULL;
 			}
+		} while (result == TRUE);
+
+		if (FindClose(hFindFile) == FALSE) {
+			Py_DECREF(d);
+			win32_error_unicode("FindClose", wnamebuf);
 			free(wnamebuf);
-			return d;
+			return NULL;
 		}
-		/* Drop the argument parsing error as narrow strings
-		   are also valid. */
-		PyErr_Clear();
+		free(wnamebuf);
+		return d;
 	}
+	/* Drop the argument parsing error as narrow strings
+	   are also valid. */
+	PyErr_Clear();
 
 	if (!PyArg_ParseTuple(args, "et#:listdir",
 	                      Py_FileSystemDefaultEncoding, &bufptr, &len))
@@ -2493,35 +2443,33 @@
 	char outbuf[MAX_PATH*2];
 	char *temp;
 
-	if (unicode_file_names()) {
-		PyUnicodeObject *po;
-		if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) {
-			Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);
-			Py_UNICODE woutbuf[MAX_PATH*2], *woutbufp = woutbuf;
-			Py_UNICODE *wtemp;
-			DWORD result;
-			PyObject *v;
-			result = GetFullPathNameW(wpath,
-						   sizeof(woutbuf)/sizeof(woutbuf[0]),
-						    woutbuf, &wtemp);
-			if (result > sizeof(woutbuf)/sizeof(woutbuf[0])) {
-				woutbufp = malloc(result * sizeof(Py_UNICODE));
-				if (!woutbufp)
-					return PyErr_NoMemory();
-				result = GetFullPathNameW(wpath, result, woutbufp, &wtemp);
-			}
-			if (result)
-				v = PyUnicode_FromUnicode(woutbufp, wcslen(woutbufp));
-			else
-				v = win32_error_unicode("GetFullPathNameW", wpath);
-			if (woutbufp != woutbuf)
-				free(woutbufp);
-			return v;
+	PyUnicodeObject *po;
+	if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) {
+		Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);
+		Py_UNICODE woutbuf[MAX_PATH*2], *woutbufp = woutbuf;
+		Py_UNICODE *wtemp;
+		DWORD result;
+		PyObject *v;
+		result = GetFullPathNameW(wpath,
+					   sizeof(woutbuf)/sizeof(woutbuf[0]),
+					    woutbuf, &wtemp);
+		if (result > sizeof(woutbuf)/sizeof(woutbuf[0])) {
+			woutbufp = malloc(result * sizeof(Py_UNICODE));
+			if (!woutbufp)
+				return PyErr_NoMemory();
+			result = GetFullPathNameW(wpath, result, woutbufp, &wtemp);
 		}
-		/* Drop the argument parsing error as narrow strings
-		   are also valid. */
-		PyErr_Clear();
-	}
+		if (result)
+			v = PyUnicode_FromUnicode(woutbufp, wcslen(woutbufp));
+		else
+			v = win32_error_unicode("GetFullPathNameW", wpath);
+		if (woutbufp != woutbuf)
+			free(woutbufp);
+		return v;
+	}
+	/* Drop the argument parsing error as narrow strings
+	   are also valid. */
+	PyErr_Clear();
 
 	if (!PyArg_ParseTuple (args, "et#:_getfullpathname",
 	                       Py_FileSystemDefaultEncoding, &inbufp,
@@ -2550,23 +2498,21 @@
 	int mode = 0777;
 
 #ifdef MS_WINDOWS
-	if (unicode_file_names()) {
-		PyUnicodeObject *po;
-		if (PyArg_ParseTuple(args, "U|i:mkdir", &po, &mode)) {
-			Py_BEGIN_ALLOW_THREADS
-			/* PyUnicode_AS_UNICODE OK without thread lock as
-			   it is a simple dereference. */
-			res = CreateDirectoryW(PyUnicode_AS_UNICODE(po), NULL);
-			Py_END_ALLOW_THREADS
-			if (!res)
-				return win32_error_unicode("mkdir", PyUnicode_AS_UNICODE(po));
-			Py_INCREF(Py_None);
-			return Py_None;
-		}
-		/* Drop the argument parsing error as narrow strings
-		   are also valid. */
-		PyErr_Clear();
+	PyUnicodeObject *po;
+	if (PyArg_ParseTuple(args, "U|i:mkdir", &po, &mode)) {
+		Py_BEGIN_ALLOW_THREADS
+		/* PyUnicode_AS_UNICODE OK without thread lock as
+		   it is a simple dereference. */
+		res = CreateDirectoryW(PyUnicode_AS_UNICODE(po), NULL);
+		Py_END_ALLOW_THREADS
+		if (!res)
+			return win32_error_unicode("mkdir", PyUnicode_AS_UNICODE(po));
+		Py_INCREF(Py_None);
+		return Py_None;
 	}
+	/* Drop the argument parsing error as narrow strings
+	   are also valid. */
+	PyErr_Clear();
 	if (!PyArg_ParseTuple(args, "et|i:mkdir",
 	                      Py_FileSystemDefaultEncoding, &path, &mode))
 		return NULL;
@@ -2657,28 +2603,26 @@
 	PyObject *o1, *o2;
 	char *p1, *p2;
 	BOOL result;
-	if (unicode_file_names()) {
-	    if (!PyArg_ParseTuple(args, "OO:rename", &o1, &o2))
+	if (!PyArg_ParseTuple(args, "OO:rename", &o1, &o2))
 		goto error;
-	    if (!convert_to_unicode(&o1))
+	if (!convert_to_unicode(&o1))
 		goto error;
-	    if (!convert_to_unicode(&o2)) {
+	if (!convert_to_unicode(&o2)) {
 		Py_DECREF(o1);
 		goto error;
-	    }
-	    Py_BEGIN_ALLOW_THREADS
-	    result = MoveFileW(PyUnicode_AsUnicode(o1),
-			       PyUnicode_AsUnicode(o2));
-	    Py_END_ALLOW_THREADS
-	    Py_DECREF(o1);
-	    Py_DECREF(o2);
-	    if (!result)
-		    return win32_error("rename", NULL);
-	    Py_INCREF(Py_None);
-	    return Py_None;
-error:
-	    PyErr_Clear();
 	}
+	Py_BEGIN_ALLOW_THREADS
+	result = MoveFileW(PyUnicode_AsUnicode(o1),
+			   PyUnicode_AsUnicode(o2));
+	Py_END_ALLOW_THREADS
+	Py_DECREF(o1);
+	Py_DECREF(o2);
+	if (!result)
+		return win32_error("rename", NULL);
+	Py_INCREF(Py_None);
+	return Py_None;
+error:
+	PyErr_Clear();
 	if (!PyArg_ParseTuple(args, "ss:rename", &p1, &p2))
 		return NULL;
 	Py_BEGIN_ALLOW_THREADS
@@ -2853,21 +2797,20 @@
 	FILETIME atime, mtime;
 	PyObject *result = NULL;
 
-	if (unicode_file_names()) {
-		if (PyArg_ParseTuple(args, "UO|:utime", &obwpath, &arg)) {
-			wpath = PyUnicode_AS_UNICODE(obwpath);
-			Py_BEGIN_ALLOW_THREADS
-			hFile = CreateFileW(wpath, FILE_WRITE_ATTRIBUTES, 0,
-					    NULL, OPEN_EXISTING,
-					    FILE_FLAG_BACKUP_SEMANTICS, NULL);
-			Py_END_ALLOW_THREADS
-			if (hFile == INVALID_HANDLE_VALUE)
-				return win32_error_unicode("utime", wpath);
-		} else
-			/* Drop the argument parsing error as narrow strings
-			   are also valid. */
-			PyErr_Clear();
-	}
+	if (PyArg_ParseTuple(args, "UO|:utime", &obwpath, &arg)) {
+		wpath = PyUnicode_AS_UNICODE(obwpath);
+		Py_BEGIN_ALLOW_THREADS
+		hFile = CreateFileW(wpath, FILE_WRITE_ATTRIBUTES, 0,
+				    NULL, OPEN_EXISTING,
+				    FILE_FLAG_BACKUP_SEMANTICS, NULL);
+		Py_END_ALLOW_THREADS
+		if (hFile == INVALID_HANDLE_VALUE)
+			return win32_error_unicode("utime", wpath);
+	} else
+		/* Drop the argument parsing error as narrow strings
+		   are also valid. */
+		PyErr_Clear();
+
 	if (!wpath) {
 		if (!PyArg_ParseTuple(args, "etO:utime",
 				Py_FileSystemDefaultEncoding, &apath, &arg))
@@ -6296,22 +6239,20 @@
 	int fd;
 
 #ifdef MS_WINDOWS
-	if (unicode_file_names()) {
-		PyUnicodeObject *po;
-		if (PyArg_ParseTuple(args, "Ui|i:mkdir", &po, &flag, &mode)) {
-			Py_BEGIN_ALLOW_THREADS
-			/* PyUnicode_AS_UNICODE OK without thread
-			   lock as it is a simple dereference. */
-			fd = _wopen(PyUnicode_AS_UNICODE(po), flag, mode);
-			Py_END_ALLOW_THREADS
-			if (fd < 0)
-				return posix_error();
-			return PyInt_FromLong((long)fd);
-		}
-		/* Drop the argument parsing error as narrow strings
-		   are also valid. */
-		PyErr_Clear();
+	PyUnicodeObject *po;
+	if (PyArg_ParseTuple(args, "Ui|i:mkdir", &po, &flag, &mode)) {
+		Py_BEGIN_ALLOW_THREADS
+		/* PyUnicode_AS_UNICODE OK without thread
+		   lock as it is a simple dereference. */
+		fd = _wopen(PyUnicode_AS_UNICODE(po), flag, mode);
+		Py_END_ALLOW_THREADS
+		if (fd < 0)
+			return posix_error();
+		return PyInt_FromLong((long)fd);
 	}
+	/* Drop the argument parsing error as narrow strings
+	   are also valid. */
+	PyErr_Clear();
 #endif
 
 	if (!PyArg_ParseTuple(args, "eti|i",
@@ -8290,40 +8231,37 @@
 	char *operation = NULL;
 	HINSTANCE rc;
 
-	if (unicode_file_names()) {
-		PyObject *unipath, *woperation = NULL;
-		if (!PyArg_ParseTuple(args, "U|s:startfile",
-				      &unipath, &operation)) {
+	PyObject *unipath, *woperation = NULL;
+	if (!PyArg_ParseTuple(args, "U|s:startfile",
+			      &unipath, &operation)) {
+		PyErr_Clear();
+		goto normal;
+	}
+
+	if (operation) {
+		woperation = PyUnicode_DecodeASCII(operation, 
+						   strlen(operation), NULL);
+		if (!woperation) {
 			PyErr_Clear();
+			operation = NULL;
 			goto normal;
 		}
+	}
 		
+	Py_BEGIN_ALLOW_THREADS
+	rc = ShellExecuteW((HWND)0, woperation ? PyUnicode_AS_UNICODE(woperation) : 0,
+		PyUnicode_AS_UNICODE(unipath),
+		NULL, NULL, SW_SHOWNORMAL);
+	Py_END_ALLOW_THREADS
 
-		if (operation) {
-		    woperation = PyUnicode_DecodeASCII(operation, 
-						       strlen(operation), NULL);
-		    if (!woperation) {
-			    PyErr_Clear();
-			    operation = NULL;
-			    goto normal;
-		    }
-		}
-			
-		Py_BEGIN_ALLOW_THREADS
-		rc = ShellExecuteW((HWND)0, woperation ? PyUnicode_AS_UNICODE(woperation) : 0,
-			PyUnicode_AS_UNICODE(unipath),
-			NULL, NULL, SW_SHOWNORMAL);
-		Py_END_ALLOW_THREADS
-
-		Py_XDECREF(woperation);
-		if (rc <= (HINSTANCE)32) {
-			PyObject *errval = win32_error_unicode("startfile",
-						PyUnicode_AS_UNICODE(unipath));
-			return errval;
-		}
-		Py_INCREF(Py_None);
-		return Py_None;
+	Py_XDECREF(woperation);
+	if (rc <= (HINSTANCE)32) {
+		PyObject *errval = win32_error_unicode("startfile",
+					PyUnicode_AS_UNICODE(unipath));
+		return errval;
 	}
+	Py_INCREF(Py_None);
+	return Py_None;
 
 normal:
 	if (!PyArg_ParseTuple(args, "et|s:startfile", 

Modified: python/trunk/Objects/fileobject.c
==============================================================================
--- python/trunk/Objects/fileobject.c	(original)
+++ python/trunk/Objects/fileobject.c	Sun Jun 28 12:23:00 2009
@@ -16,12 +16,6 @@
 #include <windows.h>
 #endif
 
-#ifdef _MSC_VER
-/* Need GetVersion to see if on NT so safe to use _wfopen */
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#endif /* _MSC_VER */
-
 #if defined(PYOS_OS2) && defined(PYCC_GCC)
 #include <io.h>
 #endif
@@ -2244,6 +2238,7 @@
 	char *mode = "r";
 	int bufsize = -1;
 	int wideargument = 0;
+	PyObject *po;
 
 	assert(PyFile_Check(self));
 	if (foself->f_fp != NULL) {
@@ -2255,19 +2250,16 @@
 	}
 
 #ifdef MS_WINDOWS
-	if (GetVersion() < 0x80000000) {    /* On NT, so wide API available */
-		PyObject *po;
-		if (PyArg_ParseTupleAndKeywords(args, kwds, "U|si:file",
-						kwlist, &po, &mode, &bufsize)) {
-			wideargument = 1;
-			if (fill_file_fields(foself, NULL, po, mode,
-					     fclose) == NULL)
-				goto Error;
-		} else {
-			/* Drop the argument parsing error as narrow
-			   strings are also valid. */
-			PyErr_Clear();
-		}
+	if (PyArg_ParseTupleAndKeywords(args, kwds, "U|si:file",
+					kwlist, &po, &mode, &bufsize)) {
+		wideargument = 1;
+		if (fill_file_fields(foself, NULL, po, mode,
+				     fclose) == NULL)
+			goto Error;
+	} else {
+		/* Drop the argument parsing error as narrow
+		   strings are also valid. */
+		PyErr_Clear();
 	}
 #endif
 

Modified: python/trunk/PC/pyconfig.h
==============================================================================
--- python/trunk/PC/pyconfig.h	(original)
+++ python/trunk/PC/pyconfig.h	Sun Jun 28 12:23:00 2009
@@ -95,12 +95,6 @@
 #endif
 
 #ifdef MS_WINCE
-/* Python uses GetVersion() to distinguish between
- * Windows NT and 9x/ME where OS Unicode support is concerned.
- * Windows CE supports Unicode in the same way as NT so we
- * define the missing GetVersion() accordingly.
- */
-#define GetVersion() (4)
 /* Windows CE does not support environment variables */
 #define getenv(v) (NULL)
 #define environ (NULL)


More information about the Python-checkins mailing list