From b022b25457aafa8759d91876264210527f0ff352 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 15 Feb 2023 19:50:31 +0100 Subject: [PATCH] distutils.ccompiler.CCompiler.has_function: Quote #include argument Arguably, this is a historic wart in the interface, which is why I subconsciously fixed it in commit 56a5b333b2a8 ("distutils.ccompiler: Make has_function work with more C99 compilers"). But it's clearly not a backwards-compatible change, so it's wrong and has to be reverted. Fixes pypa/setuptools#3820. --- distutils/ccompiler.py | 2 +- distutils/tests/test_ccompiler.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/distutils/ccompiler.py b/distutils/ccompiler.py index f4a8a89760..1818fce901 100644 --- a/distutils/ccompiler.py +++ b/distutils/ccompiler.py @@ -860,7 +860,7 @@ def has_function( # noqa: C901 f = os.fdopen(fd, "w") try: for incl in includes: - f.write("""#include %s\n""" % incl) + f.write("""#include "%s"\n""" % incl) if not includes: # Use "char func(void);" as the prototype to follow # what autoconf does. This prototype does not match diff --git a/distutils/tests/test_ccompiler.py b/distutils/tests/test_ccompiler.py index 88497d252b..49691d4b9b 100644 --- a/distutils/tests/test_ccompiler.py +++ b/distutils/tests/test_ccompiler.py @@ -66,15 +66,15 @@ def test_has_function_prototype(): assert compiler.has_function('exit') with pytest.deprecated_call(match='includes is deprecated'): # abort() is a valid expression with the prototype. - assert compiler.has_function('abort', includes=['']) + assert compiler.has_function('abort', includes=['stdlib.h']) with pytest.deprecated_call(match='includes is deprecated'): # But exit() is not valid with the actual prototype in scope. - assert not compiler.has_function('exit', includes=['']) + assert not compiler.has_function('exit', includes=['stdlib.h']) # And setuptools_does_not_exist is not declared or defined at all. assert not compiler.has_function('setuptools_does_not_exist') with pytest.deprecated_call(match='includes is deprecated'): assert not compiler.has_function( - 'setuptools_does_not_exist', includes=[''] + 'setuptools_does_not_exist', includes=['stdio.h'] )