bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/1] Move xstrtol_fatal to a new xstrtol-error module


From: Pino Toscano
Subject: [PATCH 1/1] Move xstrtol_fatal to a new xstrtol-error module
Date: Thu, 5 Dec 2019 16:18:35 +0100

The xstrtol module provides a xstrtol_fatal function which uses other
modules suitable mostly for command line handling (e.g. gettext,
getopt), and that are completely unused when using only xstrto*
functions. Furthermore, xstrtol_fatal is used only in the xstrtol-tests
(within gnulib itself).

As solution, move the xstrtol_fatal to a new xstrtol-error module,
making xstrtol-tests depend on it. Since the prototype of xstrtol_fatal
is automatically provided by xstrtol.h, it is very difficult to know
whether anyone is actually using it, so add a note about this in NEWS.

* lib/xstrtol.h: Stop including <getopt.h>.
(xstrtol_fatal): Move ...
* lib/xstrtol-error.h: ... here.  New file.
* modules/xstrtol (Files): Remove lib/xstrtol-error.c.
(Depends-on): Remove exitfail, error, getopt-gnu, and gettext-h.
(Makefile.am): Remove xstrtol-error.c from lib_SOURCES.
* lib/xstrtol-error.c: Include xstrtol-error.h instead of xstrtol.h.
* tests/test-xstrtol.c: Likewise.
* modules/xstrtol-error: New file.
* modules/xstrtol-tests (Depends-on): Add xstrtol-error.
* MODULES.html.sh: Add xstrtol-error.
* NEWS: Document the change.
---
 ChangeLog             | 16 +++++++++++++++
 MODULES.html.sh       |  1 +
 NEWS                  |  6 ++++++
 lib/xstrtol-error.c   |  2 +-
 lib/xstrtol-error.h   | 45 +++++++++++++++++++++++++++++++++++++++++++
 lib/xstrtol.h         | 20 -------------------
 modules/xstrtol       |  7 +------
 modules/xstrtol-error | 27 ++++++++++++++++++++++++++
 modules/xstrtol-tests |  1 +
 tests/test-xstrtol.c  |  2 +-
 10 files changed, 99 insertions(+), 28 deletions(-)
 create mode 100644 lib/xstrtol-error.h
 create mode 100644 modules/xstrtol-error

diff --git a/ChangeLog b/ChangeLog
index cb3ffc7e8..7709bbdec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2019-12-05  Pino Toscano  <address@hidden>
+
+       Move xstrtol_fatal to a new xstrtol-error module.
+       * lib/xstrtol.h: Stop including <getopt.h>.
+       (xstrtol_fatal): Move ...
+       * lib/xstrtol-error.h: ... here.  New file.
+       * modules/xstrtol (Files): Remove lib/xstrtol-error.c.
+       (Depends-on): Remove exitfail, error, getopt-gnu, and gettext-h.
+       (Makefile.am): Remove xstrtol-error.c from lib_SOURCES.
+       * lib/xstrtol-error.c: Include xstrtol-error.h instead of xstrtol.h.
+       * tests/test-xstrtol.c: Likewise.
+       * modules/xstrtol-error: New file.
+       * modules/xstrtol-tests (Depends-on): Add xstrtol-error.
+       * MODULES.html.sh: Add xstrtol-error.
+       * NEWS: Document the change.
+
 2019-12-04  Bruno Haible  <address@hidden>
 
        Fix compilation errors in C++ mode with xlclang++ on AIX.
diff --git a/MODULES.html.sh b/MODULES.html.sh
index 107f16cc2..2ed3bf905 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -1861,6 +1861,7 @@ func_all_modules ()
   func_module c-strtold
   func_module xstrtod
   func_module xstrtol
+  func_module xstrtol-error
   func_module xstrtoll
   func_module xstrtold
   func_end_table
diff --git a/NEWS b/NEWS
index 2655d7fc9..0972d951b 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,12 @@ Important general notes
 
 Date        Modules         Changes
 
+2019-12-05  userspec        The xstrtol_fatal is moved away from the xstrtol
+            xstrtoimax      module to a new xstrtol-error module. Because of
+            xstrtol         this, using xstrtol or any of the modules using it
+            xstrtoll        does not pull automatically the exitfail, error,
+            xstrtoumax      getopt-gnu, and gettext-h modules.
+
 2019-03-16  fatal-signal    The function that you pass to at_fatal_signal now
                             takes the signal as argument.
 
diff --git a/lib/xstrtol-error.c b/lib/xstrtol-error.c
index a0d10c285..386d22b2d 100644
--- a/lib/xstrtol-error.c
+++ b/lib/xstrtol-error.c
@@ -17,7 +17,7 @@
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 #include <config.h>
-#include "xstrtol.h"
+#include "xstrtol-error.h"
 
 #include <stdlib.h>
 
