[build] Fixes for clang errors in update-mime-database.cpp
Here are 2 patches that fix the build of update-mime-database.cpp on darwin. I'm currently not allowed to open a merge request, so I'm submitting them this way.
From 053518391f901f666ef155189fa2a38f0cf381fb Mon Sep 17 00:00:00 2001
From: Tobias Mayer <tobim@fastmail.fm>
Date: Sat, 7 Oct 2023 23:45:47 +0200
Subject: [PATCH 1/2] Fix false positive fdatasync detection on darwin
The `has_function` feature in meson uses different detection methods
depending on the contents of the `prefix` kwarg [1]:
* if it contains `#include` directives it will copy the prefix into
the test code and check if it compiles
* if it doesn't contain an include or isn't specified, `has_function`
will forward declare the function and test for it's existence by
trying to link it to the default libraries
The latter approach wrongly succeeds for `fdatasync` on darwin because
the linker binds the function to a system call of the same name. Note
that this result really is wrong because that system call has not
the expected semantics of `fdatasync`.
By adding an include for `unistd.h` we can get meson to use the
first approach and the detection fails.
Note that this has gone unnoticed so far because only recent versions
of clang (the default compiler on darwin) started to treat implicit
function declarations as an error.
[1] https://github.com/mesonbuild/meson/blob/583d2815d1a130227f0f4db47e4ab2e80ebb6a61/mesonbuild/compilers/mixins/clike.py#L839-L846
---
meson.build | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/meson.build b/meson.build
index 1780c44..7998a51 100644
--- a/meson.build
+++ b/meson.build
@@ -49,12 +49,7 @@ endif
###############################################################################
# Dependencies
-check_functions = [
- 'fdatasync',
-]
-foreach function : check_functions
- config.set('HAVE_'+function.to_upper(), cc.has_function(function))
-endforeach
+config.set('HAVE_FDATASYNC', cc.has_function('fdatasync', prefix: '#include <unistd.h>'))
if get_option('build-translations')
--
2.42.0
From 5b3fcd1d347ebdf82b9f78df6f45e247efc63695 Mon Sep 17 00:00:00 2001
From: Tobias Mayer <tobim@fastmail.fm>
Date: Sun, 8 Oct 2023 00:11:49 +0200
Subject: [PATCH 2/2] Fix string literal concatenation
Clang is not able to disambiguate between multiple string literatals
and C++11 user defined literals. Spaces help.
---
src/update-mime-database.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/update-mime-database.cpp b/src/update-mime-database.cpp
index 733ba06..4ca6d06 100644
--- a/src/update-mime-database.cpp
+++ b/src/update-mime-database.cpp
@@ -2158,7 +2158,7 @@ static void check_in_path_xdg_data(const char *mime_path)
env = getenv("XDG_DATA_DIRS");
if (!env)
- env = "/usr/local/share/"PATH_SEPARATOR"/usr/share/";
+ env = "/usr/local/share/" PATH_SEPARATOR "/usr/share/";
dirs = g_strsplit(env, PATH_SEPARATOR, 0);
g_return_if_fail(dirs != NULL);
for (n = 0; dirs[n]; n++)
--
2.42.0