66import sys
77import os
88import re
9+ import warnings
910
1011from .errors import (
1112 CompileError ,
@@ -388,7 +389,7 @@ def _fix_compile_args(self, output_dir, macros, include_dirs):
388389 raise TypeError ("'macros' (if supplied) must be a list of tuples" )
389390
390391 if include_dirs is None :
391- include_dirs = self .include_dirs
392+ include_dirs = list ( self .include_dirs )
392393 elif isinstance (include_dirs , (list , tuple )):
393394 include_dirs = list (include_dirs ) + (self .include_dirs or [])
394395 else :
@@ -824,9 +825,19 @@ def has_function( # noqa: C901
824825 libraries = None ,
825826 library_dirs = None ,
826827 ):
827- """Return a boolean indicating whether funcname is supported on
828- the current platform. The optional arguments can be used to
829- augment the compilation environment.
828+ """Return a boolean indicating whether funcname is provided as
829+ a symbol on the current platform. The optional arguments can
830+ be used to augment the compilation environment.
831+
832+ The libraries argument is a list of flags to be passed to the
833+ linker to make additional symbol definitions available for
834+ linking.
835+
836+ The includes and include_dirs arguments are deprecated.
837+ Usually, supplying include files with function declarations
838+ will cause function detection to fail even in cases where the
839+ symbol is available for linking.
840+
830841 """
831842 # this can't be included at module scope because it tries to
832843 # import math which might not be available at that point - maybe
@@ -835,8 +846,12 @@ def has_function( # noqa: C901
835846
836847 if includes is None :
837848 includes = []
849+ else :
850+ warnings .warn ("includes is deprecated" , DeprecationWarning )
838851 if include_dirs is None :
839852 include_dirs = []
853+ else :
854+ warnings .warn ("include_dirs is deprecated" , DeprecationWarning )
840855 if libraries is None :
841856 libraries = []
842857 if library_dirs is None :
@@ -845,7 +860,24 @@ def has_function( # noqa: C901
845860 f = os .fdopen (fd , "w" )
846861 try :
847862 for incl in includes :
848- f .write ("""#include "%s"\n """ % incl )
863+ f .write ("""#include %s\n """ % incl )
864+ if not includes :
865+ # Use "char func(void);" as the prototype to follow
866+ # what autoconf does. This prototype does not match
867+ # any well-known function the compiler might recognize
868+ # as a builtin, so this ends up as a true link test.
869+ # Without a fake prototype, the test would need to
870+ # know the exact argument types, and the has_function
871+ # interface does not provide that level of information.
872+ f .write (
873+ """\
874+ #ifdef __cplusplus
875+ extern "C"
876+ #endif
877+ char %s(void);
878+ """
879+ % funcname
880+ )
849881 f .write (
850882 """\
851883 int main (int argc, char **argv) {
@@ -871,7 +903,9 @@ def has_function( # noqa: C901
871903 except (LinkError , TypeError ):
872904 return False
873905 else :
874- os .remove (os .path .join (self .output_dir or '' , "a.out" ))
906+ os .remove (
907+ self .executable_filename ("a.out" , output_dir = self .output_dir or '' )
908+ )
875909 finally :
876910 for fn in objects :
877911 os .remove (fn )
0 commit comments