public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] build: Avoid length() GNU awk extension
@ 2022-03-09  7:31 Sebastian Huber
  2022-03-09  8:26 ` Corinna Vinschen
  2022-03-09  8:54 ` Mike Frysinger
  0 siblings, 2 replies; 6+ messages in thread
From: Sebastian Huber @ 2022-03-09  7:31 UTC (permalink / raw)
  To: newlib

Other awk implementations such as mawk do not support the length() function.
---
 newlib/Makefile.am | 4 ++--
 newlib/Makefile.in | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/newlib/Makefile.am b/newlib/Makefile.am
index ba0a3822f..81719660c 100644
--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -93,8 +93,8 @@ CLEANFILES += libg.a
 ## https://sourceware.org/PR28917
 AWK_UNIQUE_OBJS = $(AWK) '{ \
   for (i = NF; i > 0; --i) { \
-    split($$i, parts, "/"); \
-    name = parts[length(parts)]; \
+    count = split($$i, parts, "/"); \
+    name = parts[count]; \
     if (!(name in seen)) { \
       objs[i] = $$i; \
       seen[name] = 1; \
diff --git a/newlib/Makefile.in b/newlib/Makefile.in
index e0deacb61..7de777879 100644
--- a/newlib/Makefile.in
+++ b/newlib/Makefile.in
@@ -1380,8 +1380,8 @@ toollib_LIBRARIES = libm.a \
 toollib_DATA = $(CRT0) $(CRT1)
 AWK_UNIQUE_OBJS = $(AWK) '{ \
   for (i = NF; i > 0; --i) { \
-    split($$i, parts, "/"); \
-    name = parts[length(parts)]; \
+    count = split($$i, parts, "/"); \
+    name = parts[count]; \
     if (!(name in seen)) { \
       objs[i] = $$i; \
       seen[name] = 1; \
-- 
2.34.1


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

* Re: [PATCH] build: Avoid length() GNU awk extension
  2022-03-09  7:31 [PATCH] build: Avoid length() GNU awk extension Sebastian Huber
@ 2022-03-09  8:26 ` Corinna Vinschen
  2022-03-09  8:54 ` Mike Frysinger
  1 sibling, 0 replies; 6+ messages in thread
From: Corinna Vinschen @ 2022-03-09  8:26 UTC (permalink / raw)
  To: newlib

On Mar  9 08:31, Sebastian Huber wrote:
> Other awk implementations such as mawk do not support the length() function.
> ---
>  newlib/Makefile.am | 4 ++--
>  newlib/Makefile.in | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/newlib/Makefile.am b/newlib/Makefile.am
> index ba0a3822f..81719660c 100644
> --- a/newlib/Makefile.am
> +++ b/newlib/Makefile.am
> @@ -93,8 +93,8 @@ CLEANFILES += libg.a
>  ## https://sourceware.org/PR28917
>  AWK_UNIQUE_OBJS = $(AWK) '{ \
>    for (i = NF; i > 0; --i) { \
> -    split($$i, parts, "/"); \
> -    name = parts[length(parts)]; \
> +    count = split($$i, parts, "/"); \
> +    name = parts[count]; \
>      if (!(name in seen)) { \
>        objs[i] = $$i; \
>        seen[name] = 1; \
> diff --git a/newlib/Makefile.in b/newlib/Makefile.in
> index e0deacb61..7de777879 100644
> --- a/newlib/Makefile.in
> +++ b/newlib/Makefile.in
> @@ -1380,8 +1380,8 @@ toollib_LIBRARIES = libm.a \
>  toollib_DATA = $(CRT0) $(CRT1)
>  AWK_UNIQUE_OBJS = $(AWK) '{ \
>    for (i = NF; i > 0; --i) { \
> -    split($$i, parts, "/"); \
> -    name = parts[length(parts)]; \
> +    count = split($$i, parts, "/"); \
> +    name = parts[count]; \
>      if (!(name in seen)) { \
>        objs[i] = $$i; \
>        seen[name] = 1; \
> -- 
> 2.34.1

LGTM

Thanks,
Corinna


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

* Re: [PATCH] build: Avoid length() GNU awk extension
  2022-03-09  7:31 [PATCH] build: Avoid length() GNU awk extension Sebastian Huber
  2022-03-09  8:26 ` Corinna Vinschen
@ 2022-03-09  8:54 ` Mike Frysinger
  2022-03-09  9:02   ` Sebastian Huber
  2022-03-09  9:10   ` Mike Frysinger
  1 sibling, 2 replies; 6+ messages in thread
From: Mike Frysinger @ 2022-03-09  8:54 UTC (permalink / raw)
  To: Sebastian Huber; +Cc: newlib

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

On 09 Mar 2022 08:31, Sebastian Huber wrote:
> Other awk implementations such as mawk do not support the length() function.

