bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* new modules for libunistring metadata
@ 2024-02-21  0:15 Bruno Haible
  2024-02-21  1:12 ` Collin Funk
  0 siblings, 1 reply; 4+ messages in thread
From: Bruno Haible @ 2024-02-21  0:15 UTC (permalink / raw)
  To: bug-gnulib

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

The next version of GNU libunistring will define more metadata.
Suggested by Roger Crew <wrog@wrog.net> in
<https://lists.gnu.org/archive/html/bug-libunistring/2023-08/msg00000.html>.

If this metadata is maintained in libunistring, it has to be updated each
time we upgrade to a new Unicode version, in the future.

It's better if this metadata is generated from gen-uni-tables.c. This
eliminates a manual step. These patches do it.


2024-02-20  Bruno Haible  <bruno@clisp.org>

	unimetadata/u-version: Add tests.
	* tests/unimetadata/test-u-version.c: New file.
	* modules/unimetadata/u-version-tests: New file.

	unimetadata/u-version: New module.
	* lib/gen-uni-tables.c (output_version): New function.
	(main): Invoke it.
	* lib/unimetadata/u-version.c: New generated file.
	* modules/unimetadata/u-version: New file.

	unimetadata/base: New module.
	* lib/unimetadata.in.h: New file.
	* m4/unimetadata_h.m4: New file.
	* modules/unimetadata/base: New file.


[-- Attachment #2: 0001-unimetadata-base-New-module.patch --]
[-- Type: text/x-patch, Size: 5473 bytes --]

From cdd837506712821361ee0910c3ace675b1f77c85 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 21 Feb 2024 00:53:41 +0100
Subject: [PATCH 1/3] unimetadata/base: New module.

* lib/unimetadata.in.h: New file.
* m4/unimetadata_h.m4: New file.
* modules/unimetadata/base: New file.
---
 ChangeLog                |  7 +++++++
 lib/unimetadata.in.h     | 39 +++++++++++++++++++++++++++++++++++++
 m4/unimetadata_h.m4      | 42 ++++++++++++++++++++++++++++++++++++++++
 modules/unimetadata/base | 37 +++++++++++++++++++++++++++++++++++
 4 files changed, 125 insertions(+)
 create mode 100644 lib/unimetadata.in.h
 create mode 100644 m4/unimetadata_h.m4
 create mode 100644 modules/unimetadata/base

diff --git a/ChangeLog b/ChangeLog
index 32985d0abb..0e2478fe5f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-02-20  Bruno Haible  <bruno@clisp.org>
+
+	unimetadata/base: New module.
+	* lib/unimetadata.in.h: New file.
+	* m4/unimetadata_h.m4: New file.
+	* modules/unimetadata/base: New file.
+
 2024-02-20  Collin Funk  <collin.funk1@gmail.com>
 
 	maint.mk: Fix include header typo.
diff --git a/lib/unimetadata.in.h b/lib/unimetadata.in.h
new file mode 100644
index 0000000000..4e23350d98
--- /dev/null
+++ b/lib/unimetadata.in.h
@@ -0,0 +1,39 @@
+/* Meta information about GNU libunistring.
+   Copyright (C) 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 <https://www.gnu.org/licenses/>.  */
+
+#ifndef _UNIMETADATA_H
+#define _UNIMETADATA_H
+
+#if @HAVE_UNISTRING_WOE32DLL_H@
+# include <unistring/woe32dll.h>
+#else
+# define LIBUNISTRING_DLL_VARIABLE
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Supported Unicode version number: (major<<8) + minor  */
+extern @GNULIB_UNIMETADATA_UNICODE_VERSION_DLL_VARIABLE@ const int _libunistring_unicode_version;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _UNIMETADATA_H */
diff --git a/m4/unimetadata_h.m4 b/m4/unimetadata_h.m4
new file mode 100644
index 0000000000..abdc06d827
--- /dev/null
+++ b/m4/unimetadata_h.m4
@@ -0,0 +1,42 @@
+# unimetadata_h.m4 serial 1
+dnl Copyright (C) 2024 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN_ONCE([gl_UNIMETADATA_H],
+[
+  dnl Ensure to expand the default settings once only, before all statements
+  dnl that occur in other macros.
+  AC_REQUIRE([gl_UNIMETADATA_H_DEFAULTS])
+])
+
+# gl_UNIMETADATA_MODULE_INDICATOR([modulename])
+# sets the shell variable that indicates the presence of the given module
+# to a C preprocessor expression that will evaluate to 1.
+# This macro invocation must not occur in macros that are AC_REQUIREd.
+AC_DEFUN([gl_UNIMETADATA_MODULE_INDICATOR],
+[
+  dnl Ensure to expand the default settings once only.
+  gl_UNIMETADATA_H_REQUIRE_DEFAULTS
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+# Initializes the default values for AC_SUBSTed shell variables.
+# This macro must not be AC_REQUIREd.  It must only be invoked, and only
+# outside of macros or in macros that are not AC_REQUIREd.
+AC_DEFUN([gl_UNIMETADATA_H_REQUIRE_DEFAULTS],
+[
+  m4_defun(GL_MODULE_INDICATOR_PREFIX[_UNIMETADATA_H_MODULE_INDICATOR_DEFAULTS], [
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNIMETADATA_UNICODE_VERSION_DLL_VARIABLE], ['LIBUNISTRING_DLL_VARIABLE'])
+  ])
+  m4_require(GL_MODULE_INDICATOR_PREFIX[_UNIMETADATA_H_MODULE_INDICATOR_DEFAULTS])
+  AC_REQUIRE([gl_UNIMETADATA_H_DEFAULTS])
+])
+
+AC_DEFUN([gl_UNIMETADATA_H_DEFAULTS],
+[
+  dnl Assume proper GNU behavior unless another module says otherwise.
+])
diff --git a/modules/unimetadata/base b/modules/unimetadata/base
new file mode 100644
index 0000000000..e66c343e7e
--- /dev/null
+++ b/modules/unimetadata/base
@@ -0,0 +1,37 @@
+Description:
+Base layer for libunistring meta information.
+
+Files:
+lib/unimetadata.in.h
+m4/libunistring-base.m4
+m4/unimetadata_h.m4
+
+Depends-on:
+gen-header
+
+configure.ac:
+gl_LIBUNISTRING_LIBHEADER([1.2], [unimetadata.h])
+gl_UNIMETADATA_H
+gl_UNIMETADATA_H_REQUIRE_DEFAULTS
+AC_PROG_MKDIR_P
+
+Makefile.am:
+BUILT_SOURCES += $(LIBUNISTRING_UNIMETADATA_H)
+
+unimetadata.h: unimetadata.in.h
+@NMD@	$(AM_V_GEN)$(MKDIR_P) '%reldir%'
+	$(gl_V_at)$(SED_HEADER_STDOUT) \
+	      -e 's|@''HAVE_UNISTRING_WOE32DLL_H''@|$(HAVE_UNISTRING_WOE32DLL_H)|g' \
+	      -e 's/@''GNULIB_UNIMETADATA_UNICODE_VERSION_DLL_VARIABLE''@/$(GNULIB_UNIMETADATA_UNICODE_VERSION_DLL_VARIABLE)/g' \
+	      $(srcdir)/unimetadata.in.h > $@-t
+	$(AM_V_at)mv $@-t $@
+MOSTLYCLEANFILES += unimetadata.h unimetadata.h-t
+
+Include:
+"unimetadata.h"
+
+License:
+LGPLv2+
+
+Maintainer:
+all
-- 
2.34.1


[-- Attachment #3: 0002-unimetadata-u-version-New-module.patch --]
[-- Type: text/x-patch, Size: 5405 bytes --]

From 93293be63096a2708e3cc83e4360e7b3eb1c2174 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 21 Feb 2024 00:59:05 +0100
Subject: [PATCH 2/3] unimetadata/u-version: New module.

* lib/gen-uni-tables.c (output_version): New function.
(main): Invoke it.
* lib/unimetadata/u-version.c: New generated file.
* modules/unimetadata/u-version: New file.
---
 ChangeLog                     |  6 +++++
 lib/gen-uni-tables.c          | 48 +++++++++++++++++++++++++++++++++++
 lib/unimetadata/u-version.c   | 33 ++++++++++++++++++++++++
 modules/unimetadata/u-version | 26 +++++++++++++++++++
 4 files changed, 113 insertions(+)
 create mode 100644 lib/unimetadata/u-version.c
 create mode 100644 modules/unimetadata/u-version

diff --git a/ChangeLog b/ChangeLog
index 0e2478fe5f..a718dfa325 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2024-02-20  Bruno Haible  <bruno@clisp.org>
 
+	unimetadata/u-version: New module.
+	* lib/gen-uni-tables.c (output_version): New function.
+	(main): Invoke it.
+	* lib/unimetadata/u-version.c: New generated file.
+	* modules/unimetadata/u-version: New file.
+
 	unimetadata/base: New module.
 	* lib/unimetadata.in.h: New file.
 	* m4/unimetadata_h.m4: New file.
diff --git a/lib/gen-uni-tables.c b/lib/gen-uni-tables.c
index c73ce06d64..ea5e6aa3f8 100644
--- a/lib/gen-uni-tables.c
+++ b/lib/gen-uni-tables.c
@@ -11768,6 +11768,52 @@ output_casing_properties (const char *version)
 
 /* ========================================================================= */
 
+/* Output the Unicode version.  */
+static void
+output_version (const char *filename, const char *version)
+{
+  FILE *stream;
+  int major;
+  int minor;
+
+  stream = fopen (filename, "w");
+  if (stream == NULL)
+    {
+      fprintf (stderr, "cannot open '%s' for writing\n", filename);
+      exit (1);
+    }
+
+  fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n");
+  fprintf (stream, "/* Supported Unicode version.  */\n");
+  fprintf (stream, "/* Generated automatically by gen-uni-tables.c for Unicode %s.  */\n",
+           version);
+  fprintf (stream, "\n");
+
+  fprintf (stream, "/* Copyright (C) 2024 Free Software Foundation, Inc.\n");
+  fprintf (stream, "\n");
+  output_library_license (stream, false);
+  fprintf (stream, "\n");
+
+  fprintf (stream, "#include <config.h>\n");
+  fprintf (stream, "\n");
+
+  fprintf (stream, "/* Specification.  */\n");
+  fprintf (stream, "#include \"unimetadata.h\"\n");
+  fprintf (stream, "\n");
+
+  sscanf (version, "%d.%d", &major, &minor);
+  fprintf (stream, "const int _libunistring_unicode_version = (%d << 8) | %d;\n",
+           major, minor);
+
+  if (ferror (stream) || fclose (stream))
+    {
+      fprintf (stderr, "error writing to '%s'\n", filename);
+      exit (1);
+    }
+}
+
+/* ========================================================================= */
+
 int
 main (int argc, char * argv[])
 {
@@ -11885,6 +11931,8 @@ main (int argc, char * argv[])
   output_casing_rules ("unicase/special-casing-table.gperf", version);
   output_casing_properties (version);
 
+  output_version ("unimetadata/u-version.c", version);
+
   return 0;
 }
 
diff --git a/lib/unimetadata/u-version.c b/lib/unimetadata/u-version.c
new file mode 100644
index 0000000000..95ff0dcf31
--- /dev/null
+++ b/lib/unimetadata/u-version.c
@@ -0,0 +1,33 @@
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Supported Unicode version.  */
+/* Generated automatically by gen-uni-tables.c for Unicode 15.1.0.  */
+
+/* Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This file is free software.
+   It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
+   You can redistribute it and/or modify it under either
+     - the terms of the GNU Lesser General Public License as published
+       by the Free Software Foundation, either version 3, or (at your
+       option) any later version, or
+     - the terms of the GNU General Public License as published by the
+       Free Software Foundation; either version 2, or (at your option)
+       any later version, or
+     - the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
+
+   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 and the GNU General Public License
+   for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License and of the GNU General Public License along with this
+   program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "unimetadata.h"
+
+const int _libunistring_unicode_version = (15 << 8) | 1;
diff --git a/modules/unimetadata/u-version b/modules/unimetadata/u-version
new file mode 100644
index 0000000000..af5c2b665f
--- /dev/null
+++ b/modules/unimetadata/u-version
@@ -0,0 +1,26 @@
+Description:
+Supported Unicode version.
+
+Files:
+lib/unimetadata/u-version.c
+
+Depends-on:
+unimetadata/base
+
+configure.ac:
+gl_UNIMETADATA_H_REQUIRE_DEFAULTS
+gl_LIBUNISTRING_MODULE_WITH_VARIABLE([1.2], [unimetadata/u-version])
+
+Makefile.am:
+if LIBUNISTRING_COMPILE_UNIMETADATA_U_VERSION
+lib_SOURCES += unimetadata/u-version.c
+endif
+
+Include:
+"unimetadata.h"
+
+License:
+LGPLv3+ or GPLv2+
+
+Maintainer:
+all
-- 
2.34.1


[-- Attachment #4: 0003-unimetadata-u-version-Add-tests.patch --]
[-- Type: text/x-patch, Size: 3087 bytes --]

From 62881b7f74799530185c1ab1cea55bd435c6a4be Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 21 Feb 2024 01:02:35 +0100
Subject: [PATCH 3/3] unimetadata/u-version: Add tests.

* tests/unimetadata/test-u-version.c: New file.
* modules/unimetadata/u-version-tests: New file.
---
 ChangeLog                           |  4 +++
 modules/unimetadata/u-version-tests | 13 ++++++++++
 tests/unimetadata/test-u-version.c  | 39 +++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+)
 create mode 100644 modules/unimetadata/u-version-tests
 create mode 100644 tests/unimetadata/test-u-version.c

diff --git a/ChangeLog b/ChangeLog
index a718dfa325..dfc1641e74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2024-02-20  Bruno Haible  <bruno@clisp.org>
 
+	unimetadata/u-version: Add tests.
+	* tests/unimetadata/test-u-version.c: New file.
+	* modules/unimetadata/u-version-tests: New file.
+
 	unimetadata/u-version: New module.
 	* lib/gen-uni-tables.c (output_version): New function.
 	(main): Invoke it.
diff --git a/modules/unimetadata/u-version-tests b/modules/unimetadata/u-version-tests
new file mode 100644
index 0000000000..13d4c19521
--- /dev/null
+++ b/modules/unimetadata/u-version-tests
@@ -0,0 +1,13 @@
+Files:
+tests/unimetadata/test-u-version.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-u-version
+check_PROGRAMS += test-u-version
+test_u_version_SOURCES = unimetadata/test-u-version.c
+test_u_version_LDADD = $(LDADD) $(LIBUNISTRING)
diff --git a/tests/unimetadata/test-u-version.c b/tests/unimetadata/test-u-version.c
new file mode 100644
index 0000000000..6dc48ad389
--- /dev/null
+++ b/tests/unimetadata/test-u-version.c
@@ -0,0 +1,39 @@
+/* Test of supported Unicode version.
+   Copyright (C) 2009-2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2024.  */
+
+#include <config.h>
+
+#include "unimetadata.h"
+
+#include "macros.h"
+
+#if !(((defined _WIN32 || defined __CYGWIN__) && (HAVE_LIBUNISTRING || WOE32DLL)) || defined __ANDROID__)
+/* Check that _libunistring_unicode_version is defined and links.  */
+int const *vp = &_libunistring_unicode_version;
+#endif
+
+int
+main ()
+{
+  /* Check that _libunistring_unicode_version is defined and links.  */
+  volatile int v = _libunistring_unicode_version;
+  ASSERT (v >= (15 << 8));
+  ASSERT (v < (100 << 8));
+
+  return 0;
+}
-- 
2.34.1


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

* Re: new modules for libunistring metadata
  2024-02-21  0:15 new modules for libunistring metadata Bruno Haible
@ 2024-02-21  1:12 ` Collin Funk
  2024-02-21  2:10   ` Bruno Haible
  0 siblings, 1 reply; 4+ messages in thread
From: Collin Funk @ 2024-02-21  1:12 UTC (permalink / raw)
  To: bug-gnulib

On 2/20/24 4:15 PM, Bruno Haible wrote:
> It's better if this metadata is generated from gen-uni-tables.c. This
> eliminates a manual step. These patches do it.

Would it make sense to provide a macro to check if the current version
is greater than or equal to a given version? Or should that just be left
up to whoever wants to use this variable.

The person who submitted the feature request sent this example. It's
sort of a strange interface but it does the job.

UVersionInfo uver;
u_getUnicodeVersion(uver);
if (uver[0] < 12) {
	/* work around whatever was broken with
          HANGUL CHOSEONG CEONGCHIEUMSSANGCIEUC (**)
          in previous versions of unicode ...*/
}

I was thinking something like this:

#define LIBUNISTRING_UNICODE_VERSION_P(major, minor) \
  (_libunistring_unicode_version >= ((major << 8) + minor))

It works with these tests but they would fail as soon as the version is
updated...

ASSERT (LIBUNISTRING_UNICODE_VERSION_P (14, 0));
ASSERT (LIBUNISTRING_UNICODE_VERSION_P (15, 0));
ASSERT (!LIBUNISTRING_UNICODE_VERSION_P (16, 0));
ASSERT (LIBUNISTRING_UNICODE_VERSION_P (15, 0));
ASSERT (LIBUNISTRING_UNICODE_VERSION_P (15, 1));
ASSERT (!LIBUNISTRING_UNICODE_VERSION_P (15, 2));

Collin


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

* Re: new modules for libunistring metadata
  2024-02-21  1:12 ` Collin Funk
