mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [C23 divers headers 02/17] C23: Add the *_WIDTH macros to stdint.h
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
@ 2023-04-15 13:21 ` Jens Gustedt
  2023-04-17  9:09 ` [musl] [C23 divers headers 03/17] C23: add call_once to stdlib.h Jens Gustedt
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-15 13:21 UTC (permalink / raw)
  To: musl

This basically doubles the strategies as are already in place to
determine the correct values.

All this generation of these macros would merrit some refactoring.

We also set the include guard to the macro name requested by C23, only
that we do not yet use the final version number. This should be done
once it is agreed that this part of the headers are C23 compliant.
---
 include/stdint.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/include/stdint.h b/include/stdint.h
index a2968197..1f68b3bb 100644
--- a/include/stdint.h
+++ b/include/stdint.h
@@ -1,5 +1,5 @@
-#ifndef _STDINT_H
-#define _STDINT_H
+#ifndef __STDC_VERSION_STDINT_H__
+#define __STDC_VERSION_STDINT_H__ 201711L
 
 #define __NEED_int8_t
 #define __NEED_int16_t
@@ -35,6 +35,11 @@ typedef uint16_t uint_least16_t;
 typedef uint32_t uint_least32_t;
 typedef uint64_t uint_least64_t;
 
+#define INT8_WIDTH   8
+#define INT16_WIDTH  16
+#define INT32_WIDTH  32
+#define INT64_WIDTH  64
+
 #define INT8_MIN   (-1-0x7f)
 #define INT16_MIN  (-1-0x7fff)
 #define INT32_MIN  (-1-0x7fffffff)
@@ -45,14 +50,27 @@ typedef uint64_t uint_least64_t;
 #define INT32_MAX  (0x7fffffff)
 #define INT64_MAX  (0x7fffffffffffffff)
 
+#define UINT8_WIDTH   8
+#define UINT16_WIDTH  16
+#define UINT32_WIDTH  32
+#define UINT64_WIDTH  64
+
 #define UINT8_MAX  (0xff)
 #define UINT16_MAX (0xffff)
 #define UINT32_MAX (0xffffffffu)
 #define UINT64_MAX (0xffffffffffffffffu)
 
+#define INT_FAST8_WIDTH   8
+#define INT_FAST64_WIDTH  64
+
 #define INT_FAST8_MIN   INT8_MIN
 #define INT_FAST64_MIN  INT64_MIN
 
+#define INT_LEAST8_WIDTH   8
+#define INT_LEAST16_WIDTH  16
+#define INT_LEAST32_WIDTH  32
+#define INT_LEAST64_WIDTH  64
+
 #define INT_LEAST8_MIN   INT8_MIN
 #define INT_LEAST16_MIN  INT16_MIN
 #define INT_LEAST32_MIN  INT32_MIN
@@ -66,21 +84,36 @@ typedef uint64_t uint_least64_t;
 #define INT_LEAST32_MAX  INT32_MAX
 #define INT_LEAST64_MAX  INT64_MAX
 
+#define UINT_FAST8_WIDTH   8
+#define UINT_FAST64_WIDTH  64
+
 #define UINT_FAST8_MAX  UINT8_MAX
 #define UINT_FAST64_MAX UINT64_MAX
 
+#define UINT_LEAST8_WIDTH   8
+#define UINT_LEAST16_WIDTH  16
+#define UINT_LEAST32_WIDTH  32
+#define UINT_LEAST64_WIDTH  64
+
 #define UINT_LEAST8_MAX  UINT8_MAX
 #define UINT_LEAST16_MAX UINT16_MAX
 #define UINT_LEAST32_MAX UINT32_MAX
 #define UINT_LEAST64_MAX UINT64_MAX
 
+#define INTMAX_WIDTH 64
+#define UINTMAX_WIDTH 64
+
 #define INTMAX_MIN  INT64_MIN
 #define INTMAX_MAX  INT64_MAX
 #define UINTMAX_MAX UINT64_MAX
 
+#define WINT_WIDTH 32
+
 #define WINT_MIN 0U
 #define WINT_MAX UINT32_MAX
 
+#define WCHAR_WIDTH 32
+
 #if L'\0'-1 > 0
 #define WCHAR_MAX (0xffffffffu+L'\0')
 #define WCHAR_MIN (0+L'\0')
@@ -89,6 +122,8 @@ typedef uint64_t uint_least64_t;
 #define WCHAR_MIN (-1-0x7fffffff+L'\0')
 #endif
 
+#define SIG_ATOMIC_WIDTH 32
+
 #define SIG_ATOMIC_MIN  INT32_MIN
 #define SIG_ATOMIC_MAX  INT32_MAX
 
@@ -103,15 +138,53 @@ typedef uint64_t uint_least64_t;
 #define UINT32_C(c) c ## U
 
 #if UINTPTR_MAX == UINT64_MAX
+#define INTPTR_WIDTH 64
+#define UINTPTR_WIDTH 64
 #define INT64_C(c) c ## L
 #define UINT64_C(c) c ## UL
 #define INTMAX_C(c)  c ## L
 #define UINTMAX_C(c) c ## UL
 #else
+#define INTPTR_WIDTH 32
+#define UINTPTR_WIDTH 32
 #define INT64_C(c) c ## LL
 #define UINT64_C(c) c ## ULL
 #define INTMAX_C(c)  c ## LL
 #define UINTMAX_C(c) c ## ULL
 #endif
 
+#if UINT_FAST16_MAX == UINT32_MAX
+#define INT_FAST16_WIDTH 32
+#define UINT_FAST16_WIDTH 32
+#else
+#define INT_FAST16_WIDTH 16
+#define UINT_FAST16_WIDTH 16
+#endif
+
+#if UINT_FAST32_MAX == UINT64_MAX
+#define INT_FAST32_WIDTH 64
+#define UINT_FAST32_WIDTH 64
+#else
+#define INT_FAST32_WIDTH 32
+#define UINT_FAST32_WIDTH 32
+#endif
+
+#if PTRDIFF_MAX == INT64_MAX
+#define PTRDIFF_WIDTH 64
+#else
+#define PTRDIFF_WIDTH 32
+#endif
+
+#if SIZE_MAX == UINT64_MAX
+#define SIZE_WIDTH 64
+#else
+#define SIZE_WIDTH 32
+#endif
+
+// Enable support for _BitInt(N) types, if that comes not from the
+// compiler directly.
+#if (__STDC_VERSION__ >= 201900L) && !BITINT_MAXWIDTH && __BITINT_MAXWIDTH__
+#define BITINT_MAXWIDTH __BITINT_MAXWIDTH__
+#endif
+
 #endif
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 03/17] C23: add call_once to stdlib.h
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
  2023-04-15 13:21 ` [musl] [C23 divers headers 02/17] C23: Add the *_WIDTH macros to stdint.h Jens Gustedt
@ 2023-04-17  9:09 ` Jens Gustedt
  2023-05-24 14:23   ` Rich Felker
  2023-04-17 19:52 ` [musl] [C23 divers headers 04/17] C23: add timegm, gmtime_r and localtime_r to time.h in C23 mode Jens Gustedt
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 30+ messages in thread
From: Jens Gustedt @ 2023-04-17  9:09 UTC (permalink / raw)
  To: musl

