From: Eric Blake Date: Sat, 30 Jan 2010 15:51:59 +0000 (-0700) Subject: sys_time: use link-warning X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34deb3471655d57d311749b68d194ceee0081898;p=pspp sys_time: use link-warning Modernize replacement header, to allow another GNULIB_POSIXCHECK opportunity. * m4/sys_time_h.m4 (gl_HEADER_SYS_TIME_H_BODY): Split defaults... (gl_HEADER_SYS_TIME_H_DEFAULTS): ...into new macro. (gl_SYS_TIME_MODULE_INDICATOR): New macro. * modules/sys_time (Depends-on): Add warn-on-use. (Makefile.am): Always build replacement. (configure.ac): Update substitutions. * m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY) (gl_FUNC_GETTIMEOFDAY_CLOBBER): Include defaults, and no longer bother with SYS_TIME_H. * modules/gettimeofday (configure.ac): Declare indicator. * lib/sys_time.in.h (gettimeofday): Warn if gnulib module is not in use. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index a81223454d..b89d1273e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2010-02-01 Eric Blake + sys_time: use link-warning + * m4/sys_time_h.m4 (gl_HEADER_SYS_TIME_H_BODY): Split defaults... + (gl_HEADER_SYS_TIME_H_DEFAULTS): ...into new macro. + (gl_SYS_TIME_MODULE_INDICATOR): New macro. + * modules/sys_time (Depends-on): Add warn-on-use. + (Makefile.am): Always build replacement. + (configure.ac): Update substitutions. + * m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY) + (gl_FUNC_GETTIMEOFDAY_CLOBBER): Include defaults, and no longer + bother with SYS_TIME_H. + * modules/gettimeofday (configure.ac): Declare indicator. + * lib/sys_time.in.h (gettimeofday): Warn if gnulib module is not + in use. + closein-tests: silence compiler warning * tests/test-closein.c (main): Ignore fread result. * modules/closein-tests (Depends-on): Add ignore-value. diff --git a/lib/sys_time.in.h b/lib/sys_time.in.h index 442cae3270..12f0860be6 100644 --- a/lib/sys_time.in.h +++ b/lib/sys_time.in.h @@ -41,6 +41,8 @@ /* The definition of _GL_ARG_NONNULL is copied here. */ +/* The definition of _GL_WARN_ON_USE is copied here. */ + #ifdef __cplusplus extern "C" { #endif @@ -53,11 +55,19 @@ struct timeval }; # endif -# if @REPLACE_GETTIMEOFDAY@ -# undef gettimeofday -# define gettimeofday rpl_gettimeofday +# if @GNULIB_GETTIMEOFDAY@ +# if @REPLACE_GETTIMEOFDAY@ +# undef gettimeofday +# define gettimeofday rpl_gettimeofday extern int gettimeofday (struct timeval *restrict, void *restrict) _GL_ARG_NONNULL ((1)); +# endif +# elif defined GNULIB_POSIXCHECK +# undef gettimeofday +# if HAVE_RAW_DECL_GETTIMEOFDAY +_GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - " + "use gnulib module gettimeofday for portability"); +# endif # endif #ifdef __cplusplus diff --git a/m4/gettimeofday.m4 b/m4/gettimeofday.m4 index 735123e6dc..21556272ad 100644 --- a/m4/gettimeofday.m4 +++ b/m4/gettimeofday.m4 @@ -1,4 +1,4 @@ -# serial 12 +# serial 13 # Copyright (C) 2001-2003, 2005, 2007, 2009-2010 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY], [ AC_REQUIRE([AC_C_RESTRICT]) AC_REQUIRE([gl_HEADER_SYS_TIME_H]) + AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) AC_CHECK_FUNCS_ONCE([gettimeofday]) AC_CACHE_CHECK([for gettimeofday with POSIX signature], @@ -32,7 +33,6 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY], if test $gl_cv_func_gettimeofday_posix_signature != yes; then REPLACE_GETTIMEOFDAY=1 - SYS_TIME_H=sys/time.h if test $gl_cv_func_gettimeofday_clobber != yes; then AC_LIBOBJ([gettimeofday]) gl_PREREQ_GETTIMEOFDAY @@ -78,7 +78,6 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER], if test $gl_cv_func_gettimeofday_clobber = yes; then REPLACE_GETTIMEOFDAY=1 - SYS_TIME_H=sys/time.h gl_GETTIMEOFDAY_REPLACE_LOCALTIME AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1], [Define if gettimeofday clobbers the localtime buffer.]) diff --git a/m4/sys_time_h.m4 b/m4/sys_time_h.m4 index 9c16487957..b14bc4ba2b 100644 --- a/m4/sys_time_h.m4 +++ b/m4/sys_time_h.m4 @@ -1,5 +1,5 @@ # Configure a replacement for . -# serial 2 +# serial 3 # Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -19,15 +19,13 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H], AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY], [ AC_REQUIRE([AC_C_RESTRICT]) + AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) AC_CHECK_HEADERS_ONCE([sys/time.h]) gl_CHECK_NEXT_HEADERS([sys/time.h]) - if test $ac_cv_header_sys_time_h = yes; then - HAVE_SYS_TIME_H=1 - else + if test $ac_cv_header_sys_time_h != yes; then HAVE_SYS_TIME_H=0 fi - AC_SUBST([HAVE_SYS_TIME_H]) AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval], [AC_COMPILE_IFELSE( @@ -40,20 +38,32 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY], [[static struct timeval x; x.tv_sec = x.tv_usec;]])], [gl_cv_sys_struct_timeval=yes], [gl_cv_sys_struct_timeval=no])]) - if test $gl_cv_sys_struct_timeval = yes; then - HAVE_STRUCT_TIMEVAL=1 - else + if test $gl_cv_sys_struct_timeval != yes; then HAVE_STRUCT_TIMEVAL=0 fi - AC_SUBST([HAVE_STRUCT_TIMEVAL]) + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ +#if HAVE_SYS_TIME_H +# include +#endif +#include + ]], [gettimeofday]) +]) + +AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) + GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 +]) + +AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS], +[ + GNULIB_GETTIMEOFDAY=0; AC_SUBST([GNULIB_GETTIMEOFDAY]) dnl Assume POSIX behavior unless another module says otherwise. - REPLACE_GETTIMEOFDAY=0 - AC_SUBST([REPLACE_GETTIMEOFDAY]) - if test $HAVE_SYS_TIME_H = 0 || test $HAVE_STRUCT_TIMEVAL = 0; then - SYS_TIME_H=sys/time.h - else - SYS_TIME_H= - fi - AC_SUBST([SYS_TIME_H]) + HAVE_STRUCT_TIMEVAL=1; AC_SUBST([HAVE_STRUCT_TIMEVAL]) + HAVE_SYS_TIME_H=1; AC_SUBST([HAVE_SYS_TIME_H]) + REPLACE_GETTIMEOFDAY=0; AC_SUBST([REPLACE_GETTIMEOFDAY]) ]) diff --git a/modules/gettimeofday b/modules/gettimeofday index 0913cf1e8b..979f601d07 100644 --- a/modules/gettimeofday +++ b/modules/gettimeofday @@ -10,6 +10,7 @@ sys_time configure.ac: gl_FUNC_GETTIMEOFDAY +gl_SYS_TIME_MODULE_INDICATOR([gettimeofday]) Makefile.am: diff --git a/modules/sys_time b/modules/sys_time index f0789e5890..28d902eb9e 100644 --- a/modules/sys_time +++ b/modules/sys_time @@ -8,17 +8,18 @@ m4/sys_time_h.m4 Depends-on: include_next arg-nonnull +warn-on-use configure.ac: gl_HEADER_SYS_TIME_H AC_PROG_MKDIR_P Makefile.am: -BUILT_SOURCES += $(SYS_TIME_H) +BUILT_SOURCES += sys/time.h # We need the following in order to create when the system # doesn't have one that works with the given compiler. -sys/time.h: sys_time.in.h $(ARG_NONNULL_H) +sys/time.h: sys_time.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H) $(AM_V_at)$(MKDIR_P) sys $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ @@ -26,9 +27,11 @@ sys/time.h: sys_time.in.h $(ARG_NONNULL_H) -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \ - -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \ + -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \ + -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/sys_time.in.h; \ } > $@-t && \ mv $@-t $@