those awk implementations are not POSIX compliant.  length() is
*not* a GNU extension.  you can see it clearly defined in POSIX:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html#tag_20_06_13_13

that said, mawk does support length(), and has since at least 2008 in
the 1.3.3 release.  i stopped looking back further in the history.

so you're going to have to provide a bit more info as to what you're
trying to do here, and what tools & versions exactly you're using.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] build: Avoid length() GNU awk extension
  2022-03-09  8:54 ` Mike Frysinger
@ 2022-03-09  9:02   ` Sebastian Huber
  2022-03-09  9:10   ` Mike Frysinger
  1 sibling, 0 replies; 6+ messages in thread
From: Sebastian Huber @ 2022-03-09  9:02 UTC (permalink / raw)
  To: newlib

On 09/03/2022 09:54, Mike Frysinger wrote:
> On 09 Mar 2022 08:31, Sebastian Huber wrote:
>> Other awk implementations such as mawk do not support the length() function.
> those awk implementations are not POSIX compliant.  length() is
> *not*  a GNU extension.  you can see it clearly defined in POSIX:
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html#tag_20_06_13_13

Ok, it is defined by POSIX, I will adjust the commit message.

> 
> that said, mawk does support length(), and has since at least 2008 in
> the 1.3.3 release.  i stopped looking back further in the history.
> 
> so you're going to have to provide a bit more info as to what you're
> trying to do here, and what tools & versions exactly you're using.

I received an error report from someone else which regularly builds 
Newlib and this use of awk broke the build. I don't know the exact 
version of mawk which was used.

Independent of the POSIX compliance of the existing code I think the 
change to use the return value of split() doesn't hurt?

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

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

* Re: [PATCH] build: Avoid length() GNU awk extension
  2022-03-09  8:54 ` Mike Frysinger
  2022-03-09  9:02   ` Sebastian Huber
@ 2022-03-09  9:10   ` Mike Frysinger
  2022-03-09 10:03     ` Mike Frysinger
  1 sibling, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2022-03-09  9:10 UTC (permalink / raw)
  To: Sebastian Huber, newlib

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

On 09 Mar 2022 03:54, Mike Frysinger wrote:
> On 09 Mar 2022 08:31, Sebastian Huber wrote:
> > Other awk implementations such as mawk do not support the length() function.
> 
> those awk implementations are not POSIX compliant.  length() is
> *not* a GNU extension.  you can see it clearly defined in POSIX:
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html#tag_20_06_13_13

sorry, i quoted length() as used to count bytes in a string, not elements
in an array.  POSIX doesn't support that.  i would still argue that, while
gawk supports it, it isn't a GNU extension.  bwk supported it back in 2002,
and gawk didn't implement it until ~2005.

> that said, mawk does support length(), and has since at least 2008 in
> the 1.3.3 release.  i stopped looking back further in the history.

the original mawk has been dead for over a decade.  i hope you're not trying
to use such vintage tools.  Thomas E. Dickey picked up maintenance and has
produced a series of fixes & improvements, and every distro i'm aware of is
using his fork.
https://invisible-island.net/mawk/

i mention this because he implemented length() to count array elements back
in 2012.  so if you still haven't updated to a version that supports that,
you should really get on top of that.

all that said, the patch you propose is a simple alternative that is POSIX
compliant, so i'm fine with it too.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] build: Avoid length() GNU awk extension
  2022-03-09  9:10   ` Mike Frysinger
@ 2022-03-09 10:03     ` Mike Frysinger
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2022-03-09 10:03 UTC (permalink / raw)
  To: Sebastian Huber, newlib

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

On 09 Mar 2022 04:10, Mike Frysinger wrote:
> On 09 Mar 2022 03:54, Mike Frysinger wrote:
> > On 09 Mar 2022 08:31, Sebastian Huber wrote:
> > > Other awk implementations such as mawk do not support the length() function.
> > 
> > those awk implementations are not POSIX compliant.  length() is
> > *not* a GNU extension.  you can see it clearly defined in POSIX:
> > https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html#tag_20_06_13_13
> 
> sorry, i quoted length() as used to count bytes in a string, not elements
> in an array.  POSIX doesn't support that.  i would still argue that, while
> gawk supports it, it isn't a GNU extension.  bwk supported it back in 2002,
> and gawk didn't implement it until ~2005.

since it's widely supported for a long time, i sent a request to the POSIX
folks to just add it :)
https://www.austingroupbugs.net/view.php?id=1566
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2022-03-09 10:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09  7:31 [PATCH] build: Avoid length() GNU awk extension Sebastian Huber
2022-03-09  8:26 ` Corinna Vinschen
2022-03-09  8:54 ` Mike Frysinger
2022-03-09  9:02   ` Sebastian Huber
2022-03-09  9:10   ` Mike Frysinger
2022-03-09 10:03     ` Mike Frysinger

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