Since C23, call_once, once_flag and ONCE_FLAG_INIT are also accessible
even if the platform does not have the threads option. Add them to the
header.

The identifiers once_flag and ONCE_FLAG_INIT were not reserved in C17
if the header threads.h was not included, so this potentially creates
naming conflicts.
---
 include/stdlib.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/stdlib.h b/include/stdlib.h
index 475190bf..c635d99b 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -172,6 +172,10 @@ long double strtold_l(const char *__restrict, char **__restrict, struct __locale
 #endif
 #endif
 
+#define ONCE_FLAG_INIT 0
+typedef int once_flag;
+void call_once(once_flag *, void (*)(void));
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 04/17] C23: add timegm, gmtime_r and localtime_r to time.h in C23 mode
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
  2023-04-15 13:21 ` [musl] [C23 divers headers 02/17] C23: Add the *_WIDTH macros to stdint.h Jens Gustedt
  2023-04-17  9:09 ` [musl] [C23 divers headers 03/17] C23: add call_once to stdlib.h Jens Gustedt
@ 2023-04-17 19:52 ` Jens Gustedt
  2023-04-19  6:38 ` [musl] [C23 divers headers 15/17] C23: add the unreachable macro Jens Gustedt
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-17 19:52 UTC (permalink / raw)
  To: musl

These are already present in musl, only they had been protected under
some POSIX or BSD macros. Make them available generally.

Their names were not reserved previously, so there are potential
naming conflicts with application code.
---
 include/time.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/time.h b/include/time.h
index 3d948372..e94b3a01 100644
--- a/include/time.h
+++ b/include/time.h
@@ -66,14 +66,16 @@ int timespec_get(struct timespec *, int);
 
 #define TIME_UTC 1
 
+struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict);
+struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict);
+time_t timegm(struct tm *);
+
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  || defined(_BSD_SOURCE)
 
 size_t strftime_l (char *  __restrict, size_t, const char *  __restrict, const struct tm *  __restrict, locale_t);
 
-struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict);
-struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict);
 char *asctime_r (const struct tm *__restrict, char *__restrict);
 char *ctime_r (const time_t *, char *);
 
@@ -129,7 +131,6 @@ struct tm *getdate (const char *);
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int stime(const time_t *);
-time_t timegm(struct tm *);
 #endif
 
 #if _REDIR_TIME64
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 15/17] C23: add the unreachable macro
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (2 preceding siblings ...)
  2023-04-17 19:52 ` [musl] [C23 divers headers 04/17] C23: add timegm, gmtime_r and localtime_r to time.h in C23 mode Jens Gustedt
@ 2023-04-19  6:38 ` Jens Gustedt
  2023-05-24 14:21   ` Rich Felker
  2023-04-19  6:42 ` [musl] [C23 divers headers 16/17] C23: add the nullptr_t type Jens Gustedt
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19  6:38 UTC (permalink / raw)
  To: musl

---
 include/stddef.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/stddef.h b/include/stddef.h
index f25b8639..09be5fb6 100644
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -24,4 +24,6 @@
 #define offsetof(type, member) ((size_t)( (char *)&(((type *)0)->member) - (char *)0 ))
 #endif
 
+#define unreachable() __builtin_unreachable()
+
 #endif
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 16/17] C23: add the nullptr_t type
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (3 preceding siblings ...)
  2023-04-19  6:38 ` [musl] [C23 divers headers 15/17] C23: add the unreachable macro Jens Gustedt
@ 2023-04-19  6:42 ` Jens Gustedt
  2023-05-24 14:22   ` Rich Felker
  2023-04-19  6:46 ` [musl] [C23 divers headers 17/17] C23: add the __STDC_VERSION_STDDEF_H__ macro Jens Gustedt
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19  6:42 UTC (permalink / raw)
  To: musl

This will only work with compilers that implement typeof and
nullptr. Currently this doesn't work for gcc but this will probably be
in gcc-13. Therefore the version test uses the future date of 202311L
which is the foreseen value for C23 final.

For clang there are better feature test macros, namely
__is_identifier(nullptr) can be used to test if nullptr is an
identifier or a keyword. In particular, this feature now seems to work
with clang 16.0.2.
---
 include/stddef.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/stddef.h b/include/stddef.h
index 09be5fb6..e4d6b2ef 100644
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -26,4 +26,14 @@
 
 #define unreachable() __builtin_unreachable()
 
+#if __STDC_VERSION__ >= 202311L
+typedef typeof(nullptr) nullptr_t;
+#else
+#if __clang__
+#if !__is_identifier(nullptr)
+typedef typeof(nullptr) nullptr_t;
+#endif
+#endif
+#endif
+
 #endif
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 17/17] C23: add the __STDC_VERSION_STDDEF_H__ macro
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (4 preceding siblings ...)
  2023-04-19  6:42 ` [musl] [C23 divers headers 16/17] C23: add the nullptr_t type Jens Gustedt
@ 2023-04-19  6:46 ` Jens Gustedt
  2023-04-19  8:16 ` [musl] [C23 divers headers 09/17] C23: update stdbool.h Jens Gustedt
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19  6:46 UTC (permalink / raw)
  To: musl

Currently we don't know of such a compiler, yet, that fully supports
all the features but this will probably be gcc-13 and
clang-17.
---
 include/stddef.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/stddef.h b/include/stddef.h
index e4d6b2ef..d85b2c55 100644
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -1,5 +1,5 @@
-#ifndef _STDDEF_H
-#define _STDDEF_H
+#ifndef _STDC_VERSION_STDDEF_H__
+#define _STDC_VERSION_STDDEF_H__ 201900L
 
 #if __cplusplus >= 201103L
 #define NULL nullptr
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 09/17] C23: update stdbool.h
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (5 preceding siblings ...)
  2023-04-19  6:46 ` [musl] [C23 divers headers 17/17] C23: add the __STDC_VERSION_STDDEF_H__ macro Jens Gustedt
@ 2023-04-19  8:16 ` Jens Gustedt
  2023-04-19 11:48 ` [musl] [C23 divers headers 10/17] C23: remove the contents of stdalign.h Jens Gustedt
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19  8:16 UTC (permalink / raw)
  To: musl

C23 has false, true and bool as keywords, so this file is basically
not needed for modern applications. It is only provided for backwards
compatibility. Implementations may also provide macros in addition to
the keywords, so we do that because some user code may rely on these.
---
 include/stdbool.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/stdbool.h b/include/stdbool.h
index a9d7ab78..d9df7524 100644
--- a/include/stdbool.h
+++ b/include/stdbool.h
@@ -1,11 +1,17 @@
-#ifndef _STDBOOL_H
-#define _STDBOOL_H
+#ifndef __STDC_VERSION_STDBOOL_H__
+#define __STDC_VERSION_STDBOOL_H__ 202311L
 
 #ifndef __cplusplus
 
