[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: faster m4_divert*,m4_cond
From: |
Eric Blake |
Subject: |
Re: faster m4_divert*,m4_cond |
Date: |
Tue, 12 Aug 2008 15:24:59 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Ralf Wildenhues <Ralf.Wildenhues <at> gmx.de> writes:
> * Eric Blake wrote on Tue, Aug 12, 2008 at 05:56:31AM CEST:
> > Yes, I should add a test case along the lines of the following:
>
> Yes, please, that prevents someone (else) later breaking this
> inadvertently.
Thanks for forcing me to do this. In the process of reviewing it, I noticed a
regression in the 1.4.x version, fixed as follows:
>From 430dd8892be28702114f5f82971475c8a18b3a23 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 12 Aug 2008 09:18:53 -0600
Subject: [PATCH] Fix m4_cond corner case.
* lib/m4sugar/foreach.m4 (_m4_cond): Ensure alternate
implementation allows concatenation with subsequent text.
* tests/m4sugar.at (m4@&address@hidden): Enhance test.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 5 +++++
lib/m4sugar/foreach.m4 | 13 +++++++------
tests/m4sugar.at | 7 +++++++
3 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8c1faa2..d460078 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2008-08-12 Eric Blake <address@hidden>
+ Fix m4_cond corner case.
+ * lib/m4sugar/foreach.m4 (_m4_cond): Ensure alternate
+ implementation allows concatenation with subsequent text.
+ * tests/m4sugar.at (m4@&address@hidden): Enhance test.
+
Add test for m4_cond.
* tests/m4sugar.at (m4@&address@hidden): New test.
Reported by Ralf Wildenhues.
diff --git a/lib/m4sugar/foreach.m4 b/lib/m4sugar/foreach.m4
index 78779c4..b85fce2 100644
--- a/lib/m4sugar/foreach.m4
+++ b/lib/m4sugar/foreach.m4
@@ -132,17 +132,18 @@ m4_define([_m4_case_],
# m4_cond already guarantees either 3*n or 3*n + 1 arguments, 1 <= n.
# We only have to speed up _m4_cond, by building the temporary _m4_c:
# m4_define([_m4_c], _m4_defn([m4_unquote]))_m4_c([m4_if(($1), [($2)],
-# [$3[]m4_define([_m4_c])])])_m4_c([m4_if(($4), [($5)],
-# [$6[]m4_define([_m4_c])])])..._m4_c([m4_if(($m-2), [($m-1)],
-# [$m[]m4_define([_m4_c])])])_m4_c([$m+1]_m4_popdef([_m4_c]))
+# [[$3]m4_define([_m4_c])])])_m4_c([m4_if(($4), [($5)],
+# [[$6]m4_define([_m4_c])])])..._m4_c([m4_if(($m-2), [($m-1)],
+# [[$m]m4_define([_m4_c])])])_m4_c([[$m+1]]_m4_popdef([_m4_c]))
+# We invoke m4_unquote(_m4_c($@)), for concatenation with later text.
m4_define([_m4_cond],
[m4_define([_m4_c], m4_pushdef([_m4_c])[m4_define([_m4_c],
_m4_defn([m4_unquote]))]_m4_for([_m4_c], [2], m4_eval([$# / 3 * 3 - 1]), [3],
- [$0_(m4_decr(_m4_c), _m4_c, m4_incr(_m4_c))])[_m4_c(]m4_dquote(
- [$]m4_eval([$# / 3 * 3 + 1]))[_m4_popdef([_m4_c]))])_m4_c($@)])
+ [$0_(m4_decr(_m4_c), _m4_c, m4_incr(_m4_c))])[_m4_c(]m4_dquote(m4_dquote(
+ [$]m4_eval([$# / 3 * 3 + 1])))[_m4_popdef([_m4_c]))])m4_unquote(_m4_c($@))])
m4_define([_m4_cond_],
-[[_m4_c([m4_if(($$1), [($$2)], [$$3[]m4_define([_m4_c])])])]])
+[[_m4_c([m4_if(($$1), [($$2)], [[$$3]m4_define([_m4_c])])])]])
# m4_bpatsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...)
# ----------------------------------------------------
diff --git a/tests/m4sugar.at b/tests/m4sugar.at
index b52b833..8e5fd01 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -214,6 +214,10 @@ m4_cond([[a,a]], [a,a], [yes])
m4_cond([a,a], [a,b], [yes], [no])
m4_cond([a,a], [a,b], [yes])
m4_cond([m4_eval([0xa])])
+m4_define([ab], [AB])dnl
+m4_cond([a])b
+m4_cond([1], [1], [a])b
+m4_cond([1], [2], [3], [a])b
]], [[
a
c
@@ -223,6 +227,9 @@ yes
no
10
+AB
+AB
+AB
]], [[1
2
2
--
1.5.6.4