diff options
author | Ned Deily <nad@acm.org> | 2014-07-06 23:11:44 (GMT) |
---|---|---|
committer | Ned Deily <nad@acm.org> | 2014-07-06 23:11:44 (GMT) |
commit | 9be578990e747eee6da7444297776df53b76e187 (patch) | |
tree | a6d0d628f11fdab09a5ce7b62f57b832c71354f9 /Lib/distutils | |
parent | 4f7e09a9eb1210a0e7d6ccb75415d1b3b1872a23 (diff) | |
download | cpython-9be578990e747eee6da7444297776df53b76e187.zip cpython-9be578990e747eee6da7444297776df53b76e187.tar.gz cpython-9be578990e747eee6da7444297776df53b76e187.tar.bz2 |
Issue #21923: Prevent AttributeError in distutils.sysconfig.customize_compiler
due to possible uninitialized _config_vars. Original patch by Alex Gaynor.
Diffstat (limited to 'Lib/distutils')
-rw-r--r-- | Lib/distutils/sysconfig.py | 3 | ||||
-rw-r--r-- | Lib/distutils/tests/test_sysconfig.py | 21 |
2 files changed, 23 insertions, 1 deletions
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py index 4aa9334..de7da1d 100644 --- a/Lib/distutils/sysconfig.py +++ b/Lib/distutils/sysconfig.py @@ -165,7 +165,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 ea8d7b5..eb4d27c 100644 --- a/Lib/distutils/tests/test_sysconfig.py +++ b/Lib/distutils/tests/test_sysconfig.py @@ -3,6 +3,9 @@ import os import test import unittest import shutil +import subprocess +import sys +import textwrap from distutils import sysconfig from distutils.tests import support @@ -99,6 +102,24 @@ class SysconfigTestCase(support.EnvironGuard, self.assertEqual(global_sysconfig.get_config_var('LDSHARED'), sysconfig.get_config_var('LDSHARED')) self.assertEqual(global_sysconfig.get_config_var('CC'), sysconfig.get_config_var('CC')) + 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(): |