-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server: Backport 0060-Check-C23-nullptr-usability-as-a-sentinel.patch
Signed-off-by: Marko Lindqvist <[email protected]>
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
freeciv/patches/backports/0060-Check-C23-nullptr-usability-as-a-sentinel.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
From ac5ef97b9a6c833011278db8eeb845774062f046 Mon Sep 17 00:00:00 2001 | ||
From: Marko Lindqvist <[email protected]> | ||
Date: Fri, 19 Apr 2024 17:06:10 +0300 | ||
Subject: [PATCH 60/60] Check C23 nullptr usability as a sentinel | ||
|
||
See RM #475 | ||
|
||
Signed-off-by: Marko Lindqvist <[email protected]> | ||
--- | ||
m4/c23.m4 | 21 +++++++++++++-------- | ||
meson.build | 9 ++++++--- | ||
2 files changed, 19 insertions(+), 11 deletions(-) | ||
|
||
diff --git a/m4/c23.m4 b/m4/c23.m4 | ||
index 0c57f04856..9a265a0065 100644 | ||
--- a/m4/c23.m4 | ||
+++ b/m4/c23.m4 | ||
@@ -1,18 +1,23 @@ | ||
# Check for the presence of C23 features. | ||
|
||
-# Check for C23 nullptr, and define FREECIV_HAVE_C23_NULLPTR if it's available | ||
+# Check for C23 nullptr that can be passed as sentinel | ||
+# and define FREECIV_HAVE_C23_NULLPTR if such is available | ||
# | ||
AC_DEFUN([FC_C23_NULLPTR], | ||
[ | ||
AC_LANG_PUSH([C]) | ||
- AC_CHECK_HEADERS([stddef]) | ||
+ AC_CHECK_HEADERS([stddef.h]) | ||
AC_CACHE_CHECK([for C23 nullptr], [ac_cv_c23_nullptr], | ||
- [AC_LINK_IFELSE([AC_LANG_PROGRAM( | ||
-[[#ifdef HAVE_STDDEF | ||
-#include <stddef> | ||
-#endif]], | ||
- [[ int *var = nullptr; ]])], | ||
-[ac_cv_c23_nullptr=yes], [ac_cv_c23_nullptr=no])]) | ||
+ [_cflags_="$CFLAGS" | ||
+ CFLAGS="$EXTRA_DEBUG_CFLAGS $CFLAGS" | ||
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM( | ||
+[[#ifdef HAVE_STDDEF_H | ||
+#include <stddef.h> | ||
+#endif | ||
+void sentinental(...) __attribute__((__sentinel__(0)));]], | ||
+ [[ sentinental(nullptr); ]])], | ||
+[ac_cv_c23_nullptr=yes], [ac_cv_c23_nullptr=no])] | ||
+ CFLAGS="$_cflags_") | ||
if test "x${ac_cv_c23_nullptr}" = "xyes" ; then | ||
AC_DEFINE([FREECIV_HAVE_C23_NULLPTR], [1], [C23 nullptr available]) | ||
fi | ||
diff --git a/meson.build b/meson.build | ||
index 0a0b904599..c6b7483303 100644 | ||
--- a/meson.build | ||
+++ b/meson.build | ||
@@ -585,11 +585,14 @@ if zstd_dep.found() | ||
pub_conf_data.set('FREECIV_HAVE_LIBZSTD', 1) | ||
endif | ||
|
||
+# Check for c23 nullptr that can be passed as sentinel | ||
if c_compiler.compiles(''' | ||
-#include <stddef> | ||
-int main(void) { int *var = nullptr; return 0; }''', | ||
+#include <stddef.h> | ||
+void sentinental(...) __attribute__((__sentinel__(0))); | ||
+void caller(void) { sentinental(nullptr); }''', | ||
name: 'c23 nullptr', | ||
- include_directories: include_directories(cross_inc_path)) | ||
+ include_directories: include_directories(cross_inc_path), | ||
+ args: ['-Wformat']) | ||
pub_conf_data.set('FREECIV_HAVE_C23_NULLPTR', 1) | ||
endif | ||
|
||
-- | ||
2.43.0 | ||
|