Mercurial > hg > octave-lojdl > gnulib-hg
changeset 12725:b6a49a4ae7d7
unistd: warn on use of environ without module
_GL_WARN_ON_USE only works for functions; so we wrap access to
environ through a function when CFLAGS has -DGNULIB_POSIXCHECK=1.
* modules/unistd (Depends-on): Add warn-on-use.
(Makefile.am): Provide new substitutions.
* m4/unistd_h.m4 (gl_UNISTD_H): Check for inline and environ.
* lib/unistd.in.h (environ): Wrap with a warning helper function.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Thu, 31 Dec 2009 13:28:59 -0700 |
parents | bc2866336bbb |
children | d6da6e5f2f62 |
files | ChangeLog lib/unistd.in.h m4/unistd_h.m4 modules/unistd |
diffstat | 4 files changed, 34 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2010-01-11 Eric Blake <ebb9@byu.net> + unistd: warn on use of environ without module + * modules/unistd (Depends-on): Add warn-on-use. + (Makefile.am): Provide new substitutions. + * m4/unistd_h.m4 (gl_UNISTD_H): Check for inline and environ. + * lib/unistd.in.h (environ): Wrap with a warning helper function. + stdio: warn on suspicious uses * modules/stdio (Depends-on): Add warn-on-use. (Makefile.am): Provide new substitutions.
--- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -118,6 +118,8 @@ /* The definition of _GL_ARG_NONNULL is copied here. */ +/* The definition of _GL_WARN_ON_USE is copied here. */ + /* OS/2 EMX lacks these macros. */ #ifndef STDIN_FILENO @@ -250,11 +252,17 @@ # endif # endif #elif defined GNULIB_POSIXCHECK -# undef environ -# define environ \ - (GL_LINK_WARNING ("environ is unportable - " \ - "use gnulib module environ for portability"), \ - environ) +# if HAVE_RAW_DECL_ENVIRON +static inline char *** +rpl_environ (void) +{ + return &environ; +} +_GL_WARN_ON_USE (rpl_environ, "environ is unportable - " + "use gnulib module environ for portability"); +# undef environ +# define environ (*rpl_environ ()) +# endif #endif
--- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 37 +# unistd_h.m4 serial 38 dnl Copyright (C) 2006-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -11,6 +11,7 @@ dnl Use AC_REQUIRE here, so that the default behavior below is expanded dnl once only, before all statements that occur in other macros. AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_REQUIRE([AC_C_INLINE]) gl_CHECK_NEXT_HEADERS([unistd.h]) @@ -21,6 +22,15 @@ HAVE_UNISTD_H=0 fi AC_SUBST([HAVE_UNISTD_H]) + + 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([[#include <unistd.h> +/* Some systems declare environ in the wrong header. */ +#ifndef __GLIBC__ +# include <stdlib.h> +#endif + ]], [environ]) ]) AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
--- a/modules/unistd +++ b/modules/unistd @@ -6,10 +6,11 @@ lib/unistd.in.h Depends-on: +arg-nonnull include_next link-warning -arg-nonnull stddef +warn-on-use configure.ac: gl_UNISTD_H @@ -19,7 +20,7 @@ # We need the following in order to create an empty placeholder for # <unistd.h> when the system doesn't have one. -unistd.h: unistd.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) +unistd.h: unistd.in.h $(LINK_WARNING_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \ @@ -121,6 +122,7 @@ -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/unistd.in.h; \ } > $@-t && \ mv $@-t $@