Index: Python/sysmodule.c =================================================================== --- Python/sysmodule.c (revision 62635) +++ Python/sysmodule.c (working copy) @@ -579,6 +579,36 @@ ver.szCSDVersion); } +PyDoc_STRVAR(iswow64process_doc, +"iswow64process()\n\ +\n\ +Returns True if this is a 32bit process running on a 64bit Windows.\n\ +This is a thin wrapper around the win32 API IsWow64Process() and False is\n\ +returned if that is not available for this version of Windows. If the\n\ +function exists but fails, a WindowsError will be thrown.\n\ +" +); + +static PyObject * +sys_iswow64process(PyObject *self) +{ + BOOL bIsWow64 = FALSE; + typedef BOOL (WINAPI *IsWow64Processfunc)(HANDLE, PBOOL); + IsWow64Processfunc pfnIsWow64Process = NULL; + + // Kernel32.dll is already used by Python. + HMODULE hmodule=GetModuleHandle("Kernel32.dll"); + if (hmodule) + pfnIsWow64Process=(IsWow64Processfunc) + GetProcAddress(hmodule, "IsWow64Process"); + if (pfnIsWow64Process) { + if (!(*pfnIsWow64Process)(GetCurrentProcess(), &bIsWow64)) { + return PyErr_SetFromWindowsErr(0); + } + } + return PyBool_FromLong(bIsWow64); +} + #endif /* MS_WINDOWS */ #ifdef HAVE_DLOPEN @@ -854,6 +884,8 @@ #ifdef MS_WINDOWS {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, getwindowsversion_doc}, + {"iswow64process", (PyCFunction)sys_iswow64process, METH_NOARGS, + iswow64process_doc}, #endif /* MS_WINDOWS */ #ifdef USE_MALLOPT {"mdebug", sys_mdebug, METH_VARARGS}, Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 62635) +++ Misc/NEWS (working copy) @@ -47,6 +47,8 @@ Library ------- +- Add sys.iswow64process() on Windows platforms. + - Issue #2635: Fix bug in 'fix_sentence_endings' textwrap.fill option, where an extra space was added after a word containing (but not ending in) '.', '!' or '?'. Index: Doc/library/sys.rst =================================================================== --- Doc/library/sys.rst (revision 62635) +++ Doc/library/sys.rst (working copy) @@ -475,7 +475,18 @@ .. versionadded:: 2.3 +.. function:: iswow64process() + Returns True if this is a 32bit process running on a 64bit Windows. + This is a thin wrapper around the win32 API IsWow64Process() and False is + returned if that is not available for this version of Windows. If the + function exists but fails, a WindowsError will be thrown. + + Availability: Windows. + + .. versionadded:: 2.6 + + .. data:: hexversion The version number encoded as a single integer. This is guaranteed to increase Index: Lib/test/test_sys.py =================================================================== --- Lib/test/test_sys.py (revision 62635) +++ Lib/test/test_sys.py (working copy) @@ -209,6 +209,16 @@ self.assert_(isinstance(v[3], int)) self.assert_(isinstance(v[4], str)) + def test_iswow64process(self): + if hasattr(sys, "iswow64process"): + v = sys.iswow64process() + # it is a little hard to test is the result is correct - do + # what we can though. + # If v is true, we must be a 32bit process. + if v: + self.assert_("32 bit" in sys.version) + # else ??? + def test_dlopenflags(self): if hasattr(sys, "setdlopenflags"): self.assert_(hasattr(sys, "getdlopenflags"))