2006-06-02 Stepan Kasal * lib/m4sugar/m4sh.m4 (_AS_HERE_DOC_WORKS): Check for the ksh93f bug with long here-documents. (AS_INIT): Require this check. * doc/autoconf.texi (Here-Documents): Add more details about the bug. Index: lib/m4sugar/m4sh.m4 =================================================================== RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sh.m4,v retrieving revision 1.190 diff -u -r1.190 m4sh.m4 --- lib/m4sugar/m4sh.m4 31 May 2006 09:44:39 -0000 1.190 +++ lib/m4sugar/m4sh.m4 2 Jun 2006 11:37:00 -0000 @@ -1459,6 +1459,31 @@ } ]) +# _AS_HERE_DOC_WORKS +# ------------------ +# ksh versions prior to ksh93g mishandle braced variable expansion in +# non-quoted here-documents, if the variable name crosses a block boundary +# (block can be 1024 or 4096 bytes). Check for this. +# +m4_define([_AS_HERE_DOC_WORKS], [ +# (2^6 - 1) dots +as_d=............................................................... +# (2^9 - 1) characters +as_d="$as_d:$as_d:$as_d:$as_d +$as_d:$as_d:$as_d:$as_d" +$as_shell >/dev/null 2>&1 <<_ASOUTER +foobar=OK +bar=BAD +# the first two lines expand to (2^12 - 6) characters (including the two +# trailing newlines), so the 4096 boundary appears between "{foo" and "bar}" +grep OK <<_ASINNER +$as_d$as_d$as_d$as_d +$as_d$as_d$as_d$as_d + \${foobar} +_ASINNER +_ASOUTER +]) + # AS_INIT # ------- @@ -1473,6 +1498,7 @@ m4_divert_text([BINSH], address@hidden:@! /bin/sh]) m4_divert_text([M4SH-SANITIZE], [AS_SHELL_SANITIZE]) AS_REQUIRE([_AS_SHELL_FN_SPY]) +_AS_DETECT_REQUIRED([_AS_HERE_DOC_WORKS]) # Let's go! m4_wrap([m4_divert_pop([BODY])[]]) Index: doc/autoconf.texi =================================================================== RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v retrieving revision 1.1033 diff -u -r1.1033 autoconf.texi --- doc/autoconf.texi 1 Jun 2006 07:47:40 -0000 1.1033 +++ doc/autoconf.texi 2 Jun 2006 12:28:40 -0000 @@ -10792,11 +10792,14 @@ inefficiently. And some shells mishandle large here-documents: for example, Solaris 10 @command{dtksh} and the UnixWare 7.1.1 Posix shell, which are derived from Korn shell version M-12/28/93d, mishandle braced variable -expansion @address@hidden@}} that crosses a 1024- or 4096-byte buffer boundary -within a here-document. If the closing brace does not lie on the boundary, -the failure is silent and the variable expansion will be empty, otherwise -the shell will report a bad substitution. This bug can usually be worked -around by omitting the braces: @code{$var}. The bug was fixed in +expansion that crosses a 1024- or 4096-byte buffer boundary +within a here-document. Only the part of the variable name after the boundary +is used. For example, @address@hidden@}} could be replaced by the expansion +of @address@hidden@}}. If the end of the variable name is aligned with the block +boundary, the shell reports an error, as if you used @address@hidden@}}. +Instead of @address@hidden@}}, the shell may expand address@hidden@address@hidden, or even @address@hidden@}}. This bug can usually +be worked around by omitting the braces: @code{$var}. The bug was fixed in @samp{ksh93g} (1998-04-30) but as of 2006 many operating systems were still shipping older versions with the bug.