mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] add missing *_unlocked and wcsftime_l prototypes to wchar.h
@ 2016-09-06 21:09 Daniel Sabogal
  2016-09-06 21:09 ` Daniel Sabogal
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Sabogal @ 2016-09-06 21:09 UTC (permalink / raw)
  To: musl

I noticed that musl does not provide prototypes for the unlocked variants of
wchar.h file I/O and wcsftime_l in <wchar.h>.

But musl does define and export these functions:

nm -g /usr/lib/libc.so | grep 'lock\|time_l' | grep wc
0000000000057210 T __fgetwc_unlocked
0000000000057c10 T __fputwc_unlocked
000000000006bbf0 T __wcsftime_l
0000000000057210 W fgetwc_unlocked
0000000000057c10 W fputwc_unlocked
0000000000057210 W getwc_unlocked
0000000000058f50 W getwchar_unlocked
0000000000057c10 W putwc_unlocked
0000000000059ca0 W putwchar_unlocked
000000000006bbf0 W wcsftime_l

These functions are available in glibc.

#define _GNU_SOURCE
#include <wchar.h>
int main(void)
{
        wint_t (*a0)(FILE *) = getwc_unlocked;
        wint_t (*a1)(void) = getwchar_unlocked;
        wint_t (*a2)(FILE *) = fgetwc_unlocked;
        wint_t (*a3)(wchar_t, FILE *) = fputwc_unlocked;
        wint_t (*a4)(wchar_t, FILE *) = putwc_unlocked;
        wint_t (*a5)(wchar_t) = putwchar_unlocked;
        wchar_t *(*a6)(wchar_t *restrict, int, FILE *restrict) = fgetws_unlocked;
        int (*a7)(const wchar_t *restrict, FILE *restrict) = fputws_unlocked;
        size_t (*b0)(wchar_t *restrict, size_t, const wchar_t *restrict, const struct tm *restrict, locale_t) = wcsftime_l;
}
-- 
2.10.0



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

* [PATCH] add missing *_unlocked and wcsftime_l prototypes to wchar.h
  2016-09-06 21:09 [PATCH] add missing *_unlocked and wcsftime_l prototypes to wchar.h Daniel Sabogal
@ 2016-09-06 21:09 ` Daniel Sabogal
  2016-09-09 23:02   ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Sabogal @ 2016-09-06 21:09 UTC (permalink / raw)
  To: musl

these functions had been implemented, but prototypes were not made available
---
 include/wchar.h               | 12 ++++++++++++
 src/stdio/getwchar.c          |  2 --
 src/stdio/getwchar_unlocked.c |  8 ++++++++
 src/stdio/putwchar.c          |  2 --
 src/stdio/putwchar_unlocked.c |  8 ++++++++
 5 files changed, 28 insertions(+), 4 deletions(-)
 create mode 100644 src/stdio/getwchar_unlocked.c
 create mode 100644 src/stdio/putwchar_unlocked.c

diff --git a/include/wchar.h b/include/wchar.h
index 0167dce..58818f6 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -136,6 +136,18 @@ size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const s
 
 #undef iswdigit
 
+#if defined(_GNU_SOURCE)
+wint_t fgetwc_unlocked (FILE *);
+wint_t getwc_unlocked (FILE *);
+wint_t getwchar_unlocked (void);
+wint_t fputwc_unlocked (wchar_t, FILE *);
+wint_t putwc_unlocked (wchar_t, FILE *);
+wint_t putwchar_unlocked (wchar_t);
+wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict);
+int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict);
+size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t);
+#endif
+
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)  || defined(_BSD_SOURCE)
 FILE *open_wmemstream(wchar_t **, size_t *);
diff --git a/src/stdio/getwchar.c b/src/stdio/getwchar.c
index bd89e0e..77a9dc1 100644
--- a/src/stdio/getwchar.c
+++ b/src/stdio/getwchar.c
@@ -5,5 +5,3 @@ wint_t getwchar(void)
 {
 	return fgetwc(stdin);
 }
-
-weak_alias(getwchar, getwchar_unlocked);
diff --git a/src/stdio/getwchar_unlocked.c b/src/stdio/getwchar_unlocked.c
new file mode 100644
index 0000000..1d00567
--- /dev/null
+++ b/src/stdio/getwchar_unlocked.c
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include "stdio_impl.h"
+#include <wchar.h>
+
+wint_t getwchar_unlocked(void)
+{
+	return fgetwc_unlocked(stdin);
+}
diff --git a/src/stdio/putwchar.c b/src/stdio/putwchar.c
index b249c4a..7575384 100644
--- a/src/stdio/putwchar.c
+++ b/src/stdio/putwchar.c
@@ -5,5 +5,3 @@ wint_t putwchar(wchar_t c)
 {
 	return fputwc(c, stdout);
 }
