[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
09-divert-balance.patch
From: |
Akim Demaille |
Subject: |
09-divert-balance.patch |
Date: |
Thu, 18 Jan 2001 01:03:09 +0100 |
Index: ChangeLog
from Akim Demaille <address@hidden>
Require a perfect divert push/pop balance.
* m4sugar.m4 (m4_divert, m4_divert_push, m4_divert_pop): Keep
track of them in m4_divert_stack.
(m4_divert_pop): Accept the expected current diversion as
argument and m4_fatal if incorrect, or if there is nothing to pop.
(globally): Specify the known m4_divert_pop.
Preserve symbolic values when possible.
* acgeneral.m4: No longer push the first diversion.
Specify the known m4_divert_pop.
(AC_PLAIN_SCRIPT): When m4_divert_push a diversion, m4_wrap its
pop.
(AC_INIT): Run AC_PLAIN_SCRIPT first, not last.
* tests/m4sh.at (AS_DIRNAME & AS_DIRNAME_SED): Can't use m4_defun
without m4_init.
* m4sugar.m4: Likewise.
Index: acgeneral.m4
--- acgeneral.m4 Wed, 17 Jan 2001 21:51:05 +0100 akim (ace/27_acgeneral.
1.169.8.116 644)
+++ acgeneral.m4 Wed, 17 Jan 2001 23:16:38 +0100 akim (ace/27_acgeneral.
1.169.8.116 644)
@@ -149,12 +149,6 @@ m4_define([AC_DIVERT_ONCE],
m4_copy([m4_divert_pop], [AC_DIVERT_POP])
-# Throw away output until AC_INIT is called.
-# FIXME: Should not be here.
-m4_pushdef([_m4_divert_diversion], _m4_divert([KILL]))
-
-
-
## ------------------------------- ##
## Defining macros in autoconf::. ##
## ------------------------------- ##
@@ -782,7 +776,7 @@ m4_define([_AC_INIT_DEFAULTS],
## ------------ ##
EOF
-m4_wrap([AC_EXPAND_ONCE([_AC_INIT_LOG_COMPLETE])])dnl
+m4_wrap([AC_EXPAND_ONCE([_AC_INIT_LOG_COMPLETE])[]])dnl
_AC_INIT_DEFAULTS_FDS
#
@@ -816,7 +810,7 @@ m4_define([_AC_INIT_DEFAULTS],
# change it if the script calls AC_OBJEXT.
ac_objext=o
-m4_divert_pop()dnl
+m4_divert_pop([DEFAULTS])dnl
])# _AC_INIT_DEFAULTS
@@ -865,7 +859,7 @@ m4_define([_AC_INIT_SRCDIR],
dnl Double slashes in pathnames in object file debugging info
dnl mess up M-x gdb in Emacs.
srcdir=`echo "$srcdir" | sed 's%\([[^/]]\)/*$%\1%'`
-m4_divert_pop()dnl
+m4_divert_pop([PARSE_ARGS])dnl
])# _AC_INIT_SRCDIR
@@ -1255,7 +1249,7 @@ m4_define([_AC_INIT_PARSE_ARGS],
ac_tool_prefix=
test -n "$host_alias" && ac_tool_prefix=$host_alias-
-m4_divert_pop()dnl
+m4_divert_pop([PARSE_ARGS])dnl
])# _AC_INIT_PARSE_ARGS
@@ -1326,7 +1320,7 @@ m4_define([_AC_INIT_HELP],
EOF
cat <<\EOF]
-m4_divert_pop()dnl
+m4_divert_pop([HELP_BEGIN])dnl
dnl The order of the diversions here is
dnl - HELP_BEGIN
dnl which may be prolongated by extra generic options such as with X or
@@ -1359,7 +1353,7 @@ m4_define([_AC_INIT_HELP],
short | recursive ) echo "Configuration of AC_PACKAGE_STRING:";;
esac])
cat <<\EOF
-m4_divert_pop()dnl
+m4_divert_pop([HELP_ENABLE])dnl
m4_divert_push([HELP_END])dnl
m4_ifset([AC_PACKAGE_BUGREPORT], [
Report bugs to <AC_PACKAGE_BUGREPORT>.])
@@ -1403,7 +1397,7 @@ m4_define([_AC_INIT_HELP],
fi
test -n "$ac_init_help" && exit 0
-m4_divert_pop()dnl
+m4_divert_pop([HELP_END])dnl
])# _AC_INIT_HELP
@@ -1496,7 +1490,7 @@ m4_define([_AC_INIT_PREPARE],
AC_SUBST(DEFS)dnl
AC_SUBST(LDFLAGS)dnl
AC_SUBST(LIBS)dnl
-m4_divert_pop()dnl
+m4_divert_pop([INIT_PREPARE])dnl
])# _AC_INIT_PREPARE
@@ -1520,7 +1514,9 @@ m4_define([AC_PLAIN_SCRIPT],
[m4_init
m4_pattern_forbid([^A]m4_dquote(m4_defn([m4_cr_LETTERS]))[_])
m4_pattern_forbid([_AC_])
-m4_divert_push([BODY])])
+m4_divert_push([BODY])dnl
+m4_wrap([m4_divert_pop([BODY])[]])dnl
+])
@@ -1531,7 +1527,8 @@ m4_define([AC_PLAIN_SCRIPT],
# Note that the order is important: first initialize, then set the
# AC_CONFIG_SRCDIR.
m4_define([AC_INIT],
-[m4_ifval([$2], [_AC_INIT_PACKAGE($@)])
+[AC_PLAIN_SCRIPT
+m4_ifval([$2], [_AC_INIT_PACKAGE($@)])
m4_divert_text([BINSH], address@hidden:@! /bin/sh])
_AC_INIT_DEFAULTS
_AC_INIT_PARSE_ARGS
@@ -1544,8 +1541,6 @@ m4_define([AC_INIT],
_AC_INIT_NOTICE
_AC_INIT_COPYRIGHT
m4_ifval([$2], , [m4_ifval([$1], [AC_CONFIG_SRCDIR([$1])])])dnl
-# Initialize the diversion setup.
-AC_PLAIN_SCRIPT
])
@@ -1705,7 +1700,7 @@ AC_DEFUN_ONCE([AC_ARG_PROGRAM],
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names
-m4_divert_pop()dnl
+m4_divert_pop([HELP_BEGIN])dnl
if test "$program_transform_name" = s,x,x,; then
program_transform_name=
else
@@ -3432,7 +3427,7 @@ m4_define([_AC_CONFIG_DEPENDENCIES],
[m4_divert_push([KILL])
AC_FOREACH([AC_File], [$1],
[_AC_CONFIG_DEPENDENCY(m4_patsubst(AC_File, [:], [,]))])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
])
@@ -3460,7 +3455,7 @@ m4_define([_AC_CONFIG_UNIQUE],
AC_CONFIG_IF_MEMBER(AC_Dest, [AC_LIST_FILES],
[AC_FATAL(`AC_Dest' [is already registered with AC_CONFIG_FILES or
AC_OUTPUT.])])
m4_popdef([AC_Dest])])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
])
@@ -3497,7 +3492,7 @@ AC_DEFUN([AC_CONFIG_COMMANDS],
[ ]m4_patsubst(AC_Name, [:.*])[ ) $2 ;;
])])])
_AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
ac_config_commands="$ac_config_commands $1"
])dnl
@@ -3575,7 +3570,7 @@ AC_DEFUN([AC_CONFIG_HEADERS],
[ ]m4_patsubst(AC_File, [:.*])[ ) $2 ;;
])])])
_AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
ac_config_headers="$ac_config_headers m4_normalize([$1])"
])dnl
@@ -3612,7 +3607,7 @@ AC_DEFUN([AC_CONFIG_LINKS],
[ ]m4_patsubst(AC_File, [:.*])[ ) $2 ;;
])])])
_AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
ac_config_links="$ac_config_links m4_normalize([$1])"
])dnl
@@ -3683,7 +3678,7 @@ AC_DEFUN([AC_CONFIG_FILES],
[ ]m4_patsubst(AC_File, [:.*])[ ) $2 ;;
])])])
_AC_CONFIG_COMMANDS_INIT([$3])
-m4_divert_pop()dnl
+m4_divert_pop([KILL])dnl
ac_config_files="$ac_config_files m4_normalize([$1])"
])dnl
Index: m4sugar.m4
--- m4sugar.m4 Wed, 17 Jan 2001 22:38:42 +0100 akim (ace/b/27_libm4.m4 1.52 644)
+++ m4sugar.m4 Wed, 17 Jan 2001 23:23:01 +0100 akim (ace/b/27_libm4.m4 1.52 644)
@@ -702,15 +702,10 @@ m4_define([_m4_divert(KILL)],
# -------------------------
# Change the diversion stream to DIVERSION-NAME.
m4_define([m4_divert],
-[m4_builtin([divert], _m4_divert([$1]))dnl
-])
-
-
-# m4_undivert(DIVERSION-NAME)
-# ---------------------------
-# Undivert DIVERSION-NAME.
-m4_define([m4_undivert],
-[m4_builtin([undivert], _m4_divert([$1]))dnl
+[m4_define([m4_divert_stack],
+ m4_location[: $0: $1]m4_ifdef([m4_divert_stack], [
+m4_defn([m4_divert_stack])]))dnl
+m4_builtin([divert], _m4_divert([$1]))dnl
])
@@ -718,19 +713,29 @@ m4_define([m4_undivert],
# ------------------------------
# Change the diversion stream to DIVERSION-NAME, while stacking old values.
m4_define([m4_divert_push],
-[m4_pushdef([_m4_divert_diversion], _m4_divert([$1]))dnl
-m4_divert(_m4_divert_diversion)dnl
+[m4_pushdef([m4_divert_stack],
+ m4_location[: $0: $1]m4_ifdef([m4_divert_stack], [
+m4_defn([m4_divert_stack])]))dnl
+m4_pushdef([_m4_divert_diversion], [$1])dnl
+m4_builtin([divert], _m4_divert(_m4_divert_diversion))dnl
])
-# m4_divert_pop
-# -------------
+# m4_divert_pop([DIVERSION-NAME])
+# -------------------------------
# Change the diversion stream to its previous value, unstacking it.
+# If specified, verify we left DIVERSION-NAME.
m4_define([m4_divert_pop],
-[m4_popdef([_m4_divert_diversion])dnl
-m4_ifndef([_m4_divert_diversion],
- [m4_fatal([too many m4_divert_pop])])dnl
-m4_divert(_m4_divert_diversion)dnl
+[m4_ifval([$1],
+ [m4_if(_m4_divert([$1]), m4_divnum, [],
+ [m4_fatal([$0($1): unexpected current diversion: ]m4_divnum)])])dnl
+m4_popdef([_m4_divert_diversion])dnl
+dnl m4_ifndef([_m4_divert_diversion],
+dnl [m4_fatal([too many m4_divert_pop])])dnl
+m4_builtin([divert],
+ m4_ifdef([_m4_divert_diversion],
+ [_m4_divert(_m4_divert_diversion)], -1))dnl
+m4_popdef([m4_divert_stack])dnl
])
@@ -741,10 +746,18 @@ m4_define([m4_divert_pop],
m4_define([m4_divert_text],
[m4_divert_push([$1])dnl
$2
-m4_divert_pop()dnl
+m4_divert_pop([$1])dnl
])
+# m4_undivert(DIVERSION-NAME)
+# ---------------------------
+# Undivert DIVERSION-NAME.
+m4_define([m4_undivert],
+[m4_builtin([undivert], _m4_divert([$1]))])
+
+
+
## -------------------------------------------- ##
## 8. Defining macros with bells and whistles. ##
@@ -1142,7 +1155,7 @@ m4_define([_m4_defun_pro],
m4_define([_m4_defun_epi],
[m4_divert_pop()dnl
m4_if(_m4_divert_dump, _m4_divert_diversion,
- [m4_undivert(_m4_divert([GROW]))dnl
+ [m4_undivert([GROW])dnl
m4_undefine([_m4_divert_dump])])dnl
m4_expansion_stack_pop()dnl
m4_popdef([_m4_expanding($1)])dnl
@@ -1245,10 +1258,11 @@ m4_define([m4_require],
[m4_fatal([$0: cannot be used outside of an m4_defun'd macro])])dnl
m4_provide_ifelse([$1],
[],
- [m4_divert_push(m4_eval(_m4_divert_diversion - 1))dnl
+ [m4_divert_push(m4_eval(m4_divnum - 1))dnl
m4_default([$2], [$1])
-m4_divert(_m4_divert_dump)m4_undivert(_m4_divert_diversion)dnl
-m4_divert_pop()])dnl
+m4_divert(m4_defn([_m4_divert_dump]))dnl
+m4_undivert(m4_defn([_m4_divert_diversion]))dnl
+m4_divert_pop(m4_defn([_m4_divert_dump]))])dnl
m4_provide_ifelse([$1],
[],
[m4_warn([syntax],
@@ -1696,14 +1710,21 @@ m4_define([m4_file_append],
# m4_init
# -------
-m4_defun([m4_init],
+m4_define([m4_init],
[# We need a tmp directory.
m4_ifndef([m4_tmpdir],
[m4_define([m4_tmpdir], [/tmp])])
-
# M4sugar reserves `m4_[A-Za-z0-9_]*'. We'd need \b and +,
# but they are not portable.
m4_pattern_forbid([^m4_])
m4_pattern_forbid([^dnl$])
+
+# Check the divert push/pop perfect balance.
+m4_wrap([m4_ifdef([_m4_divert_diversion],
+ [m4_fatal([$0: unbalanced m4_divert_push:]
+m4_defn([m4_divert_stack]))])[]])
+
+m4_divert_push([KILL])
+m4_wrap([m4_divert_pop([KILL])[]])
])
Index: tests/m4sh.at
--- tests/m4sh.at Sat, 23 Dec 2000 11:36:46 +0100 akim (ace/b/44_m4sh.at 1.10
666)
+++ tests/m4sh.at Wed, 17 Jan 2001 23:26:42 +0100 akim (ace/b/44_m4sh.at 1.10
666)
@@ -12,7 +12,8 @@
AT_SETUP([[AS_DIRNAME & AS_DIRNAME_SED]])
AT_DATA(configure.ac,
-[[_AS_EXPR_PREPARE
+[[AC_PLAIN_SCRIPT
+_AS_EXPR_PREPARE
define([AS_DIRNAME_TEST],
[dir=`AS_DIRNAME([$1])`
@@ -23,7 +24,6 @@
test "$dir" = "$2" ||
echo "dirname_sed($1) = $dir instead of $2" >&2])
-AC_PLAIN_SCRIPT
AS_DIRNAME_TEST([//1], [//])
AS_DIRNAME_TEST([/1], [/])
AS_DIRNAME_TEST([./1], [.])
Index: tests/m4sugar.at
--- tests/m4sugar.at Wed, 17 Jan 2001 18:57:24 +0100 akim (ace/b/45_m4sugar.at
1.9 644)
+++ tests/m4sugar.at Wed, 17 Jan 2001 23:27:53 +0100 akim (ace/b/45_m4sugar.at
1.9 644)
@@ -73,18 +73,19 @@
m4_defun([baz],
[m4_require([foo])])
+m4_init
baz
]])
AT_CHECK_AUTOCONF([], 1, [],
-[[configure.ac:10: error: m4_require: circular dependency of foo
-configure.ac:10: foo is required by...
+[[configure.ac:11: error: m4_require: circular dependency of foo
+configure.ac:11: foo is required by...
configure.ac:5: bar is expanded from...
-configure.ac:10: bar is required by...
+configure.ac:11: bar is required by...
configure.ac:2: foo is expanded from...
-configure.ac:10: foo is required by...
+configure.ac:11: foo is required by...
configure.ac:8: baz is expanded from...
-configure.ac:10: the top level
+configure.ac:11: the top level
]])
AT_CLEANUP
Index: tests/tools.at
--- tests/tools.at Wed, 17 Jan 2001 21:51:05 +0100 akim (ace/b/30_tools.m4 1.31
644)
+++ tests/tools.at Wed, 17 Jan 2001 23:13:43 +0100 akim (ace/b/30_tools.m4 1.31
644)
@@ -106,9 +106,9 @@
AT_SETUP([autoconf --trace: user macros])
AT_DATA(configure.ac,
-[[define([active], [ACTIVE])
-AC_DEFUN([TRACE1], [TRACE2(m4_shift($@))])
-AC_DEFUN([TRACE2], [[$2], $1])
+[[m4_define([active], [ACTIVE])
+m4_define([TRACE1], [TRACE2(m4_shift($@))])
+m4_define([TRACE2], [[$2], $1])
TRACE1(foo, bar, baz)
TRACE1(foo, TRACE1(bar, baz))
TRACE1(foo, active, baz)
- 09-divert-balance.patch,
Akim Demaille <=