* gnulib-local/lib/gcc-function-attributes.h: New header file, providing macros to allow portable use of GCC function attributes. * gnulib-local/modules/gcc-attributes: New (local) module. * bootstrap.conf (local_gl_dir): Set local_gl_dir so that we can use our new module. Use the gcc-attributes module. * find/defs.h: Include gcc-function-attributes.h. Delete our local macro ATTRIBUTE_NORETURN and use the one from the header file. * find/parser.c: Include gcc-function-attributes.h. Add _GL_ATTRIBUTE_NORETURN to parse_help, parse_version and pred_quit. * find/print.c (checked_fprintf): add attribute _GL_ATTRIBUTE_FORMAT_PRINTF to the function declaration. --- bootstrap.conf | 2 + find/defs.h | 19 +-- find/parser.c | 15 +- find/print.c | 5 +- gnulib-local/lib/gcc-function-attributes.h | 233 +++++++++++++++++++++++++++++ gnulib-local/modules/gcc-attributes | 14 ++ 6 files changed, 274 insertions(+), 14 deletions(-) create mode 100644 gnulib-local/lib/gcc-function-attributes.h create mode 100644 gnulib-local/modules/gcc-attributes
diff --git a/bootstrap.conf b/bootstrap.conf index d85eb97..bcdc723 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -99,6 +99,7 @@ gnulib_modules=" fnmatch-gnu fopen-safer fts + gcc-attributes getdelim getline getopt-gnu @@ -181,6 +182,7 @@ gnulib_modules=" # Override bootstrap's defaults, with values consistent with # 'import-gnulib.sh' +local_gl_dir='gnulib-local' source_base=gl/lib m4_base=gl/m4 # use 'libgnulib' instead of the default lib$package (=libfindutils) diff --git a/find/defs.h b/find/defs.h index 2894455..a4647e8 100644 --- a/find/defs.h +++ b/find/defs.h @@ -63,14 +63,7 @@ Please stop compiling the program now #include "buildcmd.h" #include "quotearg.h" #include "sharefile.h" - -#ifndef ATTRIBUTE_NORETURN -# if HAVE_ATTRIBUTE_NORETURN -# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) -# else -# define ATTRIBUTE_NORETURN /* nothing */ -# endif -#endif +#include "gcc-function-attributes.h" int optionl_stat (const char *name, struct stat *p); int optionp_stat (const char *name, struct stat *p); @@ -399,6 +392,7 @@ bool parse_closeparen (const struct parser_table* entry, char *argv[], int *arg_ /* pred.c */ typedef bool PREDICATEFUNCTION(const char *pathname, struct stat *stat_buf, struct predicate *pred_ptr); + PREDICATEFUNCTION pred_amin; PREDICATEFUNCTION pred_and; PREDICATEFUNCTION pred_anewer; @@ -445,7 +439,6 @@ PREDICATEFUNCTION pred_perm; PREDICATEFUNCTION pred_print; PREDICATEFUNCTION pred_print0; PREDICATEFUNCTION pred_prune; -PREDICATEFUNCTION pred_quit; PREDICATEFUNCTION pred_readable; PREDICATEFUNCTION pred_regex; PREDICATEFUNCTION pred_samefile; @@ -460,6 +453,10 @@ PREDICATEFUNCTION pred_xtype; PREDICATEFUNCTION pred_context; +bool pred_quit (const char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) + _GL_ATTRIBUTE_NORETURN; + + char *find_pred_name (PRED_FUNC pred_func); @@ -494,8 +491,8 @@ const char *safely_quote_err_filename (int n, char const *arg); void record_initial_cwd (void); bool is_exec_in_local_dir(const PRED_FUNC pred_func); -void fatal_target_file_error (int errno_value, const char *name) ATTRIBUTE_NORETURN; -void fatal_nontarget_file_error (int errno_value, const char *name) ATTRIBUTE_NORETURN; +void fatal_target_file_error (int errno_value, const char *name) _GL_ATTRIBUTE_NORETURN; +void fatal_nontarget_file_error (int errno_value, const char *name) _GL_ATTRIBUTE_NORETURN; void nonfatal_target_file_error (int errno_value, const char *name); void nonfatal_nontarget_file_error (int errno_value, const char *name); diff --git a/find/parser.c b/find/parser.c index 7c75f2d..a8bdc81 100644 --- a/find/parser.c +++ b/find/parser.c @@ -52,6 +52,15 @@ #include "xstrtod.h" #include "xstrtol.h" +/* At the moment, we include this after gnulib headers, since it uses + some of the same names for function attribute macros as gnulib does, + since I plan to make gcc-sttrigbutes a gnulib module. However, for + now, I haven't made the wholesale edits to gnulib that this would + require. Including this file last simply minimises the number of + compiler warnings about macro redefinition (in gnulib headers). +*/ +#include "gcc-function-attributes.h" + /* find headers. */ #include "buildcmd.h" #include "defs.h" @@ -104,7 +113,6 @@ static bool parse_fprint0 (const struct parser_table*, char *argv[], int * static bool parse_fstype (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_gid (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_group (const struct parser_table*, char *argv[], int *arg_ptr); -static bool parse_help (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_ilname (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_iname (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_inum (const struct parser_table*, char *argv[], int *arg_ptr); @@ -143,7 +151,6 @@ static bool parse_type (const struct parser_table*, char *argv[], int * static bool parse_uid (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_used (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_user (const struct parser_table*, char *argv[], int *arg_ptr); -static bool parse_version (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_wholename (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_xdev (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_ignore_race (const struct parser_table*, char *argv[], int *arg_ptr); @@ -156,6 +163,10 @@ static bool parse_context (const struct parser_table*, char *argv[], int * static bool parse_show_control_chars (const struct parser_table*, char *argv[], int *arg_ptr); #endif +static bool parse_help (const struct parser_table* entry, char **argv, int *arg_ptr) + _GL_ATTRIBUTE_NORETURN; +static bool parse_version (const struct parser_table*, char *argv[], int *arg_ptr) + _GL_ATTRIBUTE_NORETURN; static bool insert_type (char **argv, int *arg_ptr, diff --git a/find/print.c b/find/print.c index e4c28ad..05a8ebd 100644 --- a/find/print.c +++ b/find/print.c @@ -70,6 +70,8 @@ #undef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) +static void checked_fprintf (struct format_val *dest, const char *fmt, ...) _GL_ATTRIBUTE_FORMAT_PRINTF(2, 3); + /* Create a new fprintf segment in *SEGMENT, with type KIND, from the text in FORMAT, which has length LEN. @@ -802,6 +804,7 @@ file_sparseness (const struct stat *p) } } + static void checked_fprintf (struct format_val *dest, const char *fmt, ...) { @@ -816,7 +819,7 @@ checked_fprintf (struct format_val *dest, const char *fmt, ...) static void checked_print_quoted (struct format_val *dest, - const char *format, const char *s) + const char *format, const char *s) { int rv = print_quoted (dest->stream, dest->quote_opts, dest->dest_is_tty, format, s); diff --git a/gnulib-local/lib/gcc-function-attributes.h b/gnulib-local/lib/gcc-function-attributes.h new file mode 100644 index 0000000..05a119e --- /dev/null +++ b/gnulib-local/lib/gcc-function-attributes.h @@ -0,0 +1,233 @@ +/* gcc-function-attribtues.h -- GCC-specific function attributes + + Copyright (C) 2016 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 <http://www.gnu.org/licenses/>. +*/ + +/* + Be aware that some function attributes do not work with function + pointers. See + http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00007.html + for details. +*/ +#ifndef _GCC_FUNCTION_ATTRIBUTES_H +#define _GCC_FUNCTION_ATTRIBUTES_H + +#ifndef __GNUC_PREREQ +# if defined __GNUC__ && defined __GNUC_MINOR__ +# define __GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +# else +# define __GNUC_PREREQ(maj, min) 0 +# endif +#endif + +/* +The following attributes are currently (GCC-4.4.5) defined for +functions on all targets. Where this file provides a macro +for using it, the macro name is given in the second column. + +Attribute Macro (if implemented in this file) +------------------------------------------------------------------------------- +alias +aligned +alloc_size _GL_ATTRIBUTE_ALLOC_SIZE(arg_num) +always_inline +artificial +cold +const +constructor +deprecated _GL_ATTRIBUTE_DEPRECATED +destructor +error +externally_visible +flatten +format _GL_ATTRIBUTE_FORMAT(spec) + _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(fmt,firstarg) + _GL_ATTRIBUTE_FORMAT_PRINTF(fmt,firstarg) + _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(fmt,firstarg) + _GL_ATTRIBUTE_FORMAT_SCANF(fmt,firstarg) +format_arg +gnu_inline +hot +malloc _GL_ATTRIBUTE_MALLOC +no_instrument_function +noinline +nonnull _GL_ATTRIBUTE_NONNULL(args) + _GL_ARG_NONNULL(args) +noreturn _GL_ATTRIBUTE_NORETURN +nothrow +pure _GL_ATTRIBUTE_PURE +returns_twice +section +sentinel _GL_ATTRIBUTE_SENTINEL +unused +used +warn_unused_result _GL_ATTRIBUTE_WUR +warning +weak +*/ + +/* +Attributes used in gnulib, but which appear to be platform-specific +regparm +stdcall +*/ + +/* +Attributes used in gnulib with special arguments +Macro Args +visibility "default" +*/ + +/* + The __attribute__ feature is available in gcc versions 2.5 and later. + The underscored __format__ spelling of the attribute names requires 2.6.4 (we check for 2.7). +*/ + + +#ifndef _GL_ATTRIBUTE_ALLOC_SIZE +# if __GNUC_PREREQ(4,3) +# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args)) +# else +# define _GL_ATTRIBUTE_ALLOC_SIZE(args) /* unsupported */ +# endif +#endif + +#ifndef _GL_ATTRIBUTE_DEPRECATED +# if __GNUC_PREREQ(3,1) +# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__)) +# else +# define _GL_ATTRIBUTE_DEPRECATED /* empty */ +# endif +#endif + +#ifndef _GL_ATTRIBUTE_FORMAT +# if __GNUC_PREREQ(2,7) +# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) +# else +# define _GL_ATTRIBUTE_FORMAT(spec) /* unsupported */ +# endif +#endif + +#ifndef _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM +# if __GNUC_PREREQ(2,7) +# define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) +# else +# define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(spec) /* unsupported */ +# endif +#endif + +#ifndef _GL_ATTRIBUTE_FORMAT_PRINTF +# if __GNUC_PREREQ(2,7) +# if __GNUC_PREREQ(4,4) +# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument)) +# else +# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) +# endif +# else +# define _GL_ATTRIBUTE_FORMAT_PRINTF(spec) /* unsupported */ +# endif +#endif + +#ifndef _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM +# if __GNUC_PREREQ(2,7) +# define _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument)) +# else +# define _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(spec) /* unsupported */ +# endif +#endif + +#ifndef _GL_ATTRIBUTE_FORMAT_SCANF +# if __GNUC_PREREQ(2,7) +# if __GNUC_PREREQ(4,4) +# define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__gnu_scanf__, formatstring_parameter, first_argument)) +# else +# define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument)) +# endif +# else +# define _GL_ATTRIBUTE_FORMAT_SCANF(spec) /* unsupported */ +# endif +#endif + +#ifndef _GL_ATTRIBUTE_MALLOC +# if __GNUC_PREREQ(3,0) +# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) +# else +# define _GL_ATTRIBUTE_MALLOC /* unsupported */ +# endif +#endif + + +#ifndef _GL_ATTRIBUTE_NONNULL +# if __GNUC_PREREQ(3,3) +# define _GL_ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m))) +# else +# define _GL_ATTRIBUTE_NONNULL(m) /* unsupported */ +# endif +#endif +#ifndef _GL_ARG_NONNULL +/* alternative spelling used in gnulib's stdio.h */ +# define _GL_ARG_NONNULL(m) _GL_ATTRIBUTE_NONNULL(m) +#endif + + +#ifndef _GL_ATTRIBUTE_NORETURN +# if __GNUC_PREREQ(2,8) +# define _GL_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) +# else +# define _GL_ATTRIBUTE_NORETURN /* unsupported */ +# endif +#endif + +#ifndef _GL_ATTRIBUTE_PURE +# if __GNUC_PREREQ(2,96) +# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define _GL_ATTRIBUTE_PURE /* unsupported */ +# endif +#endif + +#ifndef _GL_ATTRIBUTE_SENTINEL +# if __GNUC_PREREQ(4,0) + /* gnulib uses the __attribute__((__sentinel__)) variant, for which the + argument number 0 is assumed. Arguments are counted backwards, the last + being 0. + */ +# define _GL_ATTRIBUTE_SENTINEL(backward_arg_num) __attribute__ ((__sentinel__(backward_arg_num))) +# else +# define _GL_ATTRIBUTE_SENTINEL(backward_arg_num) /* unsupported */ +# endif +#endif + +#ifndef _GL_ATTRIBUTE_WUR +# if __GNUC_PREREQ(3,4) +# define _GL_ATTRIBUTE_WUR __attribute__ ((__warn__unused_result__)) +# else +# define _GL_ATTRIBUTE_WUR /* unsupported */ +# endif +#endif +#ifndef _GL_ATTRIBUTE_RETURN_CHECK +/* gnulib is inconsistent in which macro it uses; support both for now. */ +# define _GL_ATTRIBUTE_RETURN_CHECK _GL_ATTRIBUTE_WUR +#endif + +#endif /* _GCC_FUNCTION_ATTRIBUTES_H */ diff --git a/gnulib-local/modules/gcc-attributes b/gnulib-local/modules/gcc-attributes new file mode 100644 index 0000000..b63c2f8 --- /dev/null +++ b/gnulib-local/modules/gcc-attributes @@ -0,0 +1,14 @@ +Description: +Macros allowing portable use of GCC's __attribute__ feature. + +Files: +lib/gcc-function-attributes.h + +Include: +"lib/gcc-function-attributes.h" + +License: +GPL + +Maintainer: +James Youngman -- 2.1.4