autoconf-patches
[Top][All Lists]
Advanced

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

FYI: AC_FUNC_STRNLEN (Was: ["H.Merijn Brand" <address@hidden>] Re: bison


From: Akim Demaille
Subject: FYI: AC_FUNC_STRNLEN (Was: ["H.Merijn Brand" <address@hidden>] Re: bison-1.30j on AIX 4.3)
Date: 11 Jan 2002 14:27:42 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp)

| > From: "H.Merijn Brand" <address@hidden>
| > Subject: Re: bison-1.30j on AIX 4.3
| > To: Akim Demaille <address@hidden>
| > Cc: "H.Merijn Brand" <address@hidden>, Bison Bugs <address@hidden>
| > Date: Thu, 10 Jan 2002 11:38:48 +0100
| >
| > On Thu 10 Jan 2002 10:38, Akim Demaille <address@hidden> wrote:
| >> it is present!
| >>
| >> I think we have found the bad guy!!!
| >
| > Since I can't find a man page on strnlen from here (I'm working from home
| > today, cause my little boy is sick) for AIX 4.3, I can't verify what IBM
| > claims to be the desired behaviour, but it is indeed other than your <sane>
| > system. Is this maybe a big/small endian problem?
| >
| >> May I ask you to compile and run the following please?
| >>
| >> /tmp % cat strnlen.c                                             nostromo 
10:37
| >> #include <stdio.h>
| >> #include <stdlib.h>
| >> #include <string.h>
| >>
| >> int
| >> main (void)
| >> {
| >>   const char *foobar = "foobar";
| >>   int i;
| >>
| >>   for (i = 0; i < 10; ++i)
| >>     fprintf (stderr, "strnlen (%s, %d) = %d\n",
| >>              foobar, i, strnlen (foobar, i));
| >>   return 0;
| >> }
| >> /tmp % gcc strnlen.c                                             nostromo 
10:37
| >> /tmp % ./a.out                                                   nostromo 
10:37
| >> strnlen (foobar, 0) = 0
| >> strnlen (foobar, 1) = 1
| >> strnlen (foobar, 2) = 2
| >> strnlen (foobar, 3) = 3
| >> strnlen (foobar, 4) = 4
| >> strnlen (foobar, 5) = 5
| >> strnlen (foobar, 6) = 6
| >> strnlen (foobar, 7) = 6
| >> strnlen (foobar, 8) = 6
| >> strnlen (foobar, 9) = 6
| >
| > i2:/pro/3gl/GNU/bison-1.30j 104 > cc -O2 -o test-cc test.c
| > 1506-507 (W) No licenses available. Contact your program supplier to add 
additional users.  Compilation will proceed shortly.
| > i2:/pro/3gl/GNU/bison-1.30j 105 > gcc -O4 -o test-gcc test.c
| > i2:/pro/3gl/GNU/bison-1.30j 106 > ./test-cc
| > strnlen (foobar, 0) = 0
| > strnlen (foobar, 1) = 3
| > strnlen (foobar, 2) = 2
| > strnlen (foobar, 3) = 1
| > strnlen (foobar, 4) = 0
| > strnlen (foobar, 5) = 6
| > strnlen (foobar, 6) = 6
| > strnlen (foobar, 7) = 6
| > strnlen (foobar, 8) = 6
| > strnlen (foobar, 9) = 6
| > i2:/pro/3gl/GNU/bison-1.30j 107 > ./test-gcc
| > strnlen (foobar, 0) = 0
| > strnlen (foobar, 1) = 3
| > strnlen (foobar, 2) = 2
| > strnlen (foobar, 3) = 1
| > strnlen (foobar, 4) = 0
| > strnlen (foobar, 5) = 6
| > strnlen (foobar, 6) = 6
| > strnlen (foobar, 7) = 6
| > strnlen (foobar, 8) = 6
| > strnlen (foobar, 9) = 6
| > i2:/pro/3gl/GNU/bison-1.30j 108 >
| >
| > --
| > H.Merijn Brand        Amsterdam Perl Mongers (http://amsterdam.pm.org/)
| > using perl-5.6.1, 5.7.2 & 630 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
| >      WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-Unify
| > ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
| >
| > ----------
| 
| Akim Demaille <address@hidden> wrote:
| > I have to leave right now, sorry for this short message :(
| >
| > It's just to ask whether you are aware of the following:
| 
| Thanks!  I didn't know about that.
| Ick!

isn't it :)

| In the coreutils, I see that it's used only by strndup
| which in turn is used only by dircolors.

Correct, that's also what I saw.  I need xstrndup in Bison.

| So we'll need another run-test.
| Here's one (modeled after AC_FUNC_MEMCMP) and tested only on Linux:
| 
| # AC_FUNC_STRNLEN
| # --------------
| AC_DEFUN([AC_FUNC_STRNLEN],
| [AC_CACHE_CHECK([for working strnlen], ac_cv_func_strnlen_working,
| [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [[
| #define S "foobar"
| #define S_LEN (sizeof S - 1)
| 
|   /* At least one implementation is buggy: that of AIX 4.3 would
|      give strnlen (S, 1) == 3.  */
| 
|   int i;
|   for (i = 0; i < S_LEN + 1; ++i)
|     {
|       int expected = i <= S_LEN ? i : S_LEN;
|       if (strnlen (S, i) != expected)
|       exit (1);
|     }
|   exit (0);
| ]])],
|                [ac_cv_func_strnlen_working=yes],
|                [ac_cv_func_strnlen_working=no],
|                [ac_cv_func_strnlen_working=no])])
| test $ac_cv_func_strnlen_working = no && AC_LIBOBJ([strnlen])
| ])# AC_FUNC_STRNLEN

