[Python-checkins] cpython (merge 3.4 -> default): Issue #21923: merge from 3.4

ned.deily python-checkins at python.org
Mon Jul 7 01:18:19 CEST 2014


http://hg.python.org/cpython/rev/12546bfa1f4f
changeset:   91563:12546bfa1f4f
parent:      91560:d25ae22cc992
parent:      91562:78fa18e95445
user:        Ned Deily <nad at acm.org>
date:        Sun Jul 06 16:17:45 2014 -0700
summary:
  Issue #21923: merge from 3.4

files:
  Lib/distutils/sysconfig.py            |   3 +-
  Lib/distutils/tests/test_sysconfig.py |  22 +++++++++++++++
  Misc/NEWS                             |   2 +
  3 files changed, 26 insertions(+), 1 deletions(-)


diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -179,7 +179,8 @@
             # version and build tools may not support the same set
             # of CPU architectures for universal builds.
             global _config_vars
-            if not _config_vars.get('CUSTOMIZED_OSX_COMPILER', ''):
+            # Use get_config_var() to ensure _config_vars is initialized.
+            if not get_config_var('CUSTOMIZED_OSX_COMPILER'):
                 import _osx_support
                 _osx_support.customize_compiler(_config_vars)
                 _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
diff --git a/Lib/distutils/tests/test_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py
--- a/Lib/distutils/tests/test_sysconfig.py
+++ b/Lib/distutils/tests/test_sysconfig.py
@@ -1,6 +1,9 @@
 """Tests for distutils.sysconfig."""
 import os
 import shutil
+import subprocess
+import sys
+import textwrap
 import unittest
 
 from distutils import sysconfig
@@ -174,6 +177,25 @@
         self.assertIsNotNone(vars['SO'])
         self.assertEqual(vars['SO'], vars['EXT_SUFFIX'])
 
+    def test_customize_compiler_before_get_config_vars(self):
+        # Issue #21923: test that a Distribution compiler
+        # instance can be called without an explicit call to
+        # get_config_vars().
+        with open(TESTFN, 'w') as f:
+            f.writelines(textwrap.dedent('''\
+                from distutils.core import Distribution
+                config = Distribution().get_command_obj('config')
+                # try_compile may pass or it may fail if no compiler
+                # is found but it should not raise an exception.
+                rc = config.try_compile('int x;')
+                '''))
+        p = subprocess.Popen([str(sys.executable), TESTFN],
+                stdout=subprocess.PIPE,
+                stderr=subprocess.STDOUT,
+                universal_newlines=True)
+        outs, errs = p.communicate()
+        self.assertEqual(0, p.returncode, "Subprocess failed: " + outs)
+
 
 def test_suite():
     suite = unittest.TestSuite()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -541,6 +541,8 @@
 
 - Issue #21801: Validate that __signature__ is None or an instance of Signature.
 
+- Issue #21923: Prevent AttributeError in distutils.sysconfig.customize_compiler
+  due to possible uninitialized _config_vars.
 
 Extension Modules
 -----------------

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list