-
-weak_alias(putwchar, putwchar_unlocked);
diff --git a/src/stdio/putwchar_unlocked.c b/src/stdio/putwchar_unlocked.c
new file mode 100644
index 0000000..6817f9e
--- /dev/null
+++ b/src/stdio/putwchar_unlocked.c
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include "stdio_impl.h"
+#include <wchar.h>
+
+wint_t putwchar_unlocked(wchar_t c)
+{
+	return fputwc_unlocked(c, stdout);
+}
-- 
2.10.0



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

* Re: [PATCH] add missing *_unlocked and wcsftime_l prototypes to wchar.h
  2016-09-06 21:09 ` Daniel Sabogal
@ 2016-09-09 23:02   ` Rich Felker
  2016-09-10  0:42     ` Daniel Sabogal
  0 siblings, 1 reply; 7+ messages in thread
From: Rich Felker @ 2016-09-09 23:02 UTC (permalink / raw)
  To: musl

On Tue, Sep 06, 2016 at 05:09:39PM -0400, Daniel Sabogal wrote:
> these functions had been implemented, but prototypes were not made available
> ---
>  include/wchar.h               | 12 ++++++++++++
>  src/stdio/getwchar.c          |  2 --
>  src/stdio/getwchar_unlocked.c |  8 ++++++++
>  src/stdio/putwchar.c          |  2 --
>  src/stdio/putwchar_unlocked.c |  8 ++++++++
>  5 files changed, 28 insertions(+), 4 deletions(-)
>  create mode 100644 src/stdio/getwchar_unlocked.c
>  create mode 100644 src/stdio/putwchar_unlocked.c
> 
> diff --git a/include/wchar.h b/include/wchar.h
> index 0167dce..58818f6 100644
> --- a/include/wchar.h
> +++ b/include/wchar.h
> @@ -136,6 +136,18 @@ size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const s
>  
>  #undef iswdigit
>  
> +#if defined(_GNU_SOURCE)
> +wint_t fgetwc_unlocked (FILE *);
> +wint_t getwc_unlocked (FILE *);
> +wint_t getwchar_unlocked (void);
> +wint_t fputwc_unlocked (wchar_t, FILE *);
> +wint_t putwc_unlocked (wchar_t, FILE *);
> +wint_t putwchar_unlocked (wchar_t);
> +wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict);
> +int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict);
> +size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t);
> +#endif

I suspect BSDs also had these so they should possibly be exposed under
_GNU_SOURCE || _BSD_SOURCE. Thoughts?

> diff --git a/src/stdio/getwchar.c b/src/stdio/getwchar.c
> index bd89e0e..77a9dc1 100644
> --- a/src/stdio/getwchar.c
> +++ b/src/stdio/getwchar.c
> @@ -5,5 +5,3 @@ wint_t getwchar(void)
>  {
>  	return fgetwc(stdin);
>  }
> -
> -weak_alias(getwchar, getwchar_unlocked);
> diff --git a/src/stdio/getwchar_unlocked.c b/src/stdio/getwchar_unlocked.c
> new file mode 100644
> index 0000000..1d00567
> --- /dev/null
> +++ b/src/stdio/getwchar_unlocked.c
> @@ -0,0 +1,8 @@
> +#define _GNU_SOURCE
> +#include "stdio_impl.h"
> +#include <wchar.h>
> +
> +wint_t getwchar_unlocked(void)
> +{
> +	return fgetwc_unlocked(stdin);
> +}

What is the motivation for replacing the aliases with wrappers? This
does not seem like an improvement.

Rich


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

* Re: [PATCH] add missing *_unlocked and wcsftime_l prototypes to wchar.h
  2016-09-09 23:02   ` Rich Felker
