[tz] [PROPOSED 3/5] Use C23 [[reproducible]] if available.

Paul Eggert eggert at cs.ucla.edu
Mon Nov 21 18:36:41 UTC 2022


* private.h (ATTRIBUTE_REPRODUCIBLE): Rename from ATTRIBUTE_PURE,
and use C23 style [[reproducible]] if available.  All uses changed.
---
 localtime.c |  4 ++--
 private.h   | 19 +++++++++++++++----
 zdump.c     |  6 +++---
 zic.c       | 16 ++++++++--------
 4 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/localtime.c b/localtime.c
index 4dd9d259..1d22d351 100644
--- a/localtime.c
+++ b/localtime.c
@@ -838,7 +838,7 @@ is_digit(char c)
 ** Return a pointer to that character.
 */
 
-static ATTRIBUTE_PURE const char *
+static ATTRIBUTE_REPRODUCIBLE const char *
 getzname(register const char *strp)
 {
 	register char	c;
@@ -859,7 +859,7 @@ getzname(register const char *strp)
 ** We don't do any checking here; checking is done later in common-case code.
 */
 
-static ATTRIBUTE_PURE const char *
+static ATTRIBUTE_REPRODUCIBLE const char *
 getqzname(register const char *strp, const int delim)
 {
 	register int	c;
diff --git a/private.h b/private.h
index b9803427..643068a7 100644
--- a/private.h
+++ b/private.h
@@ -428,12 +428,10 @@ typedef unsigned long uintmax_t;
 #if 3 <= __GNUC__
 # define ATTRIBUTE_CONST __attribute__((const))
 # define ATTRIBUTE_MALLOC __attribute__((malloc))
-# define ATTRIBUTE_PURE __attribute__((pure))
 # define ATTRIBUTE_FORMAT(spec) __attribute__((format spec))
 #else
 # define ATTRIBUTE_CONST /* empty */
 # define ATTRIBUTE_MALLOC /* empty */
-# define ATTRIBUTE_PURE /* empty */
 # define ATTRIBUTE_FORMAT(spec) /* empty */
 #endif
 
@@ -472,6 +470,19 @@ typedef unsigned long uintmax_t;
 # endif
 #endif
 
+#if HAVE_HAS_C_ATTRIBUTE
+# if __has_c_attribute(reproducible)
+#  define ATTRIBUTE_REPRODUCIBLE [[reproducible]]
+# endif
+#endif
+#ifndef ATTRIBUTE_REPRODUCIBLE
+# if 3 <= __GNUC__
+#  define ATTRIBUTE_REPRODUCIBLE __attribute__((pure))
+# else
+#  define ATTRIBUTE_REPRODUCIBLE /* empty */
+# endif
+#endif
+
 #if __STDC_VERSION__ < 199901 && !defined restrict
 # define restrict /* empty */
 #endif
@@ -705,10 +716,10 @@ timezone_t tzalloc(char const *);
 void tzfree(timezone_t);
 # ifdef STD_INSPIRED
 #  if TZ_TIME_T || !defined posix2time_z
-time_t posix2time_z(timezone_t, time_t) ATTRIBUTE_PURE;
+time_t posix2time_z(timezone_t, time_t) ATTRIBUTE_REPRODUCIBLE;
 #  endif
 #  if TZ_TIME_T || !defined time2posix_z
-time_t time2posix_z(timezone_t, time_t) ATTRIBUTE_PURE;
+time_t time2posix_z(timezone_t, time_t) ATTRIBUTE_REPRODUCIBLE;
 #  endif
 # endif
 #endif
diff --git a/zdump.c b/zdump.c
index 99723ac0..47141655 100644
--- a/zdump.c
+++ b/zdump.c
@@ -89,7 +89,7 @@ static bool	warned;
 static bool	errout;
 
 static char const *abbr(struct tm const *);
-static intmax_t	delta(struct tm *, struct tm *) ATTRIBUTE_PURE;
+static intmax_t	delta(struct tm *, struct tm *) ATTRIBUTE_REPRODUCIBLE;
 static void dumptime(struct tm const *);
 static time_t hunt(timezone_t, time_t, time_t, bool);
 static void show(timezone_t, char *, time_t, bool);
@@ -97,7 +97,7 @@ static void showextrema(timezone_t, char *, time_t, struct tm *, time_t);
 static void showtrans(char const *, struct tm const *, time_t, char const *,
 		      char const *);
 static const char *tformat(void);
-static time_t yeartot(intmax_t) ATTRIBUTE_PURE;
+static time_t yeartot(intmax_t) ATTRIBUTE_REPRODUCIBLE;
 
 /* Is C an ASCII digit?  */
 static bool
@@ -134,7 +134,7 @@ size_overflow(void)
 
 /* Return A + B, exiting if the result would overflow either ptrdiff_t
    or size_t.  */
-static ATTRIBUTE_PURE ptrdiff_t
+static ATTRIBUTE_REPRODUCIBLE ptrdiff_t
 sumsize(size_t a, size_t b)
 {
 #ifdef ckd_add
diff --git a/zic.c b/zic.c
index bd0cf4cd..4af0ca27 100644
--- a/zic.c
+++ b/zic.c
@@ -472,7 +472,7 @@ size_overflow(void)
   memory_exhausted(_("size overflow"));
 }
 
-static ATTRIBUTE_PURE ptrdiff_t
+static ATTRIBUTE_REPRODUCIBLE ptrdiff_t
 size_sum(size_t a, size_t b)
 {
 #ifdef ckd_add
@@ -487,7 +487,7 @@ size_sum(size_t a, size_t b)
   size_overflow();
 }
 
-static ATTRIBUTE_PURE ptrdiff_t
+static ATTRIBUTE_REPRODUCIBLE ptrdiff_t
 size_product(ptrdiff_t nitems, ptrdiff_t itemsize)
 {
 #ifdef ckd_mul
@@ -502,7 +502,7 @@ size_product(ptrdiff_t nitems, ptrdiff_t itemsize)
   size_overflow();
 }
 
-static ATTRIBUTE_PURE ptrdiff_t
+static ATTRIBUTE_REPRODUCIBLE ptrdiff_t
 align_to(ptrdiff_t size, ptrdiff_t alignment)
 {
   ptrdiff_t lo_bits = alignment - 1, sum = size_sum(size, lo_bits);
@@ -3597,7 +3597,7 @@ lowerit(char a)
 }
 
 /* case-insensitive equality */
-static ATTRIBUTE_PURE bool
+static ATTRIBUTE_REPRODUCIBLE bool
 ciequal(register const char *ap, register const char *bp)
 {
 	while (lowerit(*ap) == lowerit(*bp++))
@@ -3606,7 +3606,7 @@ ciequal(register const char *ap, register const char *bp)
 	return false;
 }
 
-static ATTRIBUTE_PURE bool
+static ATTRIBUTE_REPRODUCIBLE bool
 itsabbr(register const char *abbr, register const char *word)
 {
 	if (lowerit(*abbr) != lowerit(*word))
@@ -3622,7 +3622,7 @@ itsabbr(register const char *abbr, register const char *word)
 
 /* Return true if ABBR is an initial prefix of WORD, ignoring ASCII case.  */
 
-static ATTRIBUTE_PURE bool
+static ATTRIBUTE_REPRODUCIBLE bool
 ciprefix(char const *abbr, char const *word)
 {
   do
@@ -3732,7 +3732,7 @@ time_overflow(void)
   exit(EXIT_FAILURE);
 }
 
-static ATTRIBUTE_PURE zic_t
+static ATTRIBUTE_REPRODUCIBLE zic_t
 oadd(zic_t t1, zic_t t2)
 {
 #ifdef ckd_add
@@ -3746,7 +3746,7 @@ oadd(zic_t t1, zic_t t2)
   time_overflow();
 }
 
-static ATTRIBUTE_PURE zic_t
+static ATTRIBUTE_REPRODUCIBLE zic_t
 tadd(zic_t t1, zic_t t2)
 {
 #ifdef ckd_add
-- 
2.37.2




More information about the tz mailing list