bug-gnulib
[Top][All Lists]
Advanced

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

add link warnings to inttypes.h


From: Bruno Haible
Subject: add link warnings to inttypes.h
Date: Sun, 18 Feb 2007 01:39:34 +0100
User-agent: KMail/1.5.4

This patch adds link warnings (conditional, only if GNULIB_POSIXCHECK is
defined) to inttypes.h.

A side effect is that the 'inttypes' module will create inttypes.h always -
like the 'string' module creates string.h always.

2007-02-17  Bruno Haible  <address@hidden>

        * lib/inttypes_.h: Add definition for GL_LINK_WARNING.
        (imaxabs, imaxdiv, strtoimax, strtoumax): Don't declare the function
        if the corresponding module is not enabled. Emit link warnings if
        the function is used nevertheless.
        * m4/inttypes_.h (gl_INTTYPES_H): Never use the existing <inttypes.h>.
        Don't AC_SUBST HAVE_DECL_IMAXABS, HAVE_DECL_IMAXDIV,
        HAVE_DECL_STRTOIMAX, HAVE_DECL_STRTOUMAX.
        (gl_INTTYPES_MODULE_INDICATOR, gl_INTTYPES_H_DEFAULTS): New macros.
        * modules/inttypes (Depends-on): Add link-warning.
        (Makefile.am): Copy the contents of build-aux/link-warning.h into
        inttypes.h.
        * modules/imaxabs (configure.ac): Invoke gl_INTTYPES_MODULE_INDICATOR.
        * modules/imaxdiv (configure.ac): Likewise.
        * modules/strtoimax (configure.ac): Likewise.
        * modules/strtoumax (configure.ac): Likewise.
        
*** lib/inttypes_.h     12 Oct 2006 12:55:07 -0000      1.6
--- lib/inttypes_.h     17 Feb 2007 23:35:51 -0000
***************
*** 1,4 ****
! /* Copyright (C) 2006 Free Software Foundation, Inc.
     Written by Paul Eggert, Bruno Haible, Derek Price.
     This file is part of gnulib.
  
--- 1,4 ----
! /* Copyright (C) 2006-2007 Free Software Foundation, Inc.
     Written by Paul Eggert, Bruno Haible, Derek Price.
     This file is part of gnulib.
  
***************
*** 42,47 ****
--- 42,49 ----
  # error "This file assumes that 'int' has exactly 32 bits. Please report your 
platform and compiler to <address@hidden>."
  #endif
  
+ /* The definition of GL_LINK_WARNING is copied here.  */
+ 
  /* 7.8.1 Macros for format specifiers */
  
  #if ! defined __cplusplus || defined __STDC_FORMAT_MACROS