@ 2024-02-21  2:10   ` Bruno Haible
  2024-02-21  2:39     ` Collin Funk
  0 siblings, 1 reply; 4+ messages in thread
From: Bruno Haible @ 2024-02-21  2:10 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Collin Funk

Collin Funk wrote:
> Would it make sense to provide a macro to check if the current version
> is greater than or equal to a given version? Or should that just be left
> up to whoever wants to use this variable.

Why is there no macro
  #define streq(a,b) (strcmp (a, b) == 0)
in <string.h>? Because it can be left to the user.

Nevertheless, sometimes you see
  #define is_empty(list) (size_of (list) == 0)
It could be left to the user, but is included in the API because
the size of the list and the concept of an empty list are
distinct concepts (although related and very close).

> I was thinking something like this:
> 
> #define LIBUNISTRING_UNICODE_VERSION_P(major, minor) \
>   (_libunistring_unicode_version >= ((major << 8) + minor))

For my feeling, there's too little added value in such a macro.

Remember the costs of documenting a function or macro:
  - The user needs more time to read the documentation.
  - The developer needs to code and document it.

Bruno





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

* Re: new modules for libunistring metadata
  2024-02-21  2:10   ` Bruno Haible
@ 2024-02-21  2:39     ` Collin Funk
  0 siblings, 0 replies; 4+ messages in thread
From: Collin Funk @ 2024-02-21  2:39 UTC (permalink / raw)
  To: Bruno Haible, bug-gnulib

On 2/20/24 6:10 PM, Bruno Haible wrote:
> For my feeling, there's too little added value in such a macro.
> 
> Remember the costs of documenting a function or macro:
>   - The user needs more time to read the documentation.
>   - The developer needs to code and document it.

Fair enough. I assume that whatever is causing them to need to know the
supported Unicode version is probably a bigger problem than bit shifting
or defining a macro themselves. :)

Collin


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

end of thread, other threads:[~2024-02-21  2:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-21  0:15 new modules for libunistring metadata Bruno Haible
2024-02-21  1:12 ` Collin Funk
2024-02-21  2:10   ` Bruno Haible
2024-02-21  2:39     ` Collin Funk

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