That's exactly what I was about to write :)

I'm checking this in.  Thanks!

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * lib/autoconf/functions.m4 (AC_FUNC_STRNLEN): New, from Jim
        Meyering.
        * doc/autoconf.texi (Function Portability): Document the strnlen
        limitation.
        (Particular Functions): Document AC_FUNC_STRNLEN.
        * lib/autoscan/functions: Adjust.

Index: NEWS
===================================================================
RCS file: /cvsroot/autoconf/autoconf/NEWS,v
retrieving revision 1.213
diff -u -u -r1.213 NEWS
--- NEWS 6 Jan 2002 20:48:10 -0000 1.213
+++ NEWS 11 Jan 2002 13:21:47 -0000
@@ -97,6 +97,9 @@
 
 - AC_FUNC_STRTOD substitutes POW_LIB.
 
+- AC_FUNC_STRNLEN
+  New.
+
 
 * Major changes in Autoconf 2.52
 ** Documentation
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.574
diff -u -u -r1.574 autoconf.texi
--- doc/autoconf.texi 6 Jan 2002 20:48:25 -0000 1.574
+++ doc/autoconf.texi 11 Jan 2002 13:21:48 -0000
@@ -3360,6 +3360,24 @@
 Porting the GNU Compiler Collection}).  Apparently in some cases even
 having format strings read-only can be a problem.
 
address@hidden @code{strnlen}
address@hidden @fuindex strnlen
address@hidden @code{strnlen}
+AIX 4.3 provides a broken version which produces funny results:
+
address@hidden
+strnlen ("foobar", 0) = 0
+strnlen ("foobar", 1) = 3
+strnlen ("foobar", 2) = 2
+strnlen ("foobar", 3) = 1
+strnlen ("foobar", 4) = 0
+strnlen ("foobar", 5) = 6
+strnlen ("foobar", 6) = 6
+strnlen ("foobar", 7) = 6
+strnlen ("foobar", 8) = 6
+strnlen ("foobar", 9) = 6
address@hidden example
+
 @item @code{unlink}
 @c @fuindex unlink
 @prindex @code{unlink}
@@ -3790,6 +3808,16 @@
 @prindex @code{strftime}
 Check for @code{strftime} in the @file{intl} library, for SCO @sc{unix}.
 Then, if @code{strftime} is available, define @code{HAVE_STRFTIME}.