+#if __STDC_VERSION__ >= 202311L
+#define true true
+#define false false
+#define bool bool
+#else
 #define true 1
 #define false 0
 #define bool _Bool
+#endif
 
 #endif
 
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 10/17] C23: remove the contents of stdalign.h
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (6 preceding siblings ...)
  2023-04-19  8:16 ` [musl] [C23 divers headers 09/17] C23: update stdbool.h Jens Gustedt
@ 2023-04-19 11:48 ` Jens Gustedt
  2023-05-24 14:25   ` Rich Felker
  2023-04-19 11:59 ` [musl] [C23 divers headers 11/17] C23: remove the static_assert macro Jens Gustedt
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19 11:48 UTC (permalink / raw)
  To: musl

This now has no contents because the features have been promoted to
keywords.
---
 include/stdalign.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/stdalign.h b/include/stdalign.h
index 2cc94be3..477ae69c 100644
--- a/include/stdalign.h
+++ b/include/stdalign.h
@@ -1,20 +1,20 @@
-#ifndef _STDALIGN_H
-#define _STDALIGN_H
+#ifndef __STDC_VERSION_STDALIGN_H__
+#define __STDC_VERSION_STDALIGN_H__ 202311L
 
 #ifndef __cplusplus
 
 /* this whole header only works in C11 or with compiler extensions */
 #if __STDC_VERSION__ < 201112L && defined( __GNUC__)
-#define _Alignas(t) __attribute__((__aligned__(t)))
-#define _Alignof(t) __alignof__(t)
-#endif
-
-#define alignas _Alignas
-#define alignof _Alignof
-
+# define _Alignas(t) __attribute__((__aligned__(t)))
+# define _Alignof(t) __alignof__(t)
 #endif
 
+/* Starting with C23 this header has no contents because these are keywords. */
+#if __STDC_VERSION__ < 202311L
 #define __alignas_is_defined 1
 #define __alignof_is_defined 1
+#endif
+
+#endif
 
 #endif
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 11/17] C23: remove the static_assert macro
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (7 preceding siblings ...)
  2023-04-19 11:48 ` [musl] [C23 divers headers 10/17] C23: remove the contents of stdalign.h Jens Gustedt
@ 2023-04-19 11:59 ` Jens Gustedt
  2023-04-19 12:17 ` [musl] [C23 divers headers 12/17] C23: change the assert macro to ... arguments Jens Gustedt
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19 11:59 UTC (permalink / raw)
  To: musl

This is now a keyword.
---
 include/assert.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/assert.h b/include/assert.h
index d14ec94e..71007a10 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -8,8 +8,8 @@
 #define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0)))
 #endif
 
-#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
-#define static_assert _Static_assert
+#if __STDC_VERSION__ >= 201112L && __STDC_VERSION__ < 202311L && !defined(__cplusplus)
+# define static_assert _Static_assert
 #endif
 
 #ifdef __cplusplus
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 12/17] C23: change the assert macro to ... arguments
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (8 preceding siblings ...)
  2023-04-19 11:59 ` [musl] [C23 divers headers 11/17] C23: remove the static_assert macro Jens Gustedt
@ 2023-04-19 12:17 ` Jens Gustedt
  2023-04-19 12:48 ` [musl] [C23 divers headers 13/17] C23: add the __STDC_VERSION_ASSERT_H__ macro Jens Gustedt
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19 12:17 UTC (permalink / raw)
  To: musl

Macro arguments are ambiguate fellows. A single C expression such as
(struct toto){ 1, 2}.a appears as two macro arguments.

This mandatory change has the macro accept an unlimited number of
macro-parameters, but which then must resolve to a single C
expression. This is achieved by squeezing the argument list through a
trivial function call to a static function.  By that we ensure that
lists that represent more than one expression (such as `1, 2`) and
empty lists are diagnosed.
---
 include/assert.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/assert.h b/include/assert.h
index 71007a10..034c4aa7 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -2,10 +2,17 @@
 
 #undef assert
 
+// Ensure that this version only accepts arguments that resolve to one
+// C expression after preprocessing.
+#ifndef __ASSERT_EXPRESSION
+#define __ASSERT_EXPRESSION(...) __assert_expression(__VA_ARGS__)
+static inline _Bool __assert_expression(_Bool __x) { return __x; }
+#endif
+
 #ifdef NDEBUG
-#define	assert(x) (void)0
+#define	assert(...) (void)0
 #else
-#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0)))
+#define assert(...) ((void)(__ASSERT_EXPRESSION(__VA_ARGS__) || (__assert_fail(#__VA_ARGS__, __FILE__, __LINE__, __func__),0)))
 #endif
 
 #if __STDC_VERSION__ >= 201112L && __STDC_VERSION__ < 202311L && !defined(__cplusplus)
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 13/17] C23: add the __STDC_VERSION_ASSERT_H__ macro
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (9 preceding siblings ...)
  2023-04-19 12:17 ` [musl] [C23 divers headers 12/17] C23: change the assert macro to ... arguments Jens Gustedt
@ 2023-04-19 12:48 ` Jens Gustedt
  2023-04-19 13:02 ` [musl] [C23 divers headers 06/17] C23: adapt setjmp.h Jens Gustedt
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19 12:48 UTC (permalink / raw)
  To: musl

---
 include/assert.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/assert.h b/include/assert.h
index 034c4aa7..0184400c 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -2,6 +2,8 @@
 
 #undef assert
 
+#define __STDC_VERSION_ASSERT_H__ 202300L
+
 // Ensure that this version only accepts arguments that resolve to one
 // C expression after preprocessing.
 #ifndef __ASSERT_EXPRESSION
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 06/17] C23: adapt setjmp.h
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (10 preceding siblings ...)
  2023-04-19 12:48 ` [musl] [C23 divers headers 13/17] C23: add the __STDC_VERSION_ASSERT_H__ macro Jens Gustedt
@ 2023-04-19 13:02 ` Jens Gustedt
  2023-04-19 13:11 ` [musl] [C23 divers headers 07/17] C23: change the noreturn functions in stdlib.h Jens Gustedt
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19 13:02 UTC (permalink / raw)
  To: musl

---
 include/setjmp.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/setjmp.h b/include/setjmp.h
index 1976af23..beb9481c 100644
--- a/include/setjmp.h
+++ b/include/setjmp.h
@@ -1,5 +1,5 @@
-#ifndef	_SETJMP_H
-#define	_SETJMP_H
+#ifndef	__STDC_VERSION_SETJMP_H__
+#define	__STDC_VERSION_SETJMP_H__ 202311L
 
 #ifdef __cplusplus
 extern "C" {
@@ -36,7 +36,7 @@ _Noreturn void _longjmp (jmp_buf, int);
 #endif
 
 int setjmp (jmp_buf) __setjmp_attr;
-_Noreturn void longjmp (jmp_buf, int);
+__noreturn void longjmp (jmp_buf, int);
 
 #define setjmp setjmp
 
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 07/17] C23: change the noreturn functions in stdlib.h
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (11 preceding siblings ...)
  2023-04-19 13:02 ` [musl] [C23 divers headers 06/17] C23: adapt setjmp.h Jens Gustedt
@ 2023-04-19 13:11 ` Jens Gustedt
  2023-04-19 13:17 ` [musl] [C23 divers headers 08/17] C23: change the noreturn function in threads.h Jens Gustedt
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19 13:11 UTC (permalink / raw)
  To: musl

---
 include/stdlib.h      | 8 ++++----
 src/exit/_Exit.c      | 2 +-
 src/exit/abort.c      | 2 +-
 src/exit/exit.c       | 2 +-
 src/exit/quick_exit.c | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/stdlib.h b/include/stdlib.h
index c635d99b..8a873f03 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -43,12 +43,12 @@ void *realloc (void *, size_t);
 void free (void *);
 void *aligned_alloc(size_t, size_t);
 
-_Noreturn void abort (void);
+__noreturn void abort (void);
 int atexit (void (*) (void));
-_Noreturn void exit (int);
-_Noreturn void _Exit (int);
+__noreturn void exit (int);
+__noreturn void _Exit (int);
 int at_quick_exit (void (*) (void));
-_Noreturn void quick_exit (int);
+__noreturn void quick_exit (int);
 
 char *getenv (const char *);
 
diff --git a/src/exit/_Exit.c b/src/exit/_Exit.c
index 7a6115c7..344e0194 100644
--- a/src/exit/_Exit.c
+++ b/src/exit/_Exit.c
@@ -1,7 +1,7 @@
 #include <stdlib.h>
 #include "syscall.h"
 
-_Noreturn void _Exit(int ec)
+__noreturn void _Exit(int ec)
 {
 	__syscall(SYS_exit_group, ec);
 	for (;;) __syscall(SYS_exit, ec);
diff --git a/src/exit/abort.c b/src/exit/abort.c
index f21f458e..276eb754 100644
--- a/src/exit/abort.c
+++ b/src/exit/abort.c
@@ -6,7 +6,7 @@
 #include "lock.h"
 #include "ksigaction.h"
 
-_Noreturn void abort(void)
+__noreturn void abort(void)
 {
 	raise(SIGABRT);
 
diff --git a/src/exit/exit.c b/src/exit/exit.c
index a6869b37..6ceb4f6d 100644
--- a/src/exit/exit.c
+++ b/src/exit/exit.c
@@ -24,7 +24,7 @@ static void libc_exit_fini(void)
 
 weak_alias(libc_exit_fini, __libc_exit_fini);
 
-_Noreturn void exit(int code)
+__noreturn void exit(int code)
 {
 	__funcs_on_exit();
 	__libc_exit_fini();
diff --git a/src/exit/quick_exit.c b/src/exit/quick_exit.c
index ada91348..e4167836 100644
--- a/src/exit/quick_exit.c
+++ b/src/exit/quick_exit.c
@@ -4,7 +4,7 @@
 static void dummy() { }
 weak_alias(dummy, __funcs_on_quick_exit);
 
-_Noreturn void quick_exit(int code)
+__noreturn void quick_exit(int code)
 {
 	__funcs_on_quick_exit();
 	_Exit(code);
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 08/17] C23: change the noreturn function in threads.h
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (12 preceding siblings ...)
  2023-04-19 13:11 ` [musl] [C23 divers headers 07/17] C23: change the noreturn functions in stdlib.h Jens Gustedt
@ 2023-04-19 13:17 ` Jens Gustedt
  2023-04-19 13:56 ` [musl] [C23 divers headers 14/17] C23: allow va_start to receive only one argument Jens Gustedt
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19 13:17 UTC (permalink / raw)
  To: musl

---
 include/threads.h      | 2 +-
 src/thread/thrd_exit.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/threads.h b/include/threads.h
index 52ec3100..608ff2a3 100644
--- a/include/threads.h
+++ b/include/threads.h
@@ -41,7 +41,7 @@ enum {
 #define ONCE_FLAG_INIT 0
 
 int thrd_create(thrd_t *, thrd_start_t, void *);
-_Noreturn void thrd_exit(int);
+__noreturn void thrd_exit(int);
 
 int thrd_detach(thrd_t);
 int thrd_join(thrd_t, int *);
diff --git a/src/thread/thrd_exit.c b/src/thread/thrd_exit.c
index 9b291ae3..fd094441 100644
--- a/src/thread/thrd_exit.c
+++ b/src/thread/thrd_exit.c
@@ -2,7 +2,7 @@
 #include <pthread.h>
 #include <stdint.h>
 
-_Noreturn void thrd_exit(int result)
+__noreturn void thrd_exit(int result)
 {
 	__pthread_exit((void*)(intptr_t)result);
 }
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 14/17] C23: allow va_start to receive only one argument
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (13 preceding siblings ...)
  2023-04-19 13:17 ` [musl] [C23 divers headers 08/17] C23: change the noreturn function in threads.h Jens Gustedt
@ 2023-04-19 13:56 ` Jens Gustedt
  2023-04-21 11:33 ` [musl] [C23 divers headers 01/17] C23: add the WIDTH macros for the standard integer types Jens Gustedt
  2023-04-22 20:06 ` [musl] [C23 divers headers 05/17] C23: memccpy, strdup and strndup are now standard C Jens Gustedt
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-19 13:56 UTC (permalink / raw)
  To: musl

C23 allows functions that only have ... and no other
arguments. Therefore the second argument to va_start, that was not
useful anymore, has been removed. For backwards compatibility it is
still possible to provide such an argument and the va_start macro has
to be adapted such that it is able to cope with one or two arguments.

We take care of this by using the new __VA_OPT__ preprocessing
feature, for which we also construct a feature test on the fly.
---
 include/stdarg.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/stdarg.h b/include/stdarg.h
