Repository: mesonbuild/meson

Issue:
Function checking fails on newest sid
Here's the log:

```
 Running compile:
 Command line:  ccache cc /tmp/tmp8lpdrvql.c -o /tmp/tmpnp00uh46
 Code:

         #define lchmod meson_disable_define_of_lchmod
         #include <sys/stat.h>
                                                     #include <unistd.h>
         #undef lchmod

         #ifdef __cplusplus
         extern "C"
         #endif
         char lchmod ();

         #if defined __stub_lchmod || defined __stub___lchmod
         fail fail fail this function is not going to work
         #endif

         int
         main ()
         {
           return lchmod ();
         }
 Compiler stdout:
  /tmp/tmp8lpdrvql.c:13:9: error: unknown type name ‘fail’
          fail fail fail this function is not going to work
          ^
 /tmp/tmp8lpdrvql.c:13:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fail’
          fail fail fail this function is not going to work
                    ^
 /tmp/tmp8lpdrvql.c:13:19: error: unknown type name ‘fail’
```



Discussion:
lchmod is not available on Linux and this is supposed to fail in exactly that way. What is the issue here?

I copypasted the wrong bit.

```
Command line:  ccache cc /tmp/tmpsoqb7tg5.c -O0 -o /tmp/tmpq3q_0ygi
Code:
 #include <sys/stat.h>
                                                #include <unistd.h>
int main() { lchmod; }
Compiler stdout:

Compiler stderr:

Checking for function "lchmod": YES

Meson encountered an error in file meson.build, line 25, column 2:
Assert failed: "lchmod" check should have failed
```

This also happens on latest Fedora.


Resolving patch:
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -709,11 +709,12 @@ def has_function(self, funcname, prefix, env, extra_args=[]):
         # glibc defines functions that are not available on Linux as stubs that
         # fail with ENOSYS (such as e.g. lchmod). In this case we want to fail
         # instead of detecting the stub as a valid symbol.
-        templ += '''
+        stubs_fail = '''
         #if defined __stub_{1} || defined __stub___{1}
         fail fail fail this function is not going to work
         #endif
         '''
+        templ += stubs_fail
 
         # And finally the actual function call
         templ += '''
@@ -736,8 +737,9 @@ def has_function(self, funcname, prefix, env, extra_args=[]):
         extra_args += self.get_no_optimization_args()
         # Sometimes the implementation is provided by the header, or the header
         # redefines the symbol to be something else. In that case, we want to
-        # still detect the function.
-        if self.links('{0}\nint main() {{ {1}; }}'.format(prefix, funcname), extra_args):
+        # still detect the function. We still want to fail if __stub_foo or
+        # _stub_foo are defined, of course.
+        if self.links('{0}\n' + stubs_fail + '\nint main() {{ {1}; }}'.format(prefix, funcname), extra_args):
             return True
         # Some functions like alloca() are defined as compiler built-ins which
         # are inlined by the compiler, so test for that instead. Built-ins are


Test patch: