mailing list of musl libc
 help / color / mirror / Atom feed
* [musl] [PATCH] support the __STDC_WANT_LIB_EXT2__ feature test macro
@ 2021-07-16 11:58 John Scott
  2021-07-16 16:06 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: John Scott @ 2021-07-16 11:58 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 524 bytes --]

Hello,

As a feature, I suggest that musl supports the __STDC_WANT_LIB_EXT2__
feature test macro specified in the ISO/IEC Dynamic Allocations TR.
I've attached a patch to accomplish this and which makes minimal
changes to the headers to get musl's support comparable to glibc's.

I was not able to get my hands on the official publication, so I only
referred to the latest draft, which is available here:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1388.pdf

I'm not subscribed, so please CC me on replies.

[-- Attachment #1.2: git format-patch-style patch --]
[-- Type: text/x-patch, Size: 4784 bytes --]

From e923a4fc391909428914d3bebfb02b5431be338a Mon Sep 17 00:00:00 2001
From: John Scott <jscott@posteo.net>
Date: Fri, 16 Jul 2021 07:34:29 -0400
Subject: [PATCH] support the __STDC_WANT_LIB_EXT2__ feature test macro

this is intended to aid applications that wish to use the functionality
specified in ISO/IEC TR 24731-2:2010. Most of these functions are
specified by POSIX, except for (v)asprintf and some of the wide
character functions.

we don't define __STDC_ALLOC_LIB__ since the latter are not implemented.
Also, implementations are required to diagnose when the definition of
__STDC_WANT_LIB_EXT2__ changes after including additional headers, but
we currently don't check this.
---
 include/stdio.h  | 16 +++++++++++-----
 include/string.h |  9 +++++++--
 include/wchar.h  |  7 ++++++-
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/include/stdio.h b/include/stdio.h
index 3604198c..15687ba3 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -131,9 +131,19 @@ FILE *tmpfile(void);
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
- || defined(_BSD_SOURCE)
+ || defined(_BSD_SOURCE) \
+ ||(defined(__STDC_WANT_LIB_EXT2__) && __STDC_WANT_LIB_EXT2__)
 FILE *fmemopen(void *__restrict, size_t, const char *__restrict);
 FILE *open_memstream(char **, size_t *);
+int asprintf(char **, const char *, ...);
+int vasprintf(char **, const char *, __isoc_va_list);
+ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
+ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
+#endif
+
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 FILE *fdopen(int, const char *);
 FILE *popen(const char *, const char *);
 int pclose(FILE *);
@@ -149,8 +159,6 @@ int getc_unlocked(FILE *);
 int getchar_unlocked(void);
 int putc_unlocked(int, FILE *);
 int putchar_unlocked(int);
-ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
-ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
 int renameat(int, const char *, int, const char *);
 char *ctermid(char *);
 #define L_ctermid 20
@@ -180,8 +188,6 @@ int fileno_unlocked(FILE *);
 int getw(FILE *);
 int putw(int, FILE *);
 char *fgetln(FILE *, size_t *);
-int asprintf(char **, const char *, ...);
-int vasprintf(char **, const char *, __isoc_va_list);
 #endif
 
 #ifdef _GNU_SOURCE
diff --git a/include/string.h b/include/string.h
index 795a2abc..fa3ad27e 100644
--- a/include/string.h
+++ b/include/string.h
@@ -65,14 +65,19 @@ 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);
 size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
 #endif
 
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \
+ ||(defined(__STDC_WANT_LIB_EXT2__) && __STDC_WANT_LIB_EXT2__)
+char *strdup (const char *);
+char *strndup (const char *, size_t);
+#endif
+
 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  || defined(_BSD_SOURCE)
 void *memccpy (void *__restrict, const void *__restrict, int, size_t);
diff --git a/include/wchar.h b/include/wchar.h
index 88eb55b1..6f8af081 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -157,7 +157,6 @@ size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)  || defined(_BSD_SOURCE)
-FILE *open_wmemstream(wchar_t **, size_t *);
 size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict);
 size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict);
 wchar_t *wcsdup(const wchar_t *);