index 3256f805..38db6257 100644
--- a/include/stdarg.h
+++ b/include/stdarg.h
@@ -1,5 +1,5 @@
-#ifndef _STDARG_H
-#define _STDARG_H
+#ifndef __STDC_VERSION_STDARG_H__
+#define __STDC_VERSION_STDARG_H__ 202311L
 
 #ifdef __cplusplus
 extern "C" {
@@ -9,7 +9,10 @@ extern "C" {
 
 #include <bits/alltypes.h>
 
-#define va_start(v,l)   __builtin_va_start(v,l)
+#define va_start(...) __va_start1(__VA_ARGS__ , 0, )
+#define __va_start1(...) __va_start2(__VA_ARGS__)
+#define __va_start2(v, l, ...) __builtin_va_start(v, l)
+
 #define va_end(v)       __builtin_va_end(v)
 #define va_arg(v,l)     __builtin_va_arg(v,l)
 #define va_copy(d,s)    __builtin_va_copy(d,s)
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 01/17] C23: add the WIDTH macros for the standard integer types
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (14 preceding siblings ...)
  2023-04-19 13:56 ` [musl] [C23 divers headers 14/17] C23: allow va_start to receive only one argument Jens Gustedt
@ 2023-04-21 11:33 ` Jens Gustedt
  2023-04-22 20:06 ` [musl] [C23 divers headers 05/17] C23: memccpy, strdup and strndup are now standard C Jens Gustedt
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-21 11:33 UTC (permalink / raw)
  To: musl

These have not previously reserved, nevertheless we define them
without feature macro. This is because these are now the fundamental
definitions for standard integer types, basically all other features
of standard integer types can now be derived from them. We could later
add a cleanup patch, that would exactly do that: provide the width of
all integer types and then derive MIN and MAX macros systematically
from that.
---
 include/limits.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/limits.h b/include/limits.h
index 53a27b9d..476f4891 100644
--- a/include/limits.h
+++ b/include/limits.h
@@ -5,6 +5,24 @@
 
 #include <bits/alltypes.h> /* __LONG_MAX */
 
+#define BOOL_WIDTH 1
+#define CHAR_WIDTH 8
+#define UCHAR_WIDTH 8
+#define SCHAR_WIDTH 8
+#define USHRT_WIDTH 16
+#define SHRT_WIDTH 16
+#define UINT_WIDTH 32
+#define INT_WIDTH 32
+#define ULLONG_WIDTH 64
+#define LLONG_WIDTH 64
+#if __LONG_MAX == 0x7fffffff
+#define ULONG_WIDTH 32
+#define LONG_WIDTH 32
+#else
+#define ULONG_WIDTH 64
+#define LONG_WIDTH 64
+#endif
+
 /* Support signed or unsigned plain-char */
 
 #if '\xff' > 0
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 05/17] C23: memccpy, strdup and strndup are now standard C
  2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
                   ` (15 preceding siblings ...)
  2023-04-21 11:33 ` [musl] [C23 divers headers 01/17] C23: add the WIDTH macros for the standard integer types Jens Gustedt
@ 2023-04-22 20:06 ` Jens Gustedt
  16 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-04-22 20:06 UTC (permalink / raw)
  To: musl

Just remove the feature guards around these. These guards had not even
strictly been necessary before, because prefixes mem and str are
reserved.
---
 include/string.h | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/string.h b/include/string.h
index db73d2a9..7df7a402 100644
--- a/include/string.h
+++ b/include/string.h
@@ -55,6 +55,10 @@ size_t strlen (const char *);
 
 char *strerror (int);
 
+char *strdup (const char *);
+char *strndup (const char *, size_t);
+void *memccpy (void *__restrict, const void *__restrict, int, size_t);
+
 #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
 #include <strings.h>
 #endif
@@ -67,8 +71,6 @@ int strerror_r (int, char *, size_t);
 char *stpcpy(char *__restrict, const char *__restrict);
 char *stpncpy(char *__restrict, const char *__restrict, size_t);
 size_t strnlen (const char *, size_t);
-char *strdup (const char *);
-char *strndup (const char *, size_t);
 char *strsignal(int);
 char *strerror_l (int, locale_t);
 int strcoll_l (const char *, const char *, locale_t);
@@ -76,11 +78,6 @@ size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
 void *memmem(const void *, size_t, const void *, size_t);
 #endif
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
- || defined(_BSD_SOURCE)
-void *memccpy (void *__restrict, const void *__restrict, int, size_t);
-#endif
-
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 char *strsep(char **, const char *);
 size_t strlcat (char *, const char *, size_t);
-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 00/17] boring header update
@ 2023-05-24 12:54 Jens Gustedt
  2023-04-15 13:21 ` [musl] [C23 divers headers 02/17] C23: Add the *_WIDTH macros to stdint.h Jens Gustedt
                   ` (16 more replies)
  0 siblings, 17 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-05-24 12:54 UTC (permalink / raw)
  To: musl

These are patches that should be more or less boring for new features
that have been already in POSIX and similar.

But evidently they need critical eyes.

Jens Gustedt (17):
  C23: add the WIDTH macros for the standard integer types
  C23: Add the *_WIDTH macros to stdint.h
  C23: add call_once to stdlib.h
  C23: add timegm, gmtime_r and localtime_r to time.h in C23 mode
  C23: memccpy, strdup and strndup are now standard C
  C23: adapt setjmp.h
  C23: change the noreturn functions in stdlib.h
  C23: change the noreturn function in threads.h
  C23: update stdbool.h
  C23: remove the contents of stdalign.h
  C23: remove the static_assert macro
  C23: change the assert macro to ... arguments
  C23: add the __STDC_VERSION_ASSERT_H__ macro
  C23: allow va_start to receive only one argument
  C23: add the unreachable macro
  C23: add the nullptr_t type
  C23: add the __STDC_VERSION_STDDEF_H__ macro

 include/assert.h       | 17 +++++++---
 include/limits.h       | 18 ++++++++++
 include/setjmp.h       |  6 ++--
 include/stdalign.h     | 18 +++++-----
 include/stdarg.h       |  9 +++--
 include/stdbool.h      | 10 ++++--
 include/stddef.h       | 16 +++++++--
 include/stdint.h       | 77 ++++++++++++++++++++++++++++++++++++++++--
 include/stdlib.h       | 12 ++++---
 include/string.h       | 11 +++---
 include/threads.h      |  2 +-
 include/time.h         |  7 ++--
 src/exit/_Exit.c       |  2 +-
 src/exit/abort.c       |  2 +-
 src/exit/exit.c        |  2 +-
 src/exit/quick_exit.c  |  2 +-
 src/thread/thrd_exit.c |  2 +-
 17 files changed, 168 insertions(+), 45 deletions(-)

-- 
2.34.1

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 15/17] C23: add the unreachable macro
  2023-04-19  6:38 ` [musl] [C23 divers headers 15/17] C23: add the unreachable macro Jens Gustedt
@ 2023-05-24 14:21   ` Rich Felker
  2023-05-24 14:26     ` Jₑₙₛ Gustedt
  0 siblings, 1 reply; 30+ messages in thread
From: Rich Felker @ 2023-05-24 14:21 UTC (permalink / raw)
  To: Jens Gustedt; +Cc: musl

On Wed, Apr 19, 2023 at 08:38:04AM +0200, Jens Gustedt wrote:
> ---
>  include/stddef.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/stddef.h b/include/stddef.h
> index f25b8639..09be5fb6 100644
> --- a/include/stddef.h
> +++ b/include/stddef.h
> @@ -24,4 +24,6 @@
>  #define offsetof(type, member) ((size_t)( (char *)&(((type *)0)->member) - (char *)0 ))
>  #endif
>  
> +#define unreachable() __builtin_unreachable()
> +
>  #endif
> -- 
> 2.34.1

This is a namespace violation unless protected by a C version check.

Rich

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 16/17] C23: add the nullptr_t type
  2023-04-19  6:42 ` [musl] [C23 divers headers 16/17] C23: add the nullptr_t type Jens Gustedt
