From f1de694cbffac2acc392e3db6a038b17f3b77d02 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 29 Aug 2021 18:02:29 -0700 Subject: maint: prefer attribute.h attributes Prefer the macros used in attribute.h, and _Noreturn, to the by-hand use of __attribute__, as this is more portable. * bootstrap.conf (gnulib_modules): Add attribute. * src/system.h: Include attribute.h. All uses of attributes changed to use the attribute.h macros. Plus, use _Noreturn. (FALLTHROUGH): Remove; attribute.h now defines this. --- bootstrap.conf | 1 + src/cmp.c | 5 ++--- src/context.c | 2 +- src/diff.c | 2 +- src/diff.h | 12 ++++++------ src/diff3.c | 8 ++++---- src/dir.c | 2 +- src/sdiff.c | 12 +++++------- src/system.h | 21 +++++---------------- src/util.c | 6 +++--- 10 files changed, 29 insertions(+), 42 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 9234a43..39908c0 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -24,6 +24,7 @@ avoided_gnulib_modules=' # gnulib modules used by this package. gnulib_modules=' announce-gen +attribute argmatch binary-io c-stack diff --git a/src/cmp.c b/src/cmp.c index 2e89ac1..a96c9ee 100644 --- a/src/cmp.c +++ b/src/cmp.c @@ -53,7 +53,7 @@ static int cmp (void); static off_t file_position (int); -static size_t block_compare (word const *, word const *) _GL_ATTRIBUTE_PURE; +static size_t block_compare (word const *, word const *) ATTRIBUTE_PURE; static size_t count_newlines (char *, size_t); static void sprintc (char *, unsigned char); @@ -110,8 +110,7 @@ static struct option const long_options[] = {0, 0, 0, 0} }; -static void try_help (char const *, char const *) __attribute__((noreturn)); -static void +static _Noreturn void try_help (char const *reason_msgid, char const *operand) { if (reason_msgid) diff --git a/src/context.c b/src/context.c index 30f8fd4..b3cfa7d 100644 --- a/src/context.c +++ b/src/context.c @@ -433,7 +433,7 @@ pr_unidiff_hunk (struct change *hunk) 2*CONTEXT unchanged lines appear, and return a pointer to the 'struct change' for the last change before those lines. */ -static struct change * _GL_ATTRIBUTE_PURE +static struct change * ATTRIBUTE_PURE find_hunk (struct change *start) { struct change *prev; diff --git a/src/diff.c b/src/diff.c index ef9710a..fedc7df 100644 --- a/src/diff.c +++ b/src/diff.c @@ -72,7 +72,7 @@ static void summarize_regexp_list (struct regexp_list *); static void specify_style (enum output_style); static void specify_value (char const **, char const *, char const *); static void specify_colors_style (char const *); -static void try_help (char const *, char const *) __attribute__((noreturn)); +static _Noreturn void try_help (char const *, char const *); static void check_stdout (void); static void usage (void); diff --git a/src/diff.h b/src/diff.h index 0228275..d65c1da 100644 --- a/src/diff.h +++ b/src/diff.h @@ -356,8 +356,8 @@ extern int diff_dirs (struct comparison const *, int (*) (struct comparison const *, char const *, char const *)); extern char *find_dir_file_pathname (char const *, char const *) - _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE - _GL_ATTRIBUTE_RETURNS_NONNULL; + ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC_FREE + ATTRIBUTE_RETURNS_NONNULL; /* ed.c */ extern void print_ed_script (struct change *); @@ -382,7 +382,7 @@ extern void print_sdiff_script (struct change *); /* util.c */ extern char const change_letter[4]; extern char const pr_program[]; -extern bool lines_differ (char const *, char const *) _GL_ATTRIBUTE_PURE; +extern bool lines_differ (char const *, char const *) ATTRIBUTE_PURE; extern lin translate_line_number (struct file_data const *, lin); extern struct change *find_change (struct change *); extern struct change *find_reverse_change (struct change *); @@ -390,13 +390,13 @@ extern enum changes analyze_hunk (struct change *, lin *, lin *, lin *, lin *); extern void begin_output (void); extern void cleanup_signal_handlers (void); extern void debug_script (struct change *); -extern void fatal (char const *) __attribute__((noreturn)); +extern _Noreturn void fatal (char const *); extern void finish_output (void); -extern void message (char const *, ...) _GL_ATTRIBUTE_FORMAT ((printf, 1, 2)); +extern void message (char const *, ...) ATTRIBUTE_FORMAT ((printf, 1, 2)); extern void output_1_line (char const *, char const *, char const *, char const *); extern void perror_with_name (char const *); -extern void pfatal_with_name (char const *) __attribute__((noreturn)); +extern _Noreturn void pfatal_with_name (char const *); extern void print_1_line (char const *, char const * const *); extern void print_1_line_nl (char const *, char const * const *, bool); extern void print_message_queue (void); diff --git a/src/diff3.c b/src/diff3.c index 9e4ad54..2ae82f3 100644 --- a/src/diff3.c +++ b/src/diff3.c @@ -191,10 +191,10 @@ static struct diff3_block *reverse_diff3_blocklist (struct diff3_block *); static struct diff3_block *using_to_diff3_block (struct diff_block *[2], struct diff_block *[2], int, int, struct diff3_block const *); static struct diff_block *process_diff (char const *, char const *, char **); static void check_stdout (void); -static void fatal (char const *) __attribute__((noreturn)); +static _Noreturn void fatal (char const *); static void output_diff3 (FILE *, struct diff3_block *, int const[3], int const[3]); -static void perror_with_exit (char const *) __attribute__((noreturn)); -static void try_help (char const *, char const *) __attribute__((noreturn)); +static _Noreturn void perror_with_exit (char const *); +static _Noreturn void try_help (char const *, char const *); static void usage (void); static char const *diff_program = DEFAULT_DIFF_PROGRAM; @@ -1097,7 +1097,7 @@ process_diff (char const *filea, /* Skip tabs and spaces, and return the first character after them. */ -static char * _GL_ATTRIBUTE_PURE +static char * ATTRIBUTE_PURE skipwhite (char *s) { while (*s == ' ' || *s == '\t') diff --git a/src/dir.c b/src/dir.c index 409eee4..b38ce73 100644 --- a/src/dir.c +++ b/src/dir.c @@ -322,7 +322,7 @@ diff_dirs (struct comparison const *cmp, /* Return nonzero if CMP is looping recursively in argument I. */ -static bool _GL_ATTRIBUTE_PURE +static bool ATTRIBUTE_PURE dir_loop (struct comparison const *cmp, int i) { struct comparison const *p = cmp; diff --git a/src/sdiff.c b/src/sdiff.c index f6011ce..9dd4960 100644 --- a/src/sdiff.c +++ b/src/sdiff.c @@ -63,8 +63,8 @@ static bool edit (struct line_filter *, char const *, lin, lin, struct line_filt static bool interact (struct line_filter *, struct line_filter *, char const *, struct line_filter *, char const *, FILE *); static void checksigs (void); static void diffarg (char const *); -static void fatal (char const *) __attribute__((noreturn)); -static void perror_fatal (char const *) __attribute__((noreturn)); +static _Noreturn void fatal (char const *); +static _Noreturn void perror_fatal (char const *); static void trapsigs (void); static void untrapsig (int); @@ -151,8 +151,7 @@ static struct option const longopts[] = {0, 0, 0, 0} }; -static void try_help (char const *, char const *) __attribute__((noreturn)); -static void +static _Noreturn void try_help (char const *reason_msgid, char const *operand) { if (reason_msgid) @@ -225,7 +224,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\ /* Clean up after a signal or other failure. This function is async-signal-safe. */ static void -cleanup (int signo __attribute__((unused))) +cleanup (_GL_UNUSED int signo) { #if HAVE_WORKING_FORK if (0 < diffpid) @@ -235,8 +234,7 @@ cleanup (int signo __attribute__((unused))) unlink (tmpname); } -static void exiterr (void) __attribute__((noreturn)); -static void +static _Noreturn void exiterr (void) { cleanup (0); diff --git a/src/system.h b/src/system.h index b6d86a9..7b71932 100644 --- a/src/system.h +++ b/src/system.h @@ -27,18 +27,12 @@ # define IF_LINT(Code) /* empty */ #endif -/* Define '__attribute__' and 'volatile' first - so that they're used consistently in all system includes. */ -#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__ -# define __attribute__(x) -#endif - #include #include #include -#include "stat-macros.h" +#include #ifndef STAT_BLOCKSIZE # if HAVE_STRUCT_STAT_ST_BLKSIZE @@ -115,8 +109,11 @@ int strcasecmp (char const *, char const *); #define MAX(a, b) ((a) >= (b) ? (a) : (b)) #include + +#include #include -#include "propername.h" +#include + #include "version.h" /* Type used for fast comparison of several bytes at a time. @@ -211,11 +208,3 @@ typedef ptrdiff_t lin; #endif #define STREQ(a, b) (strcmp (a, b) == 0) - -#ifndef FALLTHROUGH -# if __GNUC__ < 7 -# define FALLTHROUGH ((void) 0) -# else -# define FALLTHROUGH __attribute__ ((__fallthrough__)) -# endif -#endif diff --git a/src/util.c b/src/util.c index 1cb98d4..7e77522 100644 --- a/src/util.c +++ b/src/util.c @@ -1225,13 +1225,13 @@ lines_differ (char const *s1, char const *s2) /* Find the consecutive changes at the start of the script START. Return the last link before the first gap. */ -struct change * _GL_ATTRIBUTE_CONST +struct change * ATTRIBUTE_CONST find_change (struct change *start) { return start; } -struct change * _GL_ATTRIBUTE_CONST +struct change * ATTRIBUTE_CONST find_reverse_change (struct change *start) { return start; @@ -1473,7 +1473,7 @@ char const change_letter[] = { 0, 'd', 'a', 'c' }; Internal line numbers count from 0 starting after the prefix. Actual line numbers count from 1 within the entire file. */ -lin _GL_ATTRIBUTE_PURE +lin ATTRIBUTE_PURE translate_line_number (struct file_data const *file, lin i) { return i + file->prefix_lines + 1; -- cgit v1.2.1