Thanks, I installed the attached.
From 62d075ad726e9a2a93c829873a63623284971c87 Mon Sep 17 00:00:00 2001 From: Paul Eggert <egg...@cs.ucla.edu> Date: Tue, 14 May 2024 15:46:48 -0700 Subject: [PATCH] maint: be less fancy when defining extern vars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit
Bug reported by Bruno Haible in <https://bugs.gnu.org/70951>. I never did like the XTERN macro and its descendants, as this “extension” to C causes more confusion than it cures, so let’s just get rid of it and use plain ‘extern’. * cfg.mk (_gl_TS_extern): Remove XTERN, SYSTEM_EXTERN. * src/Makefile.am (cmp_SOURCES, diff3_SOURCES, sdiff_SOURCES) (diff_SOURCES): Add system.c. * src/cmp.c, src/diff.c, src/diff3.c, src/sdiff.c (SYSTEM_INLINE): Remove. * src/diff.c: Define vars declared in diff.h. * src/diff.h (DIFF_EXTERN): Remove. All uses removed. Just use ‘extern’ when declaring extern vars. * src/system.h (SYSTEM_EXTERN): Likewise. * src/system.c: New file. --- cfg.mk | 5 +-- src/Makefile.am | 8 ++--- src/cmp.c | 1 - src/diff.c | 45 +++++++++++++++++++++++++- src/diff.h | 85 ++++++++++++++++++++++++------------------------- src/diff3.c | 1 - src/sdiff.c | 1 - src/system.c | 30 +++++++++++++++++ src/system.h | 9 ++---- 9 files changed, 125 insertions(+), 60 deletions(-) create mode 100644 src/system.c diff --git a/cfg.mk b/cfg.mk index 5efdc5a..3c0296f 100644 --- a/cfg.mk +++ b/cfg.mk @@ -79,5 +79,6 @@ exclude_file_name_regexp--sc_doubled_words = ^gl/lib/mcel\.h$$ exclude_file_name_regexp--sc_prohibit_doubled_word = ^(gl/lib/mcel\.h|tests/y2038-vs-32bit)$$ exclude_file_name_regexp--sc_prohibit_strcmp = ^gl/lib/ -# Tell gnulib's tight_scope rule that we mark externs with XTERN -export _gl_TS_extern = extern|XTERN|DIFF_INLINE|SYSTEM_INLINE|SYSTEM_EXTERN +# Tell gnulib's tight_scope rule that we mark extern inlines with +# DIFF_INLINE and SYSTEM_INLINE. +export _gl_TS_extern = extern|DIFF_INLINE|SYSTEM_INLINE diff --git a/src/Makefile.am b/src/Makefile.am index 8310923..01c6f1f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,12 +42,12 @@ cmp_LDADD = $(LDADD) sdiff_LDADD = $(LDADD) $(GETRANDOM_LIB) diff3_LDADD = $(LDADD) -cmp_SOURCES = cmp.c -diff3_SOURCES = diff3.c -sdiff_SOURCES = sdiff.c +cmp_SOURCES = cmp.c system.c +diff3_SOURCES = diff3.c system.c +sdiff_SOURCES = sdiff.c system.c diff_SOURCES = \ analyze.c context.c diff.c dir.c ed.c ifdef.c io.c \ - normal.c side.c util.c + normal.c side.c system.c util.c noinst_HEADERS = diff.h system.h MOSTLYCLEANFILES = paths.h paths.ht diff --git a/src/cmp.c b/src/cmp.c index d2f65b5..9a8bfc4 100644 --- a/src/cmp.c +++ b/src/cmp.c @@ -16,7 +16,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#define SYSTEM_INLINE _GL_EXTERN_INLINE #include "system.h" #include "paths.h" diff --git a/src/diff.c b/src/diff.c index 74b03ae..76432ee 100644 --- a/src/diff.c +++ b/src/diff.c @@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #define DIFF_INLINE _GL_EXTERN_INLINE -#define SYSTEM_INLINE _GL_EXTERN_INLINE #include "diff.h" #include "paths.h" @@ -1647,3 +1646,47 @@ compare_files (struct comparison const *parent, enum detype const detype[2], return status; } + +/* Define variables declared in diff.h (which see). */ +FILE *outfile; +bool brief; +bool expand_tabs; +bool files_can_be_treated_as_binary; +bool ignore_blank_lines; +bool ignore_case; +bool ignore_file_name_case; +bool initial_tab; +bool left_column; +bool minimal; +bool no_dereference_symlinks; +bool no_diff_means_no_output; +bool paginate; +bool presume_output_tty; +bool sdiff_merge_assist; +bool speed_large_files; +bool strip_trailing_cr; +bool suppress_blank_empty; +bool suppress_common_lines; +bool text; +char *file_label[2]; +char *switch_string; +char const *group_format[CHANGED + 1]; +char const *line_format[NEW + 1]; +char const *starting_file; +char const *time_format; +enum DIFF_white_space ignore_white_space; +enum colors_style colors_style; +enum output_style output_style; +intmax_t sdiff_column2_offset; +intmax_t sdiff_half_width; +intmax_t tabsize; +lin context; +lin horizon_lines; +struct comparison curr; +struct comparison noparent; +struct exclude *excluded; +struct re_pattern_buffer function_regexp; +struct re_pattern_buffer ignore_regexp; +#ifndef localtz +timezone_t localtz; +#endif diff --git a/src/diff.h b/src/diff.h index 3944452..f0723ff 100644 --- a/src/diff.h +++ b/src/diff.h @@ -25,10 +25,7 @@ _GL_INLINE_HEADER_BEGIN -#ifdef DIFF_INLINE -# define DIFF_EXTERN(decl) extern decl; decl -#else -# define DIFF_EXTERN(decl) extern decl +#ifndef DIFF_INLINE # define DIFF_INLINE _GL_INLINE #endif @@ -101,24 +98,24 @@ DIFF_INLINE bool robust_output_style (enum output_style s) return s != OUTPUT_ED && s != OUTPUT_FORWARD_ED; } -DIFF_EXTERN (enum output_style output_style); +extern enum output_style output_style; /* Define the current color context used to print a line. */ -DIFF_EXTERN (enum colors_style colors_style); +extern enum colors_style colors_style; /* Nonzero if output cannot be generated for identical files. */ -DIFF_EXTERN (bool no_diff_means_no_output); +extern bool no_diff_means_no_output; /* Number of lines of context to show in each set of diffs. This is zero when context is not to be shown. */ -DIFF_EXTERN (lin context); +extern lin context; /* Consider all files as text files (-a). Don't interpret codes over 0177 as implying a "binary file". */ -DIFF_EXTERN (bool text); +extern bool text; /* Number of lines to keep in identical prefix and suffix. */ -DIFF_EXTERN (lin horizon_lines); +extern lin horizon_lines; /* The significance of white space during comparisons. */ enum DIFF_white_space @@ -143,107 +140,107 @@ enum DIFF_white_space /* Ignore all horizontal white space (-w). */ IGNORE_ALL_SPACE }; -DIFF_EXTERN (enum DIFF_white_space ignore_white_space); +extern enum DIFF_white_space ignore_white_space; /* Ignore changes that affect only blank lines (-B). */ -DIFF_EXTERN (bool ignore_blank_lines); +extern bool ignore_blank_lines; /* Files can be compared byte-by-byte, as if they were binary. This depends on various options. */ -DIFF_EXTERN (bool files_can_be_treated_as_binary); +extern bool files_can_be_treated_as_binary; /* Ignore differences in case of letters (-i). */ -DIFF_EXTERN (bool ignore_case); +extern bool ignore_case; /* Ignore differences in case of letters in file names. */ -DIFF_EXTERN (bool ignore_file_name_case); +extern bool ignore_file_name_case; /* Act on symbolic links themselves rather than on their target (--no-dereference). */ -DIFF_EXTERN (bool no_dereference_symlinks); +extern bool no_dereference_symlinks; /* Local timezone for 'c' output headers, if needed. */ #if HAVE_TM_GMTOFF # define localtz 0 /* Placeholder since localtz is never needed. */ #else -DIFF_EXTERN (timezone_t localtz); +extern timezone_t localtz; #endif /* File labels for '-c' output headers (--label). */ -DIFF_EXTERN (char *file_label[2]); +extern char *file_label[2]; /* Regexp to identify function-header lines (-F). */ -DIFF_EXTERN (struct re_pattern_buffer function_regexp); +extern struct re_pattern_buffer function_regexp; /* Ignore changes that affect only lines matching this regexp (-I). */ -DIFF_EXTERN (struct re_pattern_buffer ignore_regexp); +extern struct re_pattern_buffer ignore_regexp; /* Say only whether files differ, not how (-q). */ -DIFF_EXTERN (bool brief); +extern bool brief; /* Expand tabs in the output so the text lines up properly despite the characters added to the front of each line (-t). */ -DIFF_EXTERN (bool expand_tabs); +extern bool expand_tabs; /* Number of columns between tab stops. */ -DIFF_EXTERN (intmax_t tabsize); +extern intmax_t tabsize; /* Use a tab in the output, rather than a space, before the text of an input line, so as to keep the proper alignment in the input line without changing the characters in it (-T). */ -DIFF_EXTERN (bool initial_tab); +extern bool initial_tab; /* Do not output an initial space or tab before the text of an empty line. */ -DIFF_EXTERN (bool suppress_blank_empty); +extern bool suppress_blank_empty; /* Remove trailing carriage returns from input. */ -DIFF_EXTERN (bool strip_trailing_cr); +extern bool strip_trailing_cr; /* In directory comparison, specify file to start with (-S). This is used for resuming an aborted comparison. All file names less than this name are ignored. */ -DIFF_EXTERN (char const *starting_file); +extern char const *starting_file; /* Pipe each file's output through pr (-l). */ -DIFF_EXTERN (bool paginate); +extern bool paginate; /* Line group formats for unchanged, old, new, and changed groups. */ -DIFF_EXTERN (char const *group_format[CHANGED + 1]); +extern char const *group_format[CHANGED + 1]; /* Line formats for unchanged, old, and new lines. */ -DIFF_EXTERN (char const *line_format[NEW + 1]); +extern char const *line_format[NEW + 1]; /* If using OUTPUT_SDIFF print extra information to help the sdiff filter. */ -DIFF_EXTERN (bool sdiff_merge_assist); +extern bool sdiff_merge_assist; /* Tell OUTPUT_SDIFF to show only the left version of common lines. */ -DIFF_EXTERN (bool left_column); +extern bool left_column; /* Tell OUTPUT_SDIFF to not show common lines. */ -DIFF_EXTERN (bool suppress_common_lines); +extern bool suppress_common_lines; /* The half line width and column 2 offset for OUTPUT_SDIFF. */ -DIFF_EXTERN (intmax_t sdiff_half_width); -DIFF_EXTERN (intmax_t sdiff_column2_offset); +extern intmax_t sdiff_half_width; +extern intmax_t sdiff_column2_offset; /* String containing all the command options diff received, with spaces between and at the beginning but none at the end. If there were no options given, this string is empty. */ -DIFF_EXTERN (char *switch_string); +extern char *switch_string; /* Use heuristics for better speed with large files with a small density of changes. */ -DIFF_EXTERN (bool speed_large_files); +extern bool speed_large_files; /* Patterns that match file names to be excluded. */ -DIFF_EXTERN (struct exclude *excluded); +extern struct exclude *excluded; /* Don't discard lines. This makes things slower (sometimes much slower) but will find a guaranteed minimal set of changes. */ -DIFF_EXTERN (bool minimal); +extern bool minimal; /* The strftime format to use for time strings. */ -DIFF_EXTERN (char const *time_format); +extern char const *time_format; /* The result of comparison is an "edit script": a chain of 'struct change'. Each 'struct change' represents one place where some lines are deleted @@ -383,18 +380,18 @@ struct comparison /* Describe the two files currently being compared. */ -DIFF_EXTERN (struct comparison curr); +extern struct comparison curr; /* A placeholder for the parent of the top level comparison. Only the desc slots are used; although they are typically AT_FDCWD, one might be nonnegative for a directory at the top level for 'diff DIR FILE' or 'diff FILE DIR'. */ -DIFF_EXTERN (struct comparison noparent); +extern struct comparison noparent; /* Stdio stream to output diffs to. */ -DIFF_EXTERN (FILE *outfile); +extern FILE *outfile; /* Declare various functions. */ @@ -472,7 +469,7 @@ enum color_context LINE_NUMBER_CONTEXT, }; -DIFF_EXTERN (bool presume_output_tty); +extern bool presume_output_tty; extern void set_color_context (enum color_context color_context); extern void set_color_palette (char const *palette); diff --git a/src/diff3.c b/src/diff3.c index b9935c2..19aa317 100644 --- a/src/diff3.c +++ b/src/diff3.c @@ -24,7 +24,6 @@ # pragma GCC diagnostic ignored "-Wanalyzer-null-dereference" #endif -#define SYSTEM_INLINE _GL_EXTERN_INLINE #include "system.h" #include "paths.h" diff --git a/src/sdiff.c b/src/sdiff.c index 9f58d79..666f15e 100644 --- a/src/sdiff.c +++ b/src/sdiff.c @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#define SYSTEM_INLINE _GL_EXTERN_INLINE #include "system.h" #include "paths.h" diff --git a/src/system.c b/src/system.c new file mode 100644 index 0000000..7a37494 --- /dev/null +++ b/src/system.c @@ -0,0 +1,30 @@ +/* System dependent declarations. + + Copyright 2024 Free Software Foundation, Inc. + + This file is part of GNU DIFF. + + 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 <http://www.gnu.org/licenses/>. */ + +#define SYSTEM_INLINE _GL_EXTERN_INLINE +#include "system.h" + +/* Define variables declared in system.h (which see). */ +#if (defined __linux__ || defined __CYGWIN__ || defined __FreeBSD__ \ + || defined __NetBSD__ || defined _AIX) +dev_t proc_dev; +#endif +#if care_about_symlink_size && (defined __linux__ || defined __ANDROID__) +signed char symlink_size_ok; +#endif diff --git a/src/system.h b/src/system.h index 370f654..9853e2e 100644 --- a/src/system.h +++ b/src/system.h @@ -97,17 +97,14 @@ # define dassert(e) assume (e) #endif -#ifdef SYSTEM_INLINE -# define SYSTEM_EXTERN(decl) extern decl; decl -# else -# define SYSTEM_EXTERN(decl) extern decl +#ifndef SYSTEM_INLINE # define SYSTEM_INLINE _GL_INLINE #endif #if (defined __linux__ || defined __CYGWIN__ || defined __FreeBSD__ \ || defined __NetBSD__ || defined _AIX) /* The device number of the /proc file system if known; zero otherwise. */ -SYSTEM_EXTERN (dev_t proc_dev); +extern dev_t proc_dev; #endif /* Use this for code that could be used if diff ever cares about @@ -117,7 +114,7 @@ SYSTEM_EXTERN (dev_t proc_dev); #if care_about_symlink_size && (defined __linux__ || defined __ANDROID__) # include <sys/utsname.h> /* 1 if symlink st_size is OK, -1 if not, 0 if unknown yet. */ -SYSTEM_EXTERN (signed char symlink_size_ok); +extern signed char symlink_size_ok; #endif _GL_INLINE_HEADER_BEGIN -- 2.45.0