@ 2016-09-10  0:42     ` Daniel Sabogal
  2016-09-10  1:01       ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Sabogal @ 2016-09-10  0:42 UTC (permalink / raw)
  To: musl

On Fri, Sep 9, 2016 at 7:02 PM, Rich Felker <dalias@libc.org> wrote:
> On Tue, Sep 06, 2016 at 05:09:39PM -0400, Daniel Sabogal wrote:
>> these functions had been implemented, but prototypes were not made available
>> ---
>>  include/wchar.h               | 12 ++++++++++++
>>  src/stdio/getwchar.c          |  2 --
>>  src/stdio/getwchar_unlocked.c |  8 ++++++++
>>  src/stdio/putwchar.c          |  2 --
>>  src/stdio/putwchar_unlocked.c |  8 ++++++++
>>  5 files changed, 28 insertions(+), 4 deletions(-)
>>  create mode 100644 src/stdio/getwchar_unlocked.c
>>  create mode 100644 src/stdio/putwchar_unlocked.c
>>
>> diff --git a/include/wchar.h b/include/wchar.h
>> index 0167dce..58818f6 100644
>> --- a/include/wchar.h
>> +++ b/include/wchar.h
>> @@ -136,6 +136,18 @@ size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const s
>>
>>  #undef iswdigit
>>
>> +#if defined(_GNU_SOURCE)
>> +wint_t fgetwc_unlocked (FILE *);
>> +wint_t getwc_unlocked (FILE *);
>> +wint_t getwchar_unlocked (void);
>> +wint_t fputwc_unlocked (wchar_t, FILE *);
>> +wint_t putwc_unlocked (wchar_t, FILE *);
>> +wint_t putwchar_unlocked (wchar_t);
>> +wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict);
>> +int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict);
>> +size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t);
>> +#endif
>
> I suspect BSDs also had these so they should possibly be exposed under
> _GNU_SOURCE || _BSD_SOURCE. Thoughts?

Glibc doesn't provide any of these with _BSD_SOURCE.
FreeBSD and NetBSD provide wcsftime_l, but doesn't seem to have the
*_unlocked variants.
OpenBSD doesn't seem to provide either.

Perhaps wcsftime_l should be moved under _GNU_SOURCE || _BSD_SOURCE.

>> diff --git a/src/stdio/getwchar.c b/src/stdio/getwchar.c
>> index bd89e0e..77a9dc1 100644
>> --- a/src/stdio/getwchar.c
>> +++ b/src/stdio/getwchar.c
>> @@ -5,5 +5,3 @@ wint_t getwchar(void)
>>  {
>>       return fgetwc(stdin);
>>  }
>> -
>> -weak_alias(getwchar, getwchar_unlocked);
>> diff --git a/src/stdio/getwchar_unlocked.c b/src/stdio/getwchar_unlocked.c
>> new file mode 100644
>> index 0000000..1d00567
>> --- /dev/null
>> +++ b/src/stdio/getwchar_unlocked.c
>> @@ -0,0 +1,8 @@
>> +#define _GNU_SOURCE
>> +#include "stdio_impl.h"
>> +#include <wchar.h>
>> +
>> +wint_t getwchar_unlocked(void)
>> +{
>> +     return fgetwc_unlocked(stdin);
>> +}
>
> What is the motivation for replacing the aliases with wrappers? This
> does not seem like an improvement.
>
> Rich

Correct me if I'm wrong, but by using weak_alias(getwchar, getwchar_unlocked)
instead of the wrapper, wouldn't calls to getwchar_unlocked() really just invoke
getwchar() or fgetwc(stdin) instead of the intended fgetwc_unlocked(stdin)?


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

* Re: [PATCH] add missing *_unlocked and wcsftime_l prototypes to wchar.h
  2016-09-10  0:42     ` Daniel Sabogal
@ 2016-09-10  1:01       ` Rich Felker
  2016-09-10  1:23         ` Daniel Sabogal
  0 siblings, 1 reply; 7+ messages in thread
From: Rich Felker @ 2016-09-10  1:01 UTC (permalink / raw)
  To: musl

On Fri, Sep 09, 2016 at 08:42:45PM -0400, Daniel Sabogal wrote:
> On Fri, Sep 9, 2016 at 7:02 PM, Rich Felker <dalias@libc.org> wrote:
> > On Tue, Sep 06, 2016 at 05:09:39PM -0400, Daniel Sabogal wrote:
> >> these functions had been implemented, but prototypes were not made available
> >> ---
> >>  include/wchar.h               | 12 ++++++++++++
> >>  src/stdio/getwchar.c          |  2 --
> >>  src/stdio/getwchar_unlocked.c |  8 ++++++++
> >>  src/stdio/putwchar.c          |  2 --
> >>  src/stdio/putwchar_unlocked.c |  8 ++++++++
> >>  5 files changed, 28 insertions(+), 4 deletions(-)
> >>  create mode 100644 src/stdio/getwchar_unlocked.c
> >>  create mode 100644 src/stdio/putwchar_unlocked.c
> >>
> >> diff --git a/include/wchar.h b/include/wchar.h
> >> index 0167dce..58818f6 100644
> >> --- a/include/wchar.h
> >> +++ b/include/wchar.h
> >> @@ -136,6 +136,18 @@ size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const s
> >>
> >>  #undef iswdigit
> >>
> >> +#if defined(_GNU_SOURCE)
> >> +wint_t fgetwc_unlocked (FILE *);
> >> +wint_t getwc_unlocked (FILE *);
> >> +wint_t getwchar_unlocked (void);
> >> +wint_t fputwc_unlocked (wchar_t, FILE *);
> >> +wint_t putwc_unlocked (wchar_t, FILE *);
> >> +wint_t putwchar_unlocked (wchar_t);
> >> +wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict);
> >> +int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict);
> >> +size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t);
> >> +#endif
> >
> > I suspect BSDs also had these so they should possibly be exposed under
> > _GNU_SOURCE || _BSD_SOURCE. Thoughts?
> 
> Glibc doesn't provide any of these with _BSD_SOURCE.
> FreeBSD and NetBSD provide wcsftime_l, but doesn't seem to have the
> *_unlocked variants.
> OpenBSD doesn't seem to provide either.
> 
> Perhaps wcsftime_l should be moved under _GNU_SOURCE || _BSD_SOURCE.

OK.

> >> diff --git a/src/stdio/getwchar.c b/src/stdio/getwchar.c
> >> index bd89e0e..77a9dc1 100644
> >> --- a/src/stdio/getwchar.c
> >> +++ b/src/stdio/getwchar.c
> >> @@ -5,5 +5,3 @@ wint_t getwchar(void)
> >>  {
> >>       return fgetwc(stdin);
> >>  }
> >> -
> >> -weak_alias(getwchar, getwchar_unlocked);
> >> diff --git a/src/stdio/getwchar_unlocked.c b/src/stdio/getwchar_unlocked.c
> >> new file mode 100644
> >> index 0000000..1d00567
> >> --- /dev/null
> >> +++ b/src/stdio/getwchar_unlocked.c
> >> @@ -0,0 +1,8 @@
> >> +#define _GNU_SOURCE
> >> +#include "stdio_impl.h"
> >> +#include <wchar.h>
> >> +
> >> +wint_t getwchar_unlocked(void)
> >> +{
> >> +     return fgetwc_unlocked(stdin);
> >> +}
> >
> > What is the motivation for replacing the aliases with wrappers? This
> > does not seem like an improvement.
> 
> Correct me if I'm wrong, but by using weak_alias(getwchar, getwchar_unlocked)
> instead of the wrapper, wouldn't calls to getwchar_unlocked() really just invoke
> getwchar() or fgetwc(stdin) instead of the intended fgetwc_unlocked(stdin)?

As far as I can tell, the existence of a separate fgetwc_unlocked in
musl is just a historical accident due to its use in implementing
fgetws. It goes back to the initial git check-in and I didn't try to
dig up any older history.

In any case, trying to improve performance of these functions is
orthogonal to exposing declarations for them, so if done at all it
should be a separate commit. But I'd really like to avoid adding
"junk" functions where aliases already work, and get rid of some we
already have.

Rich


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

* [PATCH] add missing *_unlocked and wcsftime_l prototypes to wchar.h
  2016-09-10  1:01       ` Rich Felker
@ 2016-09-10  1:23         ` Daniel Sabogal
  2016-09-16 22:19           ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Sabogal @ 2016-09-10  1:23 UTC (permalink / raw)
  To: musl

these functions had been implemented, but prototypes were not made available
---
 include/wchar.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/wchar.h b/include/wchar.h
index 0167dce..3e6db5f 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -136,6 +136,21 @@ size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const s
 
 #undef iswdigit
 
+#if defined(_GNU_SOURCE)
+wint_t fgetwc_unlocked (FILE *);
+wint_t getwc_unlocked (FILE *);
+wint_t getwchar_unlocked (void);
+wint_t fputwc_unlocked (wchar_t, FILE *);
+wint_t putwc_unlocked (wchar_t, FILE *);
+wint_t putwchar_unlocked (wchar_t);
+wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict);
+int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict);
+#endif
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t);
+#endif
+
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)  || defined(_BSD_SOURCE)
 FILE *open_wmemstream(wchar_t **, size_t *);
-- 
2.10.0



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

* Re: [PATCH] add missing *_unlocked and wcsftime_l prototypes to wchar.h
  2016-09-10  1:23         ` Daniel Sabogal
@ 2016-09-16 22:19           ` Rich Felker
  0 siblings, 0 replies; 7+ messages in thread
From: Rich Felker @ 2016-09-16 22:19 UTC (permalink / raw)
  To: musl

On Fri, Sep 09, 2016 at 09:23:17PM -0400, Daniel Sabogal wrote:
> these functions had been implemented, but prototypes were not made available
> ---
>  include/wchar.h | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)

Committing. Thanks.

Rich


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

end of thread, other threads:[~2016-09-16 22:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-06 21:09 [PATCH] add missing *_unlocked and wcsftime_l prototypes to wchar.h Daniel Sabogal
2016-09-06 21:09 ` Daniel Sabogal
2016-09-09 23:02   ` Rich Felker
2016-09-10  0:42     ` Daniel Sabogal
2016-09-10  1:01       ` Rich Felker
2016-09-10  1:23         ` Daniel Sabogal
2016-09-16 22:19           ` Rich Felker

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).