6
6
import sys
7
7
import os
8
8
import re
9
+ import warnings
9
10
10
11
from .errors import (
11
12
CompileError ,
@@ -824,9 +825,19 @@ def has_function( # noqa: C901
824
825
libraries = None ,
825
826
library_dirs = None ,
826
827
):
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
+
830
841
"""
831
842
# this can't be included at module scope because it tries to
832
843
# import math which might not be available at that point - maybe
@@ -835,8 +846,12 @@ def has_function( # noqa: C901
835
846
836
847
if includes is None :
837
848
includes = []
849
+ else :
850
+ warnings .warn ("includes is deprecated" , DeprecationWarning )
838
851
if include_dirs is None :
839
852
include_dirs = []
853
+ else :
854
+ warnings .warn ("include_dirs is deprecated" , DeprecationWarning )
840
855
if libraries is None :
841
856
libraries = []
842
857
if library_dirs is None :
@@ -845,7 +860,24 @@ def has_function( # noqa: C901
845
860
f = os .fdopen (fd , "w" )
846
861
try :
847
862
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
+ )
849
881
f .write (
850
882
"""\
851
883
int main (int argc, char **argv) {
0 commit comments