|
|
Message-ID: <cover.1764260495.git.alx@kernel.org>
Date: Thu, 27 Nov 2025 17:27:24 +0100
From: Alejandro Colomar <alx@...nel.org>
To: musl@...ts.openwall.com
Cc: Alejandro Colomar <alx@...nel.org>, Markus Wichmann <nullplan@....net>
Subject: [PATCH v4 0/1] include/string.h: Implement QChar and QVoid wrappers
standardized in C23
Hi!
In v4, I've also added the QVoid wrappers, thanks to Markus's
suggestion. See the range-diff below.
Tested:
alx@...uan:~/tmp$ cat strchr.c
#include <stdio.h>
#include <string.h>
int
main(int argc, const char *argv[argc + 1])
{
char *p;
p = strchr(argv[0], 'u');
puts(p);
const char *cp;
cp = strchr(argv[0], 'u');
puts(cp);
&strchr(argv[0], 'u');
strchr(argv[0], 'u') = NULL;
int *i;
i = strchr(i, 'u');
}
alx@...uan:~/tmp$ gcc -I /opt/local/musl/libc/qchar/include/ strchr.c
strchr.c: In function ‘main’:
strchr.c:10:11: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
10 | p = strchr(argv[0], 'u');
| ^
strchr.c:18:9: error: lvalue required as unary ‘&’ operand
18 | &strchr(argv[0], 'u');
| ^
strchr.c:20:30: error: lvalue required as left operand of assignment
20 | strchr(argv[0], 'u') = NULL;
| ^
In file included from strchr.c:2:
strchr.c:24:20: error: passing argument 1 of ‘strchr’ from incompatible pointer type [-Wincompatible-pointer-types]
24 | i = strchr(i, 'u');
| ^
| |
| int *
/opt/local/musl/libc/qchar/include/string.h:69:54: note: in definition of macro ‘strchr’
69 | # define strchr(s, chr) ((__QCharptrof(s)) strchr(s, chr))
| ^
/opt/local/musl/libc/qchar/include/string.h:54:15: note: expected ‘const char *’ but argument is of type ‘int *’
54 | char *strchr (const char *, int);
| ^~~~~~~~~~~~
strchr.c:24:11: error: assignment to ‘int *’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]
24 | i = strchr(i, 'u');
| ^
Have a lovely day!
Alex
Alejandro Colomar (1):
include/string.h: Implement QChar and QVoid wrappers standardized in
C23
include/string.h | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
Range-diff against v3:
1: c47e9570 ! 1: b891d212 include/string.h: Implement QChar wrappers standardized in C23
@@ Metadata
Author: Alejandro Colomar <alx@...nel.org>
## Commit message ##
- include/string.h: Implement QChar wrappers standardized in C23
+ include/string.h: Implement QChar and QVoid wrappers standardized in C23
+ Co-authored-by: Markus Wichmann <nullplan@....net>
Signed-off-by: Alejandro Colomar <alx@...nel.org>
## include/string.h ##
@@ include/string.h: extern "C" {
#include <bits/alltypes.h>
-+#define __QCharof(s) typeof \
++#define __QVoidptrof(p) typeof(1?(p):(void*)"")
++#define __QCharptrof(s) typeof \
+( \
-+ _Generic(s, \
-+ const char *: (const char){}, \
-+ const void *: (const char){}, \
-+ char *: (char){}, \
-+ void *: (char){} \
++ _Generic(__QVoidptrof(s), \
++ const void *: (const char *) 0, \
++ void *: (char *) 0 \
+ ) \
+)
+
@@ include/string.h: size_t strlen (const char *);
char *strerror (int);
+#if __STDC_VERSION__ >= 202311L
-+# define strchr(s, chr) ((__QCharof(s) *) strchr(s, chr))
-+# define strrchr(s, chr) ((__QCharof(s) *) strrchr(s, chr))
-+# define strpbrk(s, chrs) ((__QCharof(s) *) strpbrk(s, chrs))
-+# define strstr(s, str) ((__QCharof(s) *) strstr(s, str))
++# define memchr(p, chr) ((__QVoidptrof(p)) memchr(p, chr))
++# define strchr(s, chr) ((__QCharptrof(s)) strchr(s, chr))
++# define strrchr(s, chr) ((__QCharptrof(s)) strrchr(s, chr))
++# define strpbrk(s, chrs) ((__QCharptrof(s)) strpbrk(s, chrs))
++# define strstr(s, str) ((__QCharptrof(s)) strstr(s, str))
+#endif
+
#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#include <strings.h>
#endif
+@@ include/string.h: char *strerror_l (int, locale_t);
+ int strcoll_l (const char *, const char *, locale_t);
+ size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
+ void *memmem(const void *, size_t, const void *, size_t);
++# if __STDC_VERSION__ >= 202311L
++# define memmem(p, mem) ((__QVoidptrof(p)) memmem(p, mem))
++# endif
+ #endif
+
+ #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
@@ include/string.h: char *strchrnul(const char *, int);
char *strcasestr(const char *, const char *);
void *memrchr(const void *, int, size_t);
void *mempcpy(void *, const void *, size_t);
+# if __STDC_VERSION__ >= 202311L
-+# define strchrnul(s, chr) ((__QCharof(s) *) strchrnul(s, chr))
-+# define strcasestr(s, str) ((__QCharof(s) *) strcasestr(s, str))
++# define strchrnul(s, chr) ((__QCharptrof(s)) strchrnul(s, chr))
++# define strcasestr(s, str) ((__QCharptrof(s)) strcasestr(s, str))
++# define memrchr(p, chr) ((__QVoidptrof(p)) memrchr(p, chr))
+# endif
#endif
--
2.51.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.