diff options
author | Ned Deily <nad@acm.org> | 2014-07-06 23:14:33 (GMT) |
---|---|---|
committer | Ned Deily <nad@acm.org> | 2014-07-06 23:14:33 (GMT) |
commit | 7bc5fb6916b59e9d6e491c8519e5affa98b8aa6c (patch) | |
tree | ebae83e1c15344bc038c411344201005bf5eaeb8 | |
parent | 898eb826962a6d14e92f2f8c4343abeb3f810030 (diff) | |
download | cpython-7bc5fb6916b59e9d6e491c8519e5affa98b8aa6c.zip cpython-7bc5fb6916b59e9d6e491c8519e5affa98b8aa6c.tar.gz cpython-7bc5fb6916b59e9d6e491c8519e5affa98b8aa6c.tar.bz2 |
Issue #21923: Prevent AttributeError in distutils.sysconfig.customize_compiler
due to possible uninitialized _config_vars. Original patch by Alex Gaynor.
-rw-r--r-- | Lib/distutils/sysconfig.py | 3 | ||||
-rw-r--r-- | Lib/distutils/tests/test_sysconfig.py | 22 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 27 insertions, 1 deletions
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py index 75537db..5b94fa2 100644 --- a/Lib/distutils/sysconfig.py +++ b/Lib/distutils/sysconfig.py @@ -179,7 +179,8 @@ def customize_compiler(compiler): # 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 index 95fa9dc..fc4d1de 100644 --- 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 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase): 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() @@ -136,6 +136,9 @@ Library - 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. + Build ----- |