@ 2023-05-24 14:22   ` Rich Felker
  2023-05-24 14:29     ` Jₑₙₛ Gustedt
  0 siblings, 1 reply; 30+ messages in thread
From: Rich Felker @ 2023-05-24 14:22 UTC (permalink / raw)
  To: Jens Gustedt; +Cc: musl

On Wed, Apr 19, 2023 at 08:42:15AM +0200, Jens Gustedt wrote:
> This will only work with compilers that implement typeof and
> nullptr. Currently this doesn't work for gcc but this will probably be
> in gcc-13. Therefore the version test uses the future date of 202311L
> which is the foreseen value for C23 final.
> 
> For clang there are better feature test macros, namely
> __is_identifier(nullptr) can be used to test if nullptr is an
> identifier or a keyword. In particular, this feature now seems to work
> with clang 16.0.2.
> ---
>  include/stddef.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/include/stddef.h b/include/stddef.h
> index 09be5fb6..e4d6b2ef 100644
> --- a/include/stddef.h
> +++ b/include/stddef.h
> @@ -26,4 +26,14 @@
>  
>  #define unreachable() __builtin_unreachable()
>  
> +#if __STDC_VERSION__ >= 202311L
> +typedef typeof(nullptr) nullptr_t;
> +#else
> +#if __clang__
> +#if !__is_identifier(nullptr)
> +typedef typeof(nullptr) nullptr_t;
> +#endif
> +#endif
> +#endif
> +
>  #endif
> -- 
> 2.34.1

nullptr_t is not defined pre-C23 so the __clang__ branch shouldn't be
there.

Rich

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 03/17] C23: add call_once to stdlib.h
  2023-04-17  9:09 ` [musl] [C23 divers headers 03/17] C23: add call_once to stdlib.h Jens Gustedt
@ 2023-05-24 14:23   ` Rich Felker
  0 siblings, 0 replies; 30+ messages in thread
From: Rich Felker @ 2023-05-24 14:23 UTC (permalink / raw)
  To: Jens Gustedt; +Cc: musl

On Mon, Apr 17, 2023 at 11:09:20AM +0200, Jens Gustedt wrote:
> Since C23, call_once, once_flag and ONCE_FLAG_INIT are also accessible
> even if the platform does not have the threads option. Add them to the
> header.
> 
> The identifiers once_flag and ONCE_FLAG_INIT were not reserved in C17
> if the header threads.h was not included, so this potentially creates
> naming conflicts.
> ---
>  include/stdlib.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/include/stdlib.h b/include/stdlib.h
> index 475190bf..c635d99b 100644
> --- a/include/stdlib.h
> +++ b/include/stdlib.h
> @@ -172,6 +172,10 @@ long double strtold_l(const char *__restrict, char **__restrict, struct __locale
>  #endif
>  #endif
>  
> +#define ONCE_FLAG_INIT 0
> +typedef int once_flag;
> +void call_once(once_flag *, void (*)(void));
> +
>  #ifdef __cplusplus
>  }
>  #endif
> -- 
> 2.34.1

This is borderline whether it matters (the name is unlikely to clash
and eventually we will only support namespace rules for latest C) but
it's probably better to guard it with C version check.

Rich

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 10/17] C23: remove the contents of stdalign.h
  2023-04-19 11:48 ` [musl] [C23 divers headers 10/17] C23: remove the contents of stdalign.h Jens Gustedt
@ 2023-05-24 14:25   ` Rich Felker
  0 siblings, 0 replies; 30+ messages in thread
From: Rich Felker @ 2023-05-24 14:25 UTC (permalink / raw)
  To: Jens Gustedt; +Cc: musl

On Wed, Apr 19, 2023 at 01:48:23PM +0200, Jens Gustedt wrote:
> This now has no contents because the features have been promoted to
> keywords.
> ---
>  include/stdalign.h | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/include/stdalign.h b/include/stdalign.h
> index 2cc94be3..477ae69c 100644
> --- a/include/stdalign.h
> +++ b/include/stdalign.h
> @@ -1,20 +1,20 @@
> -#ifndef _STDALIGN_H
> -#define _STDALIGN_H
> +#ifndef __STDC_VERSION_STDALIGN_H__
> +#define __STDC_VERSION_STDALIGN_H__ 202311L
>  
>  #ifndef __cplusplus
>  
>  /* this whole header only works in C11 or with compiler extensions */
>  #if __STDC_VERSION__ < 201112L && defined( __GNUC__)
> -#define _Alignas(t) __attribute__((__aligned__(t)))
> -#define _Alignof(t) __alignof__(t)
> -#endif
> -
> -#define alignas _Alignas
> -#define alignof _Alignof
> -
> +# define _Alignas(t) __attribute__((__aligned__(t)))
> +# define _Alignof(t) __alignof__(t)
>  #endif
>  
> +/* Starting with C23 this header has no contents because these are keywords. */
> +#if __STDC_VERSION__ < 202311L
>  #define __alignas_is_defined 1
>  #define __alignof_is_defined 1
> +#endif
> +
> +#endif
>  
>  #endif
> -- 
> 2.34.1

This needs to be conditional on C version. The existing logic should
not be removed but should be skipped for C23. While we will only
support strict namespace conformance for latest C (and for subtle
behavioral things), we don't gratuitously drop support for old
versions of the standard completely like this.

Rich

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 15/17] C23: add the unreachable macro
  2023-05-24 14:21   ` Rich Felker
@ 2023-05-24 14:26     ` Jₑₙₛ Gustedt
  2023-05-24 14:30       ` Rich Felker
  0 siblings, 1 reply; 30+ messages in thread
From: Jₑₙₛ Gustedt @ 2023-05-24 14:26 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

[-- Attachment #1: Type: text/plain, Size: 1367 bytes --]

Rich,

on Wed, 24 May 2023 10:21:05 -0400 you (Rich Felker <dalias@libc.org>)
wrote:

> On Wed, Apr 19, 2023 at 08:38:04AM +0200, Jens Gustedt wrote:
> > ---
> >  include/stddef.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/include/stddef.h b/include/stddef.h
> > index f25b8639..09be5fb6 100644
> > --- a/include/stddef.h
> > +++ b/include/stddef.h
> > @@ -24,4 +24,6 @@
> >  #define offsetof(type, member) ((size_t)( (char *)&(((type
> > *)0)->member) - (char *)0 )) #endif
> >  
> > +#define unreachable() __builtin_unreachable()
> > +
> >  #endif
> > -- 
> > 2.34.1  
> 
> This is a namespace violation unless protected by a C version check.

That would have been my first take also. I changed these things after
you (I think it was you) telling me that generally interfaces that are
added in newer versions of C need not be protected for older
version. I probably misunderstood something. Can you please clarify
under which circumstances you want feature tests and when not?


Thanks
Jₑₙₛ

-- 
:: ICube :::::::::::::::::::::::::::::: deputy director ::
:: Université de Strasbourg :::::::::::::::::::::: ICPS ::
:: INRIA Nancy Grand Est :::::::::::::::::::::::: Camus ::
:: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 ::
:: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 16/17] C23: add the nullptr_t type
  2023-05-24 14:22   ` Rich Felker