address@hidden defmac
+
address@hidden AC_FUNC_STRNLEN
address@hidden FUNC_STRNLEN
address@hidden HAVE_STRNLEN
address@hidden @fuindex strnlen
address@hidden @code{strnlen}
+Check for a working @code{strnlen}, and ask for its replacement.  Some
+architectures are know to provide broken versions of @code{strnlen}, such
+as AIX 4.3.
 @end defmac
 
 @defmac AC_FUNC_UTIME_NULL
Index: lib/autoconf/functions.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/functions.m4,v
retrieving revision 1.53
diff -u -u -r1.53 functions.m4
--- lib/autoconf/functions.m4 25 Nov 2001 15:13:04 -0000 1.53
+++ lib/autoconf/functions.m4 11 Jan 2002 13:21:48 -0000
@@ -1262,6 +1262,33 @@
 ])# AC_FUNC_STRFTIME
 
 
+# AC_FUNC_STRNLEN
+# --------------
+AC_DEFUN([AC_FUNC_STRNLEN],
+[AC_CACHE_CHECK([for working strnlen], ac_cv_func_strnlen_working,
+[AC_RUN_IFELSE([AC_LANG_PROGRAM([], [[
+#define S "foobar"
+#define S_LEN (sizeof S - 1)
+
+  /* At least one implementation is buggy: that of AIX 4.3 would
+     give strnlen (S, 1) == 3.  */
+
+  int i;
+  for (i = 0; i < S_LEN + 1; ++i)
+    {
+      int expected = i <= S_LEN ? i : S_LEN;
+      if (strnlen (S, i) != expected)
+       exit (1);
+    }
+  exit (0);
+]])],
+               [ac_cv_func_strnlen_working=yes],
+               [ac_cv_func_strnlen_working=no],
+               [ac_cv_func_strnlen_working=no])])
+test $ac_cv_func_strnlen_working = no && AC_LIBOBJ([strnlen])
+])# AC_FUNC_STRNLEN
+
+
 # AC_FUNC_SETVBUF_REVERSED
 # ------------------------
 AC_DEFUN([AC_FUNC_SETVBUF_REVERSED],
Index: lib/autoscan/functions
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoscan/functions,v
retrieving revision 1.16
diff -u -u -r1.16 functions
--- lib/autoscan/functions 25 Jun 2001 06:15:07 -0000 1.16
+++ lib/autoscan/functions 11 Jan 2002 13:21:48 -0000
@@ -1,5 +1,5 @@
-# acfunctions -- autoscan's mapping from functions to Autoconf macros
-# Copyright 1992, 1993, 1994, 1996, 1999, 2000, 2001
+# functions -- autoscan's mapping from functions to Autoconf macros
+# Copyright 1992, 1993, 1994, 1996, 1999, 2000, 2001, 2002
 # Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
@@ -59,6 +59,7 @@
 strcoll                AC_FUNC_STRCOLL
 strerror_r     AC_FUNC_STRERROR_R
 strftime       AC_FUNC_STRFTIME
+strnlen                AC_FUNC_STRNLEN
 strtod         AC_FUNC_STRTOD
 utime          AC_FUNC_UTIME_NULL
 utime          AC_CHECK_FUNCS
@@ -150,7 +151,6 @@
 strerror
 strncasecmp
 strndup
-strnlen
 strpbrk
 strrchr
 strspn
Index: tests/acfunctions.at
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/acfunctions.at,v
retrieving revision 1.5
diff -u -u -r1.5 acfunctions.at
--- tests/acfunctions.at 20 Aug 2001 17:57:06 -0000 1.5
+++ tests/acfunctions.at 11 Jan 2002 13:21:48 -0000
@@ -27,6 +27,7 @@
 AT_CHECK_MACRO([AC_FUNC_STRCOLL])
 AT_CHECK_MACRO([AC_FUNC_STRERROR_R])
 AT_CHECK_MACRO([AC_FUNC_STRFTIME])
+AT_CHECK_MACRO([AC_FUNC_STRNLEN])
 AT_CHECK_MACRO([AC_FUNC_STRTOD])
 AT_CHECK_MACRO([AC_FUNC_UTIME_NULL])
 AT_CHECK_MACRO([AC_FUNC_VPRINTF])



reply via email to

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