Re: [PATCH 1/4] stdbit: new module

2024-05-12 Thread Paul Eggert

On 2024-05-12 11:43, Collin Funk wrote:

I have similar feelings about some stuff in gnulib-tool.py. We have
lines like this:

#
# Define GLImport class
#
class GLImport:


+1 on that. It's too close to the classic:

i = i + 1;  /* Add 1 to i.  */



Re: [PATCH 1/4] stdbit: new module

2024-05-12 Thread Collin Funk
On 5/12/24 8:23 AM, Paul Eggert wrote:
> Is this stuff documented somewhere in the .texi files? If not, I suppose it 
> should be.

I'm not sure. The only reason I noticed was because I was working on
endian.h and using stdbit as a template since my m4 talents are lacking...

> Frankly I continue to be annoyed by having to read and write a line "# 
> FILENAME.m4" at the start of every m4 file FILENAME.m4. It's better for a 
> file's first line to be a human-readable comment explaining what the file is 
> for. Any automated procedure already knows the file name, so why do we need 
> to put the name there manually, an error-prone process?

I have similar feelings about some stuff in gnulib-tool.py. We have
lines like this:

#
# Define GLImport class
#
class GLImport:
  

But when searching for a class in Python you can simply look up
'^class NAME:' since whitespace matters in that language. No need for
the comment in my opinion.

Collin



Re: [PATCH 1/4] stdbit: new module

2024-05-12 Thread Paul Eggert

On 2024-05-11 23:48, Collin Funk wrote:

+# stddef_h.m4
+# serial 1

I see that you use my method of making sure files have license
headers, just copying another file. :)


Thanks, I fixed that.

Is this stuff documented somewhere in the .texi files? If not, I suppose 
it should be.


Frankly I continue to be annoyed by having to read and write a line "# 
FILENAME.m4" at the start of every m4 file FILENAME.m4. It's better for 
a file's first line to be a human-readable comment explaining what the 
file is for. Any automated procedure already knows the file name, so why 
do we need to put the name there manually, an error-prone process?




Re: [PATCH 1/4] stdbit: new module

2024-05-12 Thread Collin Funk
Hi Paul,

On 5/11/24 12:08 PM, Paul Eggert wrote:
> diff --git a/m4/stdbit_h.m4 b/m4/stdbit_h.m4
> new file mode 100644
> index 00..9ce3cb3146
> --- /dev/null
> +++ b/m4/stdbit_h.m4
> @@ -0,0 +1,19 @@
> +# stddef_h.m4
> +# serial 1

I see that you use my method of making sure files have license
headers, just copying another file. :)

Referring to the '# stddef_h.m4' comment.

Collin



[PATCH 1/4] stdbit: new module

2024-05-11 Thread Paul Eggert
* doc/gnulib-tool.texi, doc/gnulib.texi: Mention it.
* doc/posix-headers/stdbit.texi, lib/stdbit.c, lib/stdbit.in.h:
* m4/stdbit_h.m4, modules/stdbit:
New files.
---
 ChangeLog |   8 +
 doc/gnulib-tool.texi  |   1 +
 doc/gnulib.texi   |   2 +
 doc/posix-headers/stdbit.texi |  25 ++
 lib/stdbit.c  |   3 +
 lib/stdbit.in.h   | 640 ++
 m4/stdbit_h.m4|  19 +
 modules/stdbit|  44 +++
 8 files changed, 742 insertions(+)
 create mode 100644 doc/posix-headers/stdbit.texi
 create mode 100644 lib/stdbit.c
 create mode 100644 lib/stdbit.in.h
 create mode 100644 m4/stdbit_h.m4
 create mode 100644 modules/stdbit

diff --git a/ChangeLog b/ChangeLog
index da40ff41de..1019917f36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-05-11  Paul Eggert  
+
+   stdbit: new module
+   * doc/gnulib-tool.texi, doc/gnulib.texi: Mention it.
+   * doc/posix-headers/stdbit.texi, lib/stdbit.c, lib/stdbit.in.h:
+   * m4/stdbit_h.m4, modules/stdbit:
+   New files.
+
 2024-05-11  Bruno Haible  
 