@ 2023-05-24 14:29     ` Jₑₙₛ Gustedt
  2023-05-24 14:34       ` Rich Felker
  0 siblings, 1 reply; 30+ messages in thread
From: Jₑₙₛ Gustedt @ 2023-05-24 14:29 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

[-- Attachment #1: Type: text/plain, Size: 699 bytes --]

Rich,

on Wed, 24 May 2023 10:22:01 -0400 you (Rich Felker <dalias@libc.org>)
wrote:

> nullptr_t is not defined pre-C23 so the __clang__ branch shouldn't be
> there.

Well, if I do that, such a change is impossible to test, because there
are not yet any compilers with that version number. How should we do
that, then? Have a test for >= 201800L or so?


Thanks
Jₑₙₛ

-- 
:: ICube :::::::::::::::::::::::::::::: deputy director ::
:: Université de Strasbourg :::::::::::::::::::::: ICPS ::
:: INRIA Nancy Grand Est :::::::::::::::::::::::: Camus ::
:: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 ::
:: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 15/17] C23: add the unreachable macro
  2023-05-24 14:26     ` Jₑₙₛ Gustedt
@ 2023-05-24 14:30       ` Rich Felker
  0 siblings, 0 replies; 30+ messages in thread
From: Rich Felker @ 2023-05-24 14:30 UTC (permalink / raw)
  To: Jₑₙₛ Gustedt; +Cc: musl

On Wed, May 24, 2023 at 04:26:43PM +0200, Jₑₙₛ Gustedt wrote:
> Rich,
> 
> on Wed, 24 May 2023 10:21:05 -0400 you (Rich Felker <dalias@libc.org>)
> wrote:
> 
> > On Wed, Apr 19, 2023 at 08:38:04AM +0200, Jens Gustedt wrote:
> > > ---
> > >  include/stddef.h | 2 ++
> > >  1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/include/stddef.h b/include/stddef.h
> > > index f25b8639..09be5fb6 100644
> > > --- a/include/stddef.h
> > > +++ b/include/stddef.h
> > > @@ -24,4 +24,6 @@
> > >  #define offsetof(type, member) ((size_t)( (char *)&(((type
> > > *)0)->member) - (char *)0 )) #endif
> > >  
> > > +#define unreachable() __builtin_unreachable()
> > > +
> > >  #endif
> > > -- 
> > > 2.34.1  
> > 
> > This is a namespace violation unless protected by a C version check.
> 
> That would have been my first take also. I changed these things after
> you (I think it was you) telling me that generally interfaces that are
> added in newer versions of C need not be protected for older
> version. I probably misunderstood something. Can you please clarify
> under which circumstances you want feature tests and when not?

OK, I agree it's a little bit unclear, but here it's a case of a very
minimalist header (stddef.h) defining a new, plain-english-word macro
that's very likely to conflict with existing code.

I'm not sure where exactly the cutoff point for whether it matters
should be -- this is something community should probably discuss. But
I think this is a really clear case where the namespace should not be
stomped.

Cases where it's almost surely OK, OTOH, are things like promoting
common existing functions to standard -- existing code is almost
surely already avoiding conflicts with these (e.g. the time.h stuff).

Rich

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 16/17] C23: add the nullptr_t type
  2023-05-24 14:29     ` Jₑₙₛ Gustedt
@ 2023-05-24 14:34       ` Rich Felker
  2023-05-24 14:42         ` Jₑₙₛ Gustedt
  0 siblings, 1 reply; 30+ messages in thread
From: Rich Felker @ 2023-05-24 14:34 UTC (permalink / raw)
  To: Jₑₙₛ Gustedt; +Cc: musl

On Wed, May 24, 2023 at 04:29:16PM +0200, Jₑₙₛ Gustedt wrote:
> Rich,
> 
> on Wed, 24 May 2023 10:22:01 -0400 you (Rich Felker <dalias@libc.org>)
> wrote:
> 
> > nullptr_t is not defined pre-C23 so the __clang__ branch shouldn't be
> > there.
> 
> Well, if I do that, such a change is impossible to test, because there
> are not yet any compilers with that version number. How should we do
> that, then? Have a test for >= 201800L or so?

I'm not really convinced this needs testing at this point (what even
is a test testing, if not that the right version results in the
definition being present?), but what does existing -std=c2x or
whatever set the version to? Could probably use >= that instead of >=
the official C23 version.

Rich

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 16/17] C23: add the nullptr_t type
  2023-05-24 14:34       ` Rich Felker
@ 2023-05-24 14:42         ` Jₑₙₛ Gustedt
  2023-05-24 14:49           ` Rich Felker
  0 siblings, 1 reply; 30+ messages in thread
From: Jₑₙₛ Gustedt @ 2023-05-24 14:42 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

[-- Attachment #1: Type: text/plain, Size: 1559 bytes --]

Rich,

on Wed, 24 May 2023 10:34:08 -0400 you (Rich Felker <dalias@libc.org>)
wrote:

> On Wed, May 24, 2023 at 04:29:16PM +0200, Jₑₙₛ Gustedt wrote:
> > Rich,
> > 
> > on Wed, 24 May 2023 10:22:01 -0400 you (Rich Felker
> > <dalias@libc.org>) wrote:
> >   
> > > nullptr_t is not defined pre-C23 so the __clang__ branch
> > > shouldn't be there.  
> > 
> > Well, if I do that, such a change is impossible to test, because
> > there are not yet any compilers with that version number. How
> > should we do that, then? Have a test for >= 201800L or so?  
> 
> I'm not really convinced this needs testing at this point (what even
> is a test testing, if not that the right version results in the
> definition being present?),

I have code that uses these things in `_Generic` to see if they do the
intended choice. (I agree that this is more testing the compiler, than
the library.)

> but what does existing -std=c2x or
> whatever set the version to?

This depends on the compiler and its version. And some of these have
`nullptr` and some don't.

> Could probably use >= that instead of >= the official C23 version.

I'll try to find a cut-off between the clang and gcc version macros.

Thanks
Jₑₙₛ

