maint.mk: Prohibit inclusion of "xalloc.h" without use.
authorJim Meyering <meyering@redhat.com>
Sat, 14 Nov 2009 08:53:26 +0000 (09:53 +0100)
committerJim Meyering <meyering@redhat.com>
Sat, 14 Nov 2009 08:53:26 +0000 (09:53 +0100)
* top/maint.mk (sc_prohibit_close_stream_without_use): New rule.

ChangeLog
top/maint.mk

index e23f285..c821d8d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-11-14  Jim Meyering  <meyering@redhat.com>
+
+       maint.mk: Prohibit inclusion of "xalloc.h" without use.
+       * top/maint.mk (sc_prohibit_close_stream_without_use): New rule.
+
 2009-11-14  John W. Eaton  <jwe@gnu.org>
 
        strftime.h: wrap funtion declaration in extern "C" block
index 73ea8ea..34d66e1 100644 (file)
@@ -289,6 +289,23 @@ sc_prohibit_error_without_use:
        re='\<error(_at_line|_print_progname|_one_per_line|_message_count)? *\('\
          $(_header_without_use)
 
+# Don't include xalloc.h unless you use one of its functions.
+# Consider these symbols:
+# perl -lne '/^# *define (\w+)\(/ and print $1' lib/xalloc.h|grep -v '^__';
+# perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) \(/ and print $1' lib/xalloc.h
+# Divide into two sets on case, and filter each through this:
+# | sort | perl -MRegexp::Assemble -le \
+#  'print Regexp::Assemble->new(file => "/dev/stdin")->as_string'|sed 's/\?://g'
+# Note this was produced by the above:
+# _xa1 = x(alloc_(oversized|die)|([cz]|2?re)alloc|m(alloc|emdup)|strdup)
+# But we can do better:
+_xa1 = x(alloc_(oversized|die)|([cmz]|2?re)alloc|(mem|str)dup)
+_xa2 = X([CZ]|N?M)ALLOC
+sc_prohibit_xalloc_without_use:
+       @h='"xalloc.h"' \
+       re='\<($(_xa1)|$(_xa2)) *\('\
+         $(_header_without_use)
+
 sc_prohibit_safe_read_without_use:
        @h='"safe-read.h"' re='(\<SAFE_READ_ERROR\>|\<safe_read *\()' \
          $(_header_without_use)