doc: Mention module execinfo.
diff --git a/doc/gnulib-tool.texi b/doc/gnulib-tool.texi
index 9ed30c2055..5a2fd19cac 100644
--- a/doc/gnulib-tool.texi
+++ b/doc/gnulib-tool.texi
@@ -585,6 +585,7 @@ This is true for the following POSIX or ISO C standardized 
header files:
 @item @code{spawn.h}
 @item @code{stdalign.h}
 @item @code{stdarg.h}
+@item @code{stdbit.h}
 @item @code{stddef.h}
 @item @code{stdint.h}
 @item @code{stdio.h}
diff --git a/doc/gnulib.texi b/doc/gnulib.texi
index 55cf6ebcc9..6cbd10619e 100644
--- a/doc/gnulib.texi
+++ b/doc/gnulib.texi
@@ -1082,6 +1082,7 @@ which (known) portability problems are not worked around 
by Gnulib.
 * stdalign.h::
 * stdarg.h::
 * stdatomic.h::
+* stdbit.h::
 * stdbool.h::
 * stdckdint.h::
 * stddef.h::
@@ -1174,6 +1175,7 @@ which (known) portability problems are not worked around 
by Gnulib.
 @include posix-headers/stdalign.texi
 @include posix-headers/stdarg.texi
 @include posix-headers/stdatomic.texi
+@include posix-headers/stdbit.texi
 @include posix-headers/stdbool.texi
 @include posix-headers/stdckdint.texi
 @include posix-headers/stddef.texi
diff --git a/doc/posix-headers/stdbit.texi b/doc/posix-headers/stdbit.texi
new file mode 100644
index 00..8870668a59
--- /dev/null
+++ b/doc/posix-headers/stdbit.texi
@@ -0,0 +1,25 @@
+@node stdbit.h
+@section @file{stdbit.h}
+
+Gnulib module: stdbit
+
+Portability problems fixed by Gnulib:
+@itemize
+@item
+This header file is missing on many non-C23 platforms:
+glibc 2.38, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5,
+AIX 7.3, HP-UX 11.31, Solaris 11.4, mingw, MSVC 17, Android 15.
+@end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+@item
+On older non-C23 platforms lacking @code{typeof} or equivalent, a call
+to @code{stdc_bit_floor} and @code{stdc_bit_ceil} may yield a type
+that is wider than its argument.  Although C23 seems to allow this,
+it differs from GNU behavior.
+
+@item
+On non-C23 platforms, type-generic functions apply portably only to
+the standard unsigned integer types specified by C17 or earlier.
+@end itemize
diff --git a/lib/stdbit.c b/lib/stdbit.c
new file mode 100644
index 00..0346ec095c
--- /dev/null
+++ b/lib/stdbit.c
@@ -0,0 +1,3 @@
+#include 
+#define _GL_STDBIT_INLINE _GL_EXTERN_INLINE
+#include 
diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h
new file mode 100644
index 00..a2fff04772
--- /dev/null
+++ b/lib/stdbit.in.h
@@ -0,0 +1,640 @@
+/* stdbit.h - C23 bit and byte utilities for non-C23 platforms
+
+   Copyright 2024 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This file is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see .  */
+
+/* Written by Paul Eggert.  */
+
+#ifndef STDBIT_H
+#define STDBIT_H 1
+
+/* This file uses _GL_INLINE, WORDS_BIGENDIAN.  */
+#if !_GL_CONFIG_H_INCLUDED
+ #error "Please include config.h first."
+#endif
+
+#include 
+#include 
+#include 
+
+/* An expression, preferably with the type of A, that has the value of B.  */
+#if ((defined __GNUC__ && 2 <= __GNUC__) \
+ || (defined __clang_major__ && 4 <= __clang_major__) \
+ || (defined __IBMC__ && 1210 <= __IBMC__ && defined __IBM__TYPEOF__) \
+ || (defined __SUNPRO_C && 0x5110 <= __SUNPRO_C && !__STDC__))
+# define _GL_STDBIT_TYPEOF_CAST(a, b)