]> granicus.if.org Git - python/commitdiff
Issue #7860: platform.uname now reports the correct 'machine' type
authorR. David Murray <rdmurray@bitdance.com>
Mon, 22 Mar 2010 15:55:09 +0000 (15:55 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Mon, 22 Mar 2010 15:55:09 +0000 (15:55 +0000)
when Python is running in WOW64 mode on 64 bit Windows.  Patch by
Brian Curtin.

Lib/platform.py
Lib/test/test_platform.py
Misc/NEWS

index fc39b89b0dbe66cfdc91eeec46fc712912b879fc..080b836580cd91d11bc796938e517d121ebcaa98 100755 (executable)
@@ -1127,7 +1127,11 @@ def uname():
             # http://support.microsoft.com/kb/888731 and
             # http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM
             if not machine:
-                machine = os.environ.get('PROCESSOR_ARCHITECTURE', '')
+                # WOW64 processes mask the native architecture
+                if "PROCESSOR_ARCHITEW6432" in os.environ:
+                    machine = os.environ.get("PROCESSOR_ARCHITEW6432", '')
+                else:
+                    machine = os.environ.get('PROCESSOR_ARCHITECTURE', '')
             if not processor:
                 processor = os.environ.get('PROCESSOR_IDENTIFIER', machine)
 
index b9f1a2112386858ff6d0aad92959ef14f0e67fa9..afe304238c6d708e17aabdead4e247bb50eff6c3 100644 (file)
@@ -127,6 +127,27 @@ class PlatformTest(unittest.TestCase):
         res = platform.uname()
         self.assertTrue(any(res))
 
+    @unittest.skipUnless(sys.platform.startswith('win'), "windows only test")
+    def test_uname_win32_ARCHITEW6432(self):
+        # Issue 7860: make sure we get architecture from the correct variable
+        # on 64 bit Windows: if PROCESSOR_ARCHITEW6432 exists we should be
+        # using it, per
+        # http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx
+        try:
+            with test_support.EnvironmentVarGuard() as environ:
+                if 'PROCESSOR_ARCHITEW6432' in environ:
+                    del environ['PROCESSOR_ARCHITEW6432']
+                environ['PROCESSOR_ARCHITECTURE'] = 'foo'
+                platform._uname_cache = None
+                system, node, release, version, machine, processor = platform.uname()
+                self.assertEqual(machine, 'foo')
+                environ['PROCESSOR_ARCHITEW6432'] = 'bar'
+                platform._uname_cache = None
+                system, node, release, version, machine, processor = platform.uname()
+                self.assertEqual(machine, 'bar')
+        finally:
+            platform._uname_cache = None
+
     def test_java_ver(self):
         res = platform.java_ver()
         if sys.platform == 'java':
index f2876d637fe82a4aeb60602a87e56fba737bcdef..c5424c834ffa403c1649f2d4e60e8a351f2f796f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #7860: platform.uname now reports the correct 'machine' type
+  when Python is running in WOW64 mode on 64 bit Windows.
+
 - logging: Added getChild utility method to Logger and added isEnabledFor
   method to LoggerAdapter.