diff --git a/lib/xstrtol-error.h b/lib/xstrtol-error.h
new file mode 100644
index 000000000..a9cd940a4
--- /dev/null
+++ b/lib/xstrtol-error.h
@@ -0,0 +1,45 @@
+/* Error reporting interface for xstrto* functions.
+
+   Copyright (C) 1995-1996, 1998-1999, 2001-2004, 2006-2019 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/>.  */
+
+#ifndef XSTRTOL_ERROR_H_
+# define XSTRTOL_ERROR_H_ 1
+
+# include "xstrtol.h"
+
+# include <getopt.h>
+
+/* Report an error for an invalid integer in an option argument.
+
+   ERR is the error code returned by one of the xstrto* functions.
+
+   Use OPT_IDX to decide whether to print the short option string "C"
+   or "-C" or a long option string derived from LONG_OPTION.  OPT_IDX
+   is -2 if the short option "C" was used, without any leading "-"; it
+   is -1 if the short option "-C" was used; otherwise it is an index
+   into LONG_OPTIONS, which should have a name preceded by two '-'
+   characters.
+
+   ARG is the option-argument containing the integer.
+
+   After reporting an error, exit with a failure status.  */
+
+_Noreturn void xstrtol_fatal (enum strtol_error,
+                              int, char, struct option const *,
+                              char const *);
+
+#endif /* not XSTRTOL_ERROR_H_ */
diff --git a/lib/xstrtol.h b/lib/xstrtol.h
index fff320d50..d888120e6 100644
--- a/lib/xstrtol.h
+++ b/lib/xstrtol.h
@@ -19,7 +19,6 @@
 #ifndef XSTRTOL_H_
 # define XSTRTOL_H_ 1
 
-# include <getopt.h>
 # include <inttypes.h>
 
 # ifndef _STRTOL_ERROR
@@ -51,23 +50,4 @@ _DECLARE_XSTRTOL (xstrtoll, long long int)
 _DECLARE_XSTRTOL (xstrtoull, unsigned long long int)
 #endif
 
-/* Report an error for an invalid integer in an option argument.
-
-   ERR is the error code returned by one of the xstrto* functions.
-
-   Use OPT_IDX to decide whether to print the short option string "C"
-   or "-C" or a long option string derived from LONG_OPTION.  OPT_IDX
-   is -2 if the short option "C" was used, without any leading "-"; it
-   is -1 if the short option "-C" was used; otherwise it is an index
-   into LONG_OPTIONS, which should have a name preceded by two '-'
-   characters.
-
-   ARG is the option-argument containing the integer.
-
-   After reporting an error, exit with a failure status.  */
-
-_Noreturn void xstrtol_fatal (enum strtol_error,
-                              int, char, struct option const *,
-                              char const *);
-
 #endif /* not XSTRTOL_H_ */
diff --git a/modules/xstrtol b/modules/xstrtol
index 26240ecc9..a765f9745 100644
--- a/modules/xstrtol
+++ b/modules/xstrtol
@@ -5,22 +5,17 @@ Files:
 lib/xstrtol.h
 lib/xstrtol.c
 lib/xstrtoul.c
-lib/xstrtol-error.c
 m4/xstrtol.m4
 
 Depends-on:
 assure
-exitfail
-error
-getopt-gnu
-gettext-h
 inttypes-incomplete
 
 configure.ac:
 gl_XSTRTOL
 
 Makefile.am:
-lib_SOURCES += xstrtol.c xstrtoul.c xstrtol-error.c
+lib_SOURCES += xstrtol.c xstrtoul.c
 
 Include:
 "xstrtol.h"
diff --git a/modules/xstrtol-error b/modules/xstrtol-error
new file mode 100644
index 000000000..9c3da2a5a
--- /dev/null
+++ b/modules/xstrtol-error
@@ -0,0 +1,27 @@
+Description:
+Error reporting function for xstrto* functions.
+
+Files:
+lib/xstrtol-error.c
+lib/xstrtol-error.h
+
+Depends-on:
+xstrtol
+error
+exitfail
+getopt-gnu
+gettext-h
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += xstrtol-error.c
+
+Include:
+"xstrtol-error.h"
+
+License:
+GPL
+
+Maintainer:
+Jim Meyering
diff --git a/modules/xstrtol-tests b/modules/xstrtol-tests
index da11c1960..1786873d0 100644
--- a/modules/xstrtol-tests
+++ b/modules/xstrtol-tests
@@ -6,6 +6,7 @@ tests/test-xstrtol.sh
 Depends-on:
 inttypes
 test-framework-sh
+xstrtol-error
 
 configure.ac:
 
diff --git a/tests/test-xstrtol.c b/tests/test-xstrtol.c
index 7f9df2e3f..ffac9bdea 100644
--- a/tests/test-xstrtol.c
+++ b/tests/test-xstrtol.c
@@ -20,7 +20,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "xstrtol.h"
+#include "xstrtol-error.h"
 #include "error.h"
 
 #ifndef __xstrtol
-- 
2.21.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]