bug-gnulib
[Top][All Lists]
Advanced

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

Re: string.h uses restrict


From: Jim Meyering
Subject: Re: string.h uses restrict
Date: Tue, 07 Apr 2009 10:56:50 +0200

Reuben Thomas wrote:
> On Tue, 7 Apr 2009, Jim Meyering wrote:
>> Ok.  Post "git format-patch ..." output and I'll push it,
>> unless someone objects in the mean time.
>
> Attached. Let me know if I did something wrong.
>
> (Copyright assignment: I'm assuming that since I didn't write any of
> this, but just made trivial changes, it's not a problem. I have in any
> case requested an assignment which was apparently mailed on 19th March
> but hasn't reached me in the UK yet.)
>
> From ce5497a2c9fd85cfa14226d5fb814786d0b44fcf Mon Sep 17 00:00:00 2001
> From: Reuben Thomas <address@hidden>
> Date: Tue, 7 Apr 2009 09:05:47 +0100
> Subject: [PATCH] 
> =?utf-8?q?Import=20some=20changes=20to=20syntax=20check=20macros=20from=20coreutils=E2=80=99s=20maint.mk.?=
> MIME-Version: 1.0
> Content-Type: text/plain; charset=utf-8
> Content-Transfer-Encoding: 8bit
>
> Add _prohibit_regexp and _header_without_use, and use them in the
> relevant macros.

Thanks. just nits.
  - your summary/subject was needlessly utf8-encoded.
      That makes it harder to read.
  - use the file or module name as the first word on the summary line
  - use ChangeLog-style "* full-relative-name/to-each-affected-file
  (func,rule,etc.): description..." in the log, because that is what
  goes into the ChangeLog for gnulib.  In coreutils, the log is the
  primary source, and ChangeLog is automatically generated from that.
  In gnulib, we don't all agree on policy, so we retain use of a VC'd
  ChangeLog, and here, my ChangeLog entries are identical (modulo the
  leading TABs which are in the file but not in log).  When sending in
  "git format-patch" patches, I prefer *not* to have ChangeLog diffs,
  because they're very likely not to apply.  Instead, when I pull
  a change from a private branch onto master, just prior to pushing,
  I automatically convert the log entry into a ChangeLog entry, and
  then use "git commit --amend ChangeLog" to make that part of the
  commit I'm about to push.

So here's what I'll push shortly.
The code changes are identical to yours.

>From 47e938da5594035e3b049a77fe481bd9b7762bfc Mon Sep 17 00:00:00 2001
From: Reuben Thomas <address@hidden>
Date: Tue, 7 Apr 2009 09:05:47 +0100
Subject: [PATCH] maint.mk: import changes to syntax-check macros from coreutils

* top/maint.mk (_prohibit_regexp, _header_without_use): Define.
Use them in the relevant macros.
---
 top/maint.mk |   70 ++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/top/maint.mk b/top/maint.mk
index 3177d57..3390e7b 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -38,34 +38,42 @@ GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
 export LC_ALL = C

+# There are many rules below that prohibit constructs in this package.
+# If the offending construct can be matched with a grep-E-style regexp,
+# use this macro.  The shell variables "re" and "msg" must be defined.
+define _prohibit_regexp
+  dummy=; : so we do not need a semicolon before each use;             \
+  test "x$$re" != x || { echo '$(ME): re not defined' 1>&2; exit 1; }; \
+  test "x$$msg" != x || { echo '$(ME): msg not defined' 1>&2; exit 1; };\
+  grep $(_ignore_case) -nE "$$re" $(C_SOURCES) &&                      \
+    { echo '$(ME): '"$$msg" 1>&2; exit 1; } || :
+endef
+
 # Casting arguments to free is never necessary.
 sc_cast_of_argument_to_free:
-       @grep -nE '\<free *\( *\(' $(C_SOURCES) &&                      \
-         { echo '$(ME): don'\''t cast free argument' 1>&2;             \
-           exit 1; } || :
+       @re='\<free *\( *\(' msg='don'\''t cast free argument'          \
+         $(_prohibit_regexp)

 sc_cast_of_x_alloc_return_value:
-       @grep -nE '\*\) *x(m|c|re)alloc\>' $(C_SOURCES) &&              \
-         { echo '$(ME): don'\''t cast x*alloc return value' 1>&2;      \
-           exit 1; } || :
+       @re='\*\) *x(m|c|re)alloc\>'                                    \
+       msg='don'\''t cast x*alloc return value'                        \
+         $(_prohibit_regexp)

 sc_cast_of_alloca_return_value:
-       @grep -nE '\*\) *alloca\>' $(C_SOURCES) &&                      \
-         { echo '$(ME): don'\''t cast alloca return value' 1>&2;       \
-           exit 1; } || :
+       @re='\*\) *alloca\>' msg='don'\''t cast alloca return value'    \
+         $(_prohibit_regexp)

 sc_space_tab:
-       @grep -n '[ ]   ' $(C_SOURCES) &&                               \
-         { echo '$(ME): found SPACE-TAB sequence; remove the SPACE'    \
-               1>&2; exit 1; } || :
+       @re='[ ]        ' msg='found SPACE-TAB sequence; remove the SPACE' \
+         $(_prohibit_regexp)

-# Don't use the old ato* functions in `real' code.
+# Don't use *scanf or the old ato* functions in `real' code.
 # They provide no error checking mechanism.
 # Instead, use strto* functions.
 sc_prohibit_atoi_atof:
-       @grep -nE '\<ato([filq]|ll)\>' $(C_SOURCES) &&                  \
-         { echo '$(ME): do not use ato''f, ato''i, ato''l, ato''ll, or ato''q' 
\
-               1>&2; exit 1; } || :
+       @re='\<([fs]?scanf|ato([filq]|ll)) *\('                         \
+       msg='do not use *scan''f, ato''f, ato''i, ato''l, ato''ll or ato''q' \
+         $(_prohibit_regexp)

 # Using EXIT_SUCCESS as the first argument to error is misleading,
 # since when that parameter is 0, error does not exit.  Use `0' instead.
@@ -80,21 +88,31 @@ sc_no_if_have_config_h:
          { echo '$(ME): found use of #if HAVE_CONFIG_H; use #ifdef'    \
                1>&2; exit 1; } || :

+# To use this "command" macro, you must first define two shell variables:
+# h: the header, enclosed in <> or ""
+# re: a regular expression that matches IFF something provided by $h is used.
+define _header_without_use
+  h_esc=`echo "$$h"|sed 's/\./\\./g'`;                                 \
+  if $(C_SOURCES) | grep -l '\.c$$' > /dev/null; then                  \
+    files=$$(grep -l '^# *include '"$$h_esc"                           \
+            $$($(C_SOURCES) | grep '\.c$$')) &&                        \
+    grep -LE "$$re" $$files | grep . &&                                        
\
+      { echo "$(ME): the above files include $$h but don't use it"     \
+       1>&2; exit 1; } || :;                                           \
+  else :;                                                              \
+  fi
+endef
+
 # Prohibit the inclusion of assert.h without an actual use of assert.
 sc_prohibit_assert_without_use:
-       @files=$$(grep -l '# *include [<"]assert\.h[>"]' $(C_SOURCES)   \
-                       | grep '\.[cy]$$') &&                           \
-       grep -L '\<assert (' $$files                                    \
-           | grep . &&                                                 \
-         { echo "$(ME): the above files include <assert.h> but don't use it" \
-               1>&2; exit 1; } || :
+       @h='<assert.h>' re='\<assert *\(' $(_header_without_use)

 sc_obsolete_symbols:
-       @grep -nE '\<(HAVE''_FCNTL_H|O''_NDELAY)\>' $(C_SOURCES) &&     \
-         { echo '$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY'       \
-               1>&2; exit 1; } || :
+       @re='\<(HAVE''_FCNTL_H|O''_NDELAY)\>'                           \
+       msg='do not use HAVE''_FCNTL_H or O'_NDELAY                     \
+         $(_prohibit_regexp)

-# Each nonempty line must start with a year number, or a TAB.
+# Each nonempty ChangeLog line must start with a year number, or a TAB.
 sc_changelog:
        @grep -n '^[^12 ]' $$(find . -name ChangeLog) &&        \
          { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2;  \
--
1.6.2.rc1.285.gc5f54




reply via email to

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