Skip to content

Commit

Permalink
Merge pull request numpy#12895 from eric-wieser/distutils-extra-quote…
Browse files Browse the repository at this point in the history
…s-again

BUG: Do not insert extra double quote into preprocessor macros
  • Loading branch information
charris authored Jan 31, 2019
2 parents b5c855a + 490b854 commit e36b62e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions numpy/distutils/system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@
platform_bits = _bits[platform.architecture()[0]]


def _c_string_literal(s):
"""
Convert a python string into a literal suitable for inclusion into C code
"""
# only these three characters are forbidden in C strings
s = s.replace('\\', r'\\')
s = s.replace('"', r'\"')
s = s.replace('\n', r'\n')
return '"{}"'.format(s)


def libpaths(paths, bits):
"""Return a list of library paths valid on 32 or 64 bit systems.
Expand Down Expand Up @@ -1497,7 +1508,7 @@ def get_atlas_version(**config):
atlas_version = os.environ.get('ATLAS_VERSION', None)
if atlas_version:
dict_append(info, define_macros=[(
'ATLAS_INFO', '"\\"%s\\""' % atlas_version)
'ATLAS_INFO', _c_string_literal(atlas_version))
])
else:
dict_append(info, define_macros=[('NO_ATLAS_INFO', -1)])
Expand All @@ -1518,7 +1529,7 @@ def get_atlas_version(**config):
dict_append(info, define_macros=[('NO_ATLAS_INFO', -2)])
else:
dict_append(info, define_macros=[(
'ATLAS_INFO', '"\\"%s\\""' % atlas_version)
'ATLAS_INFO', _c_string_literal(atlas_version))
])
result = _cached_atlas_version[key] = atlas_version, info
return result
Expand Down Expand Up @@ -2063,7 +2074,7 @@ def calc_info(self):
if vrs is None:
continue
macros = [(self.modulename.upper() + '_VERSION',
'"\\"%s\\""' % (vrs)),
_c_string_literal(vrs)),
(self.modulename.upper(), None)]
break
dict_append(info, define_macros=macros)
Expand Down Expand Up @@ -2268,7 +2279,7 @@ def calc_info(self):
version = self.get_config_output(config_exe, self.version_flag)
if version:
macros.append((self.__class__.__name__.split('.')[-1].upper(),
'"\\"%s\\""' % (version)))
_c_string_literal(version)))
if self.version_macro_name:
macros.append((self.version_macro_name + '_%s'
% (version.replace('.', '_')), None))
Expand Down

0 comments on commit e36b62e

Please sign in to comment.