-- 
:: ICube :::::::::::::::::::::::::::::: deputy director ::
:: Université de Strasbourg :::::::::::::::::::::: ICPS ::
:: INRIA Nancy Grand Est :::::::::::::::::::::::: Camus ::
:: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 ::
:: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 16/17] C23: add the nullptr_t type
  2023-05-24 14:42         ` Jₑₙₛ Gustedt
@ 2023-05-24 14:49           ` Rich Felker
  2023-05-24 15:24             ` Jₑₙₛ Gustedt
  0 siblings, 1 reply; 30+ messages in thread
From: Rich Felker @ 2023-05-24 14:49 UTC (permalink / raw)
  To: Jₑₙₛ Gustedt; +Cc: musl

On Wed, May 24, 2023 at 04:42:53PM +0200, Jₑₙₛ Gustedt wrote:
> Rich,
> 
> on Wed, 24 May 2023 10:34:08 -0400 you (Rich Felker <dalias@libc.org>)
> wrote:
> 
> > On Wed, May 24, 2023 at 04:29:16PM +0200, Jₑₙₛ Gustedt wrote:
> > > Rich,
> > > 
> > > on Wed, 24 May 2023 10:22:01 -0400 you (Rich Felker
> > > <dalias@libc.org>) wrote:
> > >   
> > > > nullptr_t is not defined pre-C23 so the __clang__ branch
> > > > shouldn't be there.  
> > > 
> > > Well, if I do that, such a change is impossible to test, because
> > > there are not yet any compilers with that version number. How
> > > should we do that, then? Have a test for >= 201800L or so?  
> > 
> > I'm not really convinced this needs testing at this point (what even
> > is a test testing, if not that the right version results in the
> > definition being present?),
> 
> I have code that uses these things in `_Generic` to see if they do the
> intended choice. (I agree that this is more testing the compiler, than
> the library.)
> 
> > but what does existing -std=c2x or
> > whatever set the version to?
> 
> This depends on the compiler and its version. And some of these have
> `nullptr` and some don't.
> 
> > Could probably use >= that instead of >= the official C23 version.
> 
> I'll try to find a cut-off between the clang and gcc version macros.

One thought: For testing, you should be able to pass
-D__STDC_VERSION__=whatever to override it, no?

Rich

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [musl] [C23 divers headers 16/17] C23: add the nullptr_t type
  2023-05-24 14:49           ` Rich Felker
@ 2023-05-24 15:24             ` Jₑₙₛ Gustedt
  0 siblings, 0 replies; 30+ messages in thread
From: Jₑₙₛ Gustedt @ 2023-05-24 15:24 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

[-- Attachment #1: Type: text/plain, Size: 849 bytes --]

Rich,

on Wed, 24 May 2023 10:49:06 -0400 you (Rich Felker <dalias@libc.org>)
wrote:

> One thought: For testing, you should be able to pass
> -D__STDC_VERSION__=whatever to override it, no?

Probably. That doesn't solve the problem, though, of knowing during
transition if a C23 feature (which isn't a macro) is yet supported by a
compiler. The clang feature tests are a very good tool for that. I also
have something that mimics this with gcc, but you probably don't want
that in musl, don't you ?-)


Thanks
Jₑₙₛ

-- 
:: ICube :::::::::::::::::::::::::::::: deputy director ::
:: Université de Strasbourg :::::::::::::::::::::: ICPS ::
:: INRIA Nancy Grand Est :::::::::::::::::::::::: Camus ::
:: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 ::
:: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [musl] [C23 divers headers 03/17] C23: add call_once to stdlib.h
  2023-05-31  9:22 [musl] [C23 divers headers 00/17] Jens Gustedt
@ 2023-05-31  9:22 ` Jens Gustedt
  0 siblings, 0 replies; 30+ messages in thread
From: Jens Gustedt @ 2023-05-31  9:22 UTC (permalink / raw)
  To: musl

Since C23, call_once, once_flag and ONCE_FLAG_INIT are also accessible
even if the platform does not have the threads option. Add them to the
header.

The identifiers once_flag and ONCE_FLAG_INIT were not reserved in C17
if the header threads.h was not included, so we protect this with the
version macro.
---
 include/stdlib.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/stdlib.h b/include/stdlib.h
index 475190bf..0e66f84a 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -172,6 +172,12 @@ long double strtold_l(const char *__restrict, char **__restrict, struct __locale
 #endif
 #endif
 
+#if __STDC_VERSION__ >= 202000L
+#define ONCE_FLAG_INIT 0
+typedef int once_flag;
+void call_once(once_flag *, void (*)(void));
+#endif
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.34.1


^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2023-05-31  9:24 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-24 12:54 [musl] [C23 divers headers 00/17] boring header update Jens Gustedt
2023-04-15 13:21 ` [musl] [C23 divers headers 02/17] C23: Add the *_WIDTH macros to stdint.h Jens Gustedt
2023-04-17  9:09 ` [musl] [C23 divers headers 03/17] C23: add call_once to stdlib.h Jens Gustedt
2023-05-24 14:23   ` Rich Felker
2023-04-17 19:52 ` [musl] [C23 divers headers 04/17] C23: add timegm, gmtime_r and localtime_r to time.h in C23 mode Jens Gustedt
2023-04-19  6:38 ` [musl] [C23 divers headers 15/17] C23: add the unreachable macro Jens Gustedt
2023-05-24 14:21   ` Rich Felker
2023-05-24 14:26     ` Jₑₙₛ Gustedt
2023-05-24 14:30       ` Rich Felker
2023-04-19  6:42 ` [musl] [C23 divers headers 16/17] C23: add the nullptr_t type Jens Gustedt
2023-05-24 14:22   ` Rich Felker
2023-05-24 14:29     ` Jₑₙₛ Gustedt
2023-05-24 14:34       ` Rich Felker
2023-05-24 14:42         ` Jₑₙₛ Gustedt
2023-05-24 14:49           ` Rich Felker
2023-05-24 15:24             ` Jₑₙₛ Gustedt
2023-04-19  6:46 ` [musl] [C23 divers headers 17/17] C23: add the __STDC_VERSION_STDDEF_H__ macro Jens Gustedt
2023-04-19  8:16 ` [musl] [C23 divers headers 09/17] C23: update stdbool.h Jens Gustedt
2023-04-19 11:48 ` [musl] [C23 divers headers 10/17] C23: remove the contents of stdalign.h Jens Gustedt
2023-05-24 14:25   ` Rich Felker
2023-04-19 11:59 ` [musl] [C23 divers headers 11/17] C23: remove the static_assert macro Jens Gustedt
2023-04-19 12:17 ` [musl] [C23 divers headers 12/17] C23: change the assert macro to ... arguments Jens Gustedt
2023-04-19 12:48 ` [musl] [C23 divers headers 13/17] C23: add the __STDC_VERSION_ASSERT_H__ macro Jens Gustedt
2023-04-19 13:02 ` [musl] [C23 divers headers 06/17] C23: adapt setjmp.h Jens Gustedt
2023-04-19 13:11 ` [musl] [C23 divers headers 07/17] C23: change the noreturn functions in stdlib.h Jens Gustedt
2023-04-19 13:17 ` [musl] [C23 divers headers 08/17] C23: change the noreturn function in threads.h Jens Gustedt
2023-04-19 13:56 ` [musl] [C23 divers headers 14/17] C23: allow va_start to receive only one argument Jens Gustedt
2023-04-21 11:33 ` [musl] [C23 divers headers 01/17] C23: add the WIDTH macros for the standard integer types Jens Gustedt
2023-04-22 20:06 ` [musl] [C23 divers headers 05/17] C23: memccpy, strdup and strndup are now standard C Jens Gustedt
2023-05-31  9:22 [musl] [C23 divers headers 00/17] Jens Gustedt
2023-05-31  9:22 ` [musl] [C23 divers headers 03/17] C23: add call_once to stdlib.h Jens Gustedt

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).