***************
*** 1034,1053 ****
  extern "C" {
  #endif
  
! #if address@hidden@
  extern intmax_t imaxabs (intmax_t);
  #endif
  
! #if address@hidden@
  typedef struct { intmax_t quot; intmax_t rem; } imaxdiv_t;
  extern imaxdiv_t imaxdiv (intmax_t, intmax_t);
  #endif
  
! #if address@hidden@
  extern intmax_t strtoimax (const char *, char **, int);
  #endif
! #if address@hidden@
  extern uintmax_t strtoumax (const char *, char **, int);
  #endif
  
  /* Don't bother defining or declaring wcstoimax and wcstoumax, since
--- 1036,1088 ----
  extern "C" {
  #endif
  
! #if @GNULIB_IMAXABS@
! # if address@hidden@
  extern intmax_t imaxabs (intmax_t);
+ # endif
+ #elif defined GNULIB_POSIXCHECK
+ # undef imaxabs
+ # define imaxabs(a) \
+     (GL_LINK_WARNING ("imaxabs is unportable - "\
+                       "use gnulib module imaxabs for portability"), \
+      imaxabs (a))
  #endif
  
! #if @GNULIB_IMAXDIV@
! # if address@hidden@
  typedef struct { intmax_t quot; intmax_t rem; } imaxdiv_t;
  extern imaxdiv_t imaxdiv (intmax_t, intmax_t);
+ # endif
+ #elif defined GNULIB_POSIXCHECK
+ # undef imaxdiv
+ # define imaxdiv(a,b) \
+     (GL_LINK_WARNING ("imaxdiv is unportable - "\
+                       "use gnulib module imaxdiv for portability"), \
+      imaxdiv (a, b))
  #endif
  
! #if @GNULIB_STRTOIMAX@
! # if address@hidden@
  extern intmax_t strtoimax (const char *, char **, int);
+ # endif
+ #elif defined GNULIB_POSIXCHECK
+ # undef strtoimax
+ # define strtoimax(p,e,b) \
+     (GL_LINK_WARNING ("strtoimax is unportable - "\
+                       "use gnulib module strtoimax for portability"), \
+      strtoimax (p, e, b))
  #endif
! 
! #if @GNULIB_STRTOUMAX@
! # if address@hidden@
  extern uintmax_t strtoumax (const char *, char **, int);
+ # endif
+ #elif defined GNULIB_POSIXCHECK
+ # undef strtoumax
+ # define strtoumax(p,e,b) \
+     (GL_LINK_WARNING ("strtoumax is unportable - "\
+                       "use gnulib module strtoumax for portability"), \
+      strtoumax (p, e, b))
  #endif
  
  /* Don't bother defining or declaring wcstoimax and wcstoumax, since
*** m4/inttypes.m4      14 Nov 2006 22:27:06 -0000      1.17
--- m4/inttypes.m4      17 Feb 2007 23:35:51 -0000
***************
*** 1,5 ****
! # inttypes.m4 serial 7
! dnl Copyright (C) 2006 Free Software Foundation, Inc.
  dnl This file is free software; the Free Software Foundation
  dnl gives unlimited permission to copy and/or distribute it,
  dnl with or without modifications, as long as this notice is preserved.
--- 1,5 ----
! # inttypes.m4 serial 8
! dnl Copyright (C) 2006-2007 Free Software Foundation, Inc.
  dnl This file is free software; the Free Software Foundation
  dnl gives unlimited permission to copy and/or distribute it,
  dnl with or without modifications, as long as this notice is preserved.
***************
*** 133,143 ****
         ])],
         [gl_cv_header_working_inttypes_h=yes])
       fi])
!   if test $gl_cv_header_working_inttypes_h = yes; then
      dnl Use the existing <inttypes.h>.
      INTTYPES_H=''
    else
  
      dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h.
      if test $ac_cv_header_inttypes_h = yes; then
        gl_ABSOLUTE_HEADER([inttypes.h])
--- 133,146 ----
         ])],
         [gl_cv_header_working_inttypes_h=yes])
       fi])
! 
!   dnl Override <inttypes.h> always, so that the portability warnings work.
!   if false && test $gl_cv_header_working_inttypes_h = yes; then
      dnl Use the existing <inttypes.h>.
      INTTYPES_H=''
    else
  
+     AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
      dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h.
      if test $ac_cv_header_inttypes_h = yes; then
        gl_ABSOLUTE_HEADER([inttypes.h])
***************
*** 175,204 ****
      else
        HAVE_DECL_IMAXABS=0
      fi
-     AC_SUBST([HAVE_DECL_IMAXABS])
  
      if test "$ac_cv_have_decl_imaxdiv" = yes; then
        HAVE_DECL_IMAXDIV=1
      else
        HAVE_DECL_IMAXDIV=0
      fi
-     AC_SUBST([HAVE_DECL_IMAXDIV])
  
      if test "$ac_cv_have_decl_strtoimax" = yes; then
        HAVE_DECL_STRTOIMAX=1
      else
        HAVE_DECL_STRTOIMAX=0
      fi
-     AC_SUBST([HAVE_DECL_STRTOIMAX])
  
      if test "$ac_cv_have_decl_strtoumax" = yes; then
        HAVE_DECL_STRTOUMAX=1
      else
        HAVE_DECL_STRTOUMAX=0
      fi
-     AC_SUBST([HAVE_DECL_STRTOUMAX])
  
      INTTYPES_H='inttypes.h'
    fi
    AC_SUBST(INTTYPES_H)
  ])
--- 178,223 ----
      else
        HAVE_DECL_IMAXABS=0
      fi
  
      if test "$ac_cv_have_decl_imaxdiv" = yes; then
        HAVE_DECL_IMAXDIV=1
      else
        HAVE_DECL_IMAXDIV=0
      fi
  
      if test "$ac_cv_have_decl_strtoimax" = yes; then
        HAVE_DECL_STRTOIMAX=1
      else
        HAVE_DECL_STRTOIMAX=0
      fi
  
      if test "$ac_cv_have_decl_strtoumax" = yes; then
        HAVE_DECL_STRTOUMAX=1
      else
        HAVE_DECL_STRTOUMAX=0
      fi
  
      INTTYPES_H='inttypes.h'
    fi
    AC_SUBST(INTTYPES_H)
  ])
+ 
+ AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
+ [
+   dnl Use AC_REQUIRE here, so that the default settings are expanded once 
only.
+   AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
+   
GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+ ])
+ 
+ AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
+ [
+   GNULIB_IMAXABS=0;      AC_SUBST([GNULIB_IMAXABS])
+   GNULIB_IMAXDIV=0;      AC_SUBST([GNULIB_IMAXDIV])
+   GNULIB_STRTOIMAX=0;    AC_SUBST([GNULIB_STRTOIMAX])
+   GNULIB_STRTOUMAX=0;    AC_SUBST([GNULIB_STRTOUMAX])
+   dnl Assume proper GNU behavior unless another module says otherwise.
+   HAVE_DECL_IMAXABS=1;   AC_SUBST([HAVE_DECL_IMAXABS])
+   HAVE_DECL_IMAXDIV=1;   AC_SUBST([HAVE_DECL_IMAXDIV])
+   HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
+   HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])
+ ])
*** modules/imaxabs     13 Oct 2006 12:40:23 -0000      1.3
--- modules/imaxabs     17 Feb 2007 23:35:51 -0000
***************
*** 10,15 ****
--- 10,16 ----
  
  configure.ac:
  gl_FUNC_IMAXABS
+ gl_INTTYPES_MODULE_INDICATOR([imaxabs])
  
  Makefile.am:
  
*** modules/imaxdiv     13 Oct 2006 12:40:23 -0000      1.3
--- modules/imaxdiv     17 Feb 2007 23:35:51 -0000
***************
*** 10,15 ****
--- 10,16 ----
  
  configure.ac:
  gl_FUNC_IMAXDIV
+ gl_INTTYPES_MODULE_INDICATOR([imaxdiv])
  
  Makefile.am:
  
*** modules/inttypes    26 Dec 2006 18:42:09 -0000      1.17
--- modules/inttypes    17 Feb 2007 23:35:51 -0000
***************
*** 8,13 ****
--- 8,14 ----
  
  Depends-on:
  absolute-header
+ link-warning
  stdint
  
  configure.ac:
***************
*** 31,36 ****
--- 32,38 ----
              -e 's/@''HAVE_DECL_IMAXDIV''@/$(HAVE_DECL_IMAXDIV)/g' \
              -e 's/@''HAVE_DECL_STRTOIMAX''@/$(HAVE_DECL_STRTOIMAX)/g' \
              -e 's/@''HAVE_DECL_STRTOUMAX''@/$(HAVE_DECL_STRTOUMAX)/g' \
+             -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
              < $(srcdir)/inttypes_.h; \
        } > address@hidden
        mv address@hidden $@
*** modules/strtoimax   13 Oct 2006 12:40:23 -0000      1.9
--- modules/strtoimax   17 Feb 2007 23:35:51 -0000
***************
*** 14,19 ****
--- 14,20 ----
  
  configure.ac:
  gl_FUNC_STRTOIMAX
+ gl_INTTYPES_MODULE_INDICATOR([strtoimax])
  
  Makefile.am:
  
*** modules/strtoumax   13 Oct 2006 12:40:23 -0000      1.8
--- modules/strtoumax   17 Feb 2007 23:35:51 -0000
***************
*** 14,19 ****
--- 14,20 ----
  
  configure.ac:
  gl_FUNC_STRTOUMAX
+ gl_INTTYPES_MODULE_INDICATOR([strtoumax])
  
  Makefile.am:
  





reply via email to

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