@@ -172,6 +171,12 @@ int wcscoll_l(const wchar_t *, const wchar_t *, locale_t);
 size_t wcsxfrm_l(wchar_t *__restrict, const wchar_t *__restrict, size_t, locale_t);
 #endif
 
+#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \
+ ||(defined(__STDC_WANT_LIB_EXT2__) && __STDC_WANT_LIB_EXT2__)
+FILE *open_wmemstream(wchar_t **, size_t *);
+#endif
+
 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int wcwidth (wchar_t);
 int wcswidth (const wchar_t *, size_t);
-- 
2.30.2


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

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

* Re: [musl] [PATCH] support the __STDC_WANT_LIB_EXT2__ feature test macro
  2021-07-16 11:58 [musl] [PATCH] support the __STDC_WANT_LIB_EXT2__ feature test macro John Scott
@ 2021-07-16 16:06 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2021-07-16 16:06 UTC (permalink / raw)
  To: John Scott; +Cc: musl

On Fri, Jul 16, 2021 at 11:58:47AM +0000, John Scott wrote:
> Hello,
> 
> As a feature, I suggest that musl supports the __STDC_WANT_LIB_EXT2__
> feature test macro specified in the ISO/IEC Dynamic Allocations TR.
> I've attached a patch to accomplish this and which makes minimal
> changes to the headers to get musl's support comparable to glibc's.
> 
> I was not able to get my hands on the official publication, so I only
> referred to the latest draft, which is available here:
> http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1388.pdf
> 
> I'm not subscribed, so please CC me on replies.

> From e923a4fc391909428914d3bebfb02b5431be338a Mon Sep 17 00:00:00 2001
> From: John Scott <jscott@posteo.net>
> Date: Fri, 16 Jul 2021 07:34:29 -0400
> Subject: [PATCH] support the __STDC_WANT_LIB_EXT2__ feature test macro
> 
> this is intended to aid applications that wish to use the functionality
> specified in ISO/IEC TR 24731-2:2010. Most of these functions are
> specified by POSIX, except for (v)asprintf and some of the wide
> character functions.
> 
> we don't define __STDC_ALLOC_LIB__ since the latter are not implemented.
> Also, implementations are required to diagnose when the definition of
> __STDC_WANT_LIB_EXT2__ changes after including additional headers, but
> we currently don't check this.

I'm not entirely against this, but I somewhat question both the
practical value (does anyone actually program to a "suppress POSIX but
want extensions from an unadopted C TR" profile?) and the potential
quagmire of getting bogged down in supporting a lot of TRs that never
make it into being an official part of the standard.

In particular we would need to be aware of any divergence between
these TRs and the corresponding specifications in POSIX; things would
get very messy if they disagree, since POSIX is aligned with ISO C but
*not* with random TRs. Moreover we don't even implement all of this TR
(the added wide functions you noted).

> ---
>  include/stdio.h  | 16 +++++++++++-----
>  include/string.h |  9 +++++++--
>  include/wchar.h  |  7 ++++++-
>  3 files changed, 24 insertions(+), 8 deletions(-)
> 
> diff --git a/include/stdio.h b/include/stdio.h
> index 3604198c..15687ba3 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -131,9 +131,19 @@ FILE *tmpfile(void);
>  
>  #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
>   || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
> - || defined(_BSD_SOURCE)
> + || defined(_BSD_SOURCE) \
> + ||(defined(__STDC_WANT_LIB_EXT2__) && __STDC_WANT_LIB_EXT2__)

Small nit if this change is taken: the defined() condition isn't
needed and isn't doing anything here. Either way the default expansion
to 0 when it's not defined happens (because they're in the same #if)
and in any case musl is okay with using that part of the language.

Rich

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

end of thread, other threads:[~2021-07-16 16:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-16 11:58 [musl] [PATCH] support the __STDC_WANT_LIB_EXT2__ feature test macro John Scott
2021-07-16 16:06 ` Rich Felker

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/musl

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ http://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git