autoconf-patches
[Top][All Lists]
Advanced

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

[Bruno Haible <address@hidden>] _AC_COMPUTE_INT forgets to include stdio


From: Akim Demaille
Subject: [Bruno Haible <address@hidden>] _AC_COMPUTE_INT forgets to include stdio.h, stdlib.h
Date: 13 Sep 2001 17:24:41 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Artificial Intelligence)

Hi Bruno!

Thanks!

This seems OK to me.  Paul?

--- Begin Message --- Subject: _AC_COMPUTE_INT forgets to include stdio.h, stdlib.h Date: Thu, 13 Sep 2001 16:54:34 +0200 (CEST)
Hi,

An _AC_COMPUTE_INT failure was reported to me, caused by the lack of
<stdio.h> by an autoconf generated snippet that uses 'FILE'.

Here is the input:
====================== configure.in ======================
AC_INIT(configure.in)

AC_CHECK_SIZEOF([wchar_t], [], [#include <wchar.h>])

_AC_COMPUTE_INT([EILSEQ], ac_cv_decl_EILSEQ, [
#include <errno.h>
#include <wchar.h>
])

AC_OUTPUT
==========================================================

Call 'autoconf' (version 2.52), you will see that the generated
configure file contains the two following test programs.

==========================================================
#line 1808 "configure"
#include "confdefs.h"
#include <wchar.h>

int
main ()
{
FILE *f = fopen ("conftest.val", "w");
if (!f)
  exit (1);
fprintf (f, "%d", (sizeof (wchar_t)));
fclose (f);
  ;
  return 0;
}
==========================================================
#line 2009 "configure"
#include "confdefs.h"

#include <errno.h>
#include <wchar.h>

int
main ()
{
FILE *f = fopen ("conftest.val", "w");
if (!f)
  exit (1);
fprintf (f, "%d", (EILSEQ));
fclose (f);
  ;
  return 0;
}
==========================================================

There are three bugs here:

1) The code should include <stdio.h>, for FILE.
2) The code should include <stdlib.h>, for exit(). This matters when
   the C compiler is actually a C++ compiler: CC="gcc" CFLAGS="-x c++".
3) The printf argument could be of type 'long' or 'size_t'. Before
   passing it to printf, you need to cast it to 'int', to avoid problems
   on 64-bit platforms.

Below is a patch that changes the produced snippet to read as follows.

==========================================================
#line 1808 "configure"
#include "confdefs.h"
#include <wchar.h>

int conftestval () { return (sizeof (wchar_t)); }
#include <stdio.h>
#include <stdlib.h>
int
main ()
{
FILE *f = fopen ("conftest.val", "w");
if (!f)
  exit (1);
fprintf (f, "%d", conftestval ());
fclose (f);
  ;
  return 0;
}
==========================================================


2001-09-13  Bruno Haible  <address@hidden>

        * aclang.m4 (AC_LANG_INT_SAVE(C)): Always include <stdio.h> and
        <stdlib.h>. Evaluate the expression in an extra function before
        these includes. Call fprintf "%d" only after ensuring the argument
        is of type 'int'.
        Reported by Wayne Chapeskie <address@hidden>.

*** aclang.m4.bak       Wed Jul 18 14:47:34 2001
--- aclang.m4   Thu Sep 13 13:03:33 2001
***************
*** 423,436 ****
  
  # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
  # -----------------------------------------
! # We need `stdio.h' to open a `FILE', so the prologue defaults to the
! # inclusion of `stdio.h'.
  m4_define([AC_LANG_INT_SAVE(C)],
! [AC_LANG_PROGRAM([m4_default([$1], address@hidden:@include <stdio.h>])],
  [FILE *f = fopen ("conftest.val", "w");
  if (!f)
    exit (1);
! fprintf (f, "%d", ($2));
  fclose (f);])])
  
  
--- 423,439 ----
  
  # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
  # -----------------------------------------
! # We need `stdio.h' to open a `FILE' and `stdlib.h' for 'exit'. But we include
! # them only after the EXPRESSION has been evaluated.
  m4_define([AC_LANG_INT_SAVE(C)],
! [AC_LANG_PROGRAM([$1
! int conftestval () { return ($2); }
! @%:@include <stdio.h>
! @%:@include <stdlib.h>],
  [FILE *f = fopen ("conftest.val", "w");
  if (!f)
    exit (1);
! fprintf (f, "%d", conftestval ());
  fclose (f);])])
  
  



--- End Message ---

reply via email to

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