public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [Bug?] SIG2STR_MAX not good for #if
@ 2023-06-19  6:15 Mingye Wang
  2023-06-19  9:00 ` Corinna Vinschen
  0 siblings, 1 reply; 9+ messages in thread
From: Mingye Wang @ 2023-06-19  6:15 UTC (permalink / raw)
  To: newlib

When building schilytools on MSYS2, I got hit with:

```
defs.h:1288:21: error: missing binary operator before token "("
 1288 | #if     NUMBUFLEN < SIG2STR_MAX
```

For context, the source goes:

```
#define     NUMBUFLEN   21  /* big enough for 64 bits */
#if NUMBUFLEN < SIG2STR_MAX
#undef      NUMBUFLEN
#define     NUMBUFLEN   (SIG2STR_MAX-1)
#endif
```

A cursory inspection of /usr/include leads me to this "#define
SIG2STR_MAX (sizeof("RTMAX+") + sizeof("4294967295") - 1)" definition;
redefining it with a plain number makes the build go through. Looking
up the newlib source code, it appears that the definition is not
specific to MSYS2 or Cygwin, but common to all newlib distributions.

The wording proposed for SIG2STR_MAX by geoffclare in comment 4975[1]
under the POSIX issue 8 bug report requires that the definition is
suitable for #if, which newlib currently violates. Now this isn't
quite standard yet and is subject to change, so I can't say for sure
this is newlib's bug.

  [1]: https://www.austingroupbugs.net/view.php?id=1138#c4975

Regards,
Mingye Wang (Artoria2e5)

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

* Re: [Bug?] SIG2STR_MAX not good for #if
  2023-06-19  6:15 [Bug?] SIG2STR_MAX not good for #if Mingye Wang
@ 2023-06-19  9:00 ` Corinna Vinschen
  2023-06-19 11:11   ` Joel Sherrill
  2023-06-21  1:22   ` [PATCH] Make SIG2STR_MAX usable in #if Mingye Wang
  0 siblings, 2 replies; 9+ messages in thread
From: Corinna Vinschen @ 2023-06-19  9:00 UTC (permalink / raw)
  To: Mingye Wang; +Cc: newlib

On Jun 19 14:15, Mingye Wang wrote:
> When building schilytools on MSYS2, I got hit with:
> 
> ```
> defs.h:1288:21: error: missing binary operator before token "("
>  1288 | #if     NUMBUFLEN < SIG2STR_MAX
> ```
> 
> For context, the source goes:
> 
> ```
> #define     NUMBUFLEN   21  /* big enough for 64 bits */
> #if NUMBUFLEN < SIG2STR_MAX
> #undef      NUMBUFLEN
> #define     NUMBUFLEN   (SIG2STR_MAX-1)
> #endif
> ```
> 
> A cursory inspection of /usr/include leads me to this "#define
> SIG2STR_MAX (sizeof("RTMAX+") + sizeof("4294967295") - 1)" definition;
> redefining it with a plain number makes the build go through. Looking
> up the newlib source code, it appears that the definition is not
> specific to MSYS2 or Cygwin, but common to all newlib distributions.
> 
> The wording proposed for SIG2STR_MAX by geoffclare in comment 4975[1]
> under the POSIX issue 8 bug report requires that the definition is
> suitable for #if, which newlib currently violates. Now this isn't
> quite standard yet and is subject to change, so I can't say for sure
> this is newlib's bug.
> 
>   [1]: https://www.austingroupbugs.net/view.php?id=1138#c4975

We could redefine SIG2STR_MAX as static values (still dependent on
__SIZEOF_INT__) and prepend the sizeof expressions as comments.

Do you want to provide a patch?


Thanks,
Corinna


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

* Re: [Bug?] SIG2STR_MAX not good for #if
  2023-06-19  9:00 ` Corinna Vinschen
@ 2023-06-19 11:11   ` Joel Sherrill
  2023-06-21  1:08     ` Mingye Wang
  2023-06-21  1:22   ` [PATCH] Make SIG2STR_MAX usable in #if Mingye Wang
  1 sibling, 1 reply; 9+ messages in thread
From: Joel Sherrill @ 2023-06-19 11:11 UTC (permalink / raw)
  To: Newlib, Mingye Wang

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

On Mon, Jun 19, 2023, 4:00 AM Corinna Vinschen <vinschen@redhat.com> wrote:

> On Jun 19 14:15, Mingye Wang wrote:
> > When building schilytools on MSYS2, I got hit with:
> >
> > ```
> > defs.h:1288:21: error: missing binary operator before token "("
> >  1288 | #if     NUMBUFLEN < SIG2STR_MAX
> > ```
> >
> > For context, the source goes:
> >
> > ```
> > #define     NUMBUFLEN   21  /* big enough for 64 bits */
> > #if NUMBUFLEN < SIG2STR_MAX
> > #undef      NUMBUFLEN
> > #define     NUMBUFLEN   (SIG2STR_MAX-1)
> > #endif
> > ```
> >
> > A cursory inspection of /usr/include leads me to this "#define
> > SIG2STR_MAX (sizeof("RTMAX+") + sizeof("4294967295") - 1)" definition;
> > redefining it with a plain number makes the build go through. Looking
> > up the newlib source code, it appears that the definition is not
> > specific to MSYS2 or Cygwin, but common to all newlib distributions.
> >
> > The wording proposed for SIG2STR_MAX by geoffclare in comment 4975[1]
> > under the POSIX issue 8 bug report requires that the definition is
> > suitable for #if, which newlib currently violates. Now this isn't
> > quite standard yet and is subject to change, so I can't say for sure
> > this is newlib's bug.
> >
> >   [1]: https://www.austingroupbugs.net/view.php?id=1138#c4975
>
> We could redefine SIG2STR_MAX as static values (still dependent on
> __SIZEOF_INT__) and prepend the sizeof expressions as comments.
>

FWIW This appears to be a common extension and ere does not appear in the
POSIX standard.

Given that, it should be compatible with glibc

--joel

>
> Do you want to provide a patch?
>
>
> Thanks,
> Corinna
>
>

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

* Re: [Bug?] SIG2STR_MAX not good for #if
  2023-06-19 11:11   ` Joel Sherrill
@ 2023-06-21  1:08     ` Mingye Wang
  0 siblings, 0 replies; 9+ messages in thread
From: Mingye Wang @ 2023-06-21  1:08 UTC (permalink / raw)
  To: joel; +Cc: Newlib

On Mon, Jun 19, 2023 at 7:12 PM Joel Sherrill <joel@rtems.org> wrote:
>
> FWIW This appears to be a common extension and ere does not appear in the POSIX standard.
>
> Given that, it should be compatible with glibc

It's part of the proposed standard per link [1] of original message.
It's already been put into the branch for the next issue per its last
comment.

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

* [PATCH] Make SIG2STR_MAX usable in #if
  2023-06-19  9:00 ` Corinna Vinschen
  2023-06-19 11:11   ` Joel Sherrill
@ 2023-06-21  1:22   ` Mingye Wang
  2023-06-21  7:33     ` Torbjorn SVENSSON
  1 sibling, 1 reply; 9+ messages in thread
From: Mingye Wang @ 2023-06-21  1:22 UTC (permalink / raw)
  To: Newlib, Mingye Wang

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

On Mon, Jun 19, 2023 at 5:00 PM Corinna Vinschen <vinschen@redhat.com> wrote:
>
> We could redefine SIG2STR_MAX as static values (still dependent on
> __SIZEOF_INT__) and prepend the sizeof expressions as comments.
>
> Do you want to provide a patch?

I guess? See the attached file for an attempt.

Uh, what license am I supposed to say I am releasing this patch under?

Sincerely,
Mingye

[-- Attachment #2: 0802d3650565f4192a931beb9676276480df8fb3.patch.txt --]
[-- Type: text/plain, Size: 1106 bytes --]

From 0802d3650565f4192a931beb9676276480df8fb3 Mon Sep 17 00:00:00 2001
From: Mingye Wang <arthur200126@gmail.com>
Date: Wed, 21 Jun 2023 09:16:06 +0800
Subject: [PATCH] Make SIG2STR_MAX usable in #if

The language accepted for POSIX issue 8 requires that SIG2STR_MAX be usable in #if, which we currently break with sizeof. Use static values instead.
---
 newlib/libc/include/sys/signal.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/include/sys/signal.h b/newlib/libc/include/sys/signal.h
index 8dc5fb9c34..18fee63691 100644
--- a/newlib/libc/include/sys/signal.h
+++ b/newlib/libc/include/sys/signal.h
@@ -245,9 +245,9 @@ int sigqueue (pid_t, int, const union sigval);
 /* POSIX Issue 8 adds sig2str() and str2sig() */
 
 #if __SIZEOF_INT__ >= 4
-#define SIG2STR_MAX (sizeof("RTMAX+") + sizeof("4294967295") - 1)
+#define SIG2STR_MAX 21	/* (sizeof("RTMAX+") + sizeof("4294967295") - 1) */
 #else
-#define SIG2STR_MAX (sizeof("RTMAX+") + sizeof("65535") - 1)
+#define SIG2STR_MAX 17	/* (sizeof("RTMAX+") + sizeof("65535") - 1) */
 #endif
 
 int sig2str(int, char *);

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

* Re: [PATCH] Make SIG2STR_MAX usable in #if
  2023-06-21  1:22   ` [PATCH] Make SIG2STR_MAX usable in #if Mingye Wang
@ 2023-06-21  7:33     ` Torbjorn SVENSSON
  2023-06-21  9:13       ` Corinna Vinschen
  0 siblings, 1 reply; 9+ messages in thread
From: Torbjorn SVENSSON @ 2023-06-21  7:33 UTC (permalink / raw)
  To: newlib


  #if __SIZEOF_INT__ >= 4
-#define SIG2STR_MAX (sizeof("RTMAX+") + sizeof("4294967295") - 1)
+#define SIG2STR_MAX 21	/* (sizeof("RTMAX+") + sizeof("4294967295") - 1) */
  #else
-#define SIG2STR_MAX (sizeof("RTMAX+") + sizeof("65535") - 1)
+#define SIG2STR_MAX 17	/* (sizeof("RTMAX+") + sizeof("65535") - 1) */
  #endif


I have not read the specification, but how come it's 17 and 21?

 From what I can tell, "RTMAX+65535" is not 4 shorter than "RTMAX+4294967295".

Kind regards,
Torbjörn

On 2023-06-21 03:22, Mingye Wang wrote:
> On Mon, Jun 19, 2023 at 5:00 PM Corinna Vinschen <vinschen@redhat.com> wrote:
>>
>> We could redefine SIG2STR_MAX as static values (still dependent on
>> __SIZEOF_INT__) and prepend the sizeof expressions as comments.
>>
>> Do you want to provide a patch?
> 
> I guess? See the attached file for an attempt.
> 
> Uh, what license am I supposed to say I am releasing this patch under?
> 
> Sincerely,
> Mingye

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

* Re: [PATCH] Make SIG2STR_MAX usable in #if
  2023-06-21  7:33     ` Torbjorn SVENSSON
@ 2023-06-21  9:13       ` Corinna Vinschen
  2023-06-21 12:13         ` [PATCHv2] " Mingye Wang
  0 siblings, 1 reply; 9+ messages in thread
From: Corinna Vinschen @ 2023-06-21  9:13 UTC (permalink / raw)
  To: Torbjorn SVENSSON; +Cc: Mingye Wang, newlib

On Jun 21 09:33, Torbjorn SVENSSON wrote:
> 
>  #if __SIZEOF_INT__ >= 4
> -#define SIG2STR_MAX (sizeof("RTMAX+") + sizeof("4294967295") - 1)
> +#define SIG2STR_MAX 21	/* (sizeof("RTMAX+") + sizeof("4294967295") - 1) */
>  #else
> -#define SIG2STR_MAX (sizeof("RTMAX+") + sizeof("65535") - 1)
> +#define SIG2STR_MAX 17	/* (sizeof("RTMAX+") + sizeof("65535") - 1) */
>  #endif
> 
> 
> I have not read the specification, but how come it's 17 and 21?
> 
> From what I can tell, "RTMAX+65535" is not 4 shorter than "RTMAX+4294967295".

That should be 7 + 11 - 1 = 17 and 7 + 6 - 1 = 12, shouldn't it?


Corinna


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

* [PATCHv2] Make SIG2STR_MAX usable in #if
  2023-06-21  9:13       ` Corinna Vinschen
@ 2023-06-21 12:13         ` Mingye Wang
  2023-06-21 13:20           ` Corinna Vinschen
  0 siblings, 1 reply; 9+ messages in thread
From: Mingye Wang @ 2023-06-21 12:13 UTC (permalink / raw)
  To: Newlib, Torbjorn SVENSSON, Mingye Wang

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

> That should be 7 + 11 - 1 = 17 and 7 + 6 - 1 = 12, shouldn't it?

Yep, it should be. Misread my terminal output and wondered for a bit
why the second one is longer than the first. Should have thought about
double-checking.

[-- Attachment #2: bccdc7d72cc1ea8a0d2aa04acf86e0afd2a3d6b5.patch.txt --]
[-- Type: text/plain, Size: 1102 bytes --]

From bccdc7d72cc1ea8a0d2aa04acf86e0afd2a3d6b5 Mon Sep 17 00:00:00 2001
From: Mingye Wang <arthur200126@gmail.com>
Date: Wed, 21 Jun 2023 20:11:57 +0800
Subject: [PATCH] Make SIG2STR_MAX usable in #if

The text accepted for POSIX issue 8 requires that SIG2STR_MAX be usable
in #if, which we currently break with sizeof. Use static values instead.
---
 newlib/libc/include/sys/signal.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/include/sys/signal.h b/newlib/libc/include/sys/signal.h
index 8dc5fb9c34..96bf9781ae 100644
--- a/newlib/libc/include/sys/signal.h
+++ b/newlib/libc/include/sys/signal.h
@@ -245,9 +245,9 @@ int sigqueue (pid_t, int, const union sigval);
 /* POSIX Issue 8 adds sig2str() and str2sig() */
 
 #if __SIZEOF_INT__ >= 4
-#define SIG2STR_MAX (sizeof("RTMAX+") + sizeof("4294967295") - 1)
+#define SIG2STR_MAX 17	/* (sizeof("RTMAX+") + sizeof("4294967295") - 1) */
 #else
-#define SIG2STR_MAX (sizeof("RTMAX+") + sizeof("65535") - 1)
+#define SIG2STR_MAX 12	/* (sizeof("RTMAX+") + sizeof("65535") - 1) */
 #endif
 
 int sig2str(int, char *);

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

* Re: [PATCHv2] Make SIG2STR_MAX usable in #if
  2023-06-21 12:13         ` [PATCHv2] " Mingye Wang
@ 2023-06-21 13:20           ` Corinna Vinschen
  0 siblings, 0 replies; 9+ messages in thread
From: Corinna Vinschen @ 2023-06-21 13:20 UTC (permalink / raw)
  To: Mingye Wang; +Cc: Newlib, Torbjorn SVENSSON

On Jun 21 20:13, Mingye Wang wrote:
> > That should be 7 + 11 - 1 = 17 and 7 + 6 - 1 = 12, shouldn't it?
> 
> Yep, it should be. Misread my terminal output and wondered for a bit
> why the second one is longer than the first. Should have thought about
> double-checking.

> From bccdc7d72cc1ea8a0d2aa04acf86e0afd2a3d6b5 Mon Sep 17 00:00:00 2001
> From: Mingye Wang <arthur200126@gmail.com>
> Date: Wed, 21 Jun 2023 20:11:57 +0800
> Subject: [PATCH] Make SIG2STR_MAX usable in #if
> 
> The text accepted for POSIX issue 8 requires that SIG2STR_MAX be usable
> in #if, which we currently break with sizeof. Use static values instead.
> ---
>  newlib/libc/include/sys/signal.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/newlib/libc/include/sys/signal.h b/newlib/libc/include/sys/signal.h
> index 8dc5fb9c34..96bf9781ae 100644
> --- a/newlib/libc/include/sys/signal.h
> +++ b/newlib/libc/include/sys/signal.h
> @@ -245,9 +245,9 @@ int sigqueue (pid_t, int, const union sigval);
>  /* POSIX Issue 8 adds sig2str() and str2sig() */
>  
>  #if __SIZEOF_INT__ >= 4
> -#define SIG2STR_MAX (sizeof("RTMAX+") + sizeof("4294967295") - 1)
> +#define SIG2STR_MAX 17	/* (sizeof("RTMAX+") + sizeof("4294967295") - 1) */
>  #else
> -#define SIG2STR_MAX (sizeof("RTMAX+") + sizeof("65535") - 1)
> +#define SIG2STR_MAX 12	/* (sizeof("RTMAX+") + sizeof("65535") - 1) */
>  #endif
>  
>  int sig2str(int, char *);

Pushed.


Thanks,
Corinna


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

end of thread, other threads:[~2023-06-21 13:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-19  6:15 [Bug?] SIG2STR_MAX not good for #if Mingye Wang
2023-06-19  9:00 ` Corinna Vinschen
2023-06-19 11:11   ` Joel Sherrill
2023-06-21  1:08     ` Mingye Wang
2023-06-21  1:22   ` [PATCH] Make SIG2STR_MAX usable in #if Mingye Wang
2023-06-21  7:33     ` Torbjorn SVENSSON
2023-06-21  9:13       ` Corinna Vinschen
2023-06-21 12:13         ` [PATCHv2] " Mingye Wang
2023-06-21 13:20           ` Corinna Vinschen

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 read-only IMAP folder(s) and NNTP newsgroup(s).