[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: head - Re: branch-1_4 patsubst bug, and missing arguments
From: |
Eric Blake |
Subject: |
Re: head - Re: branch-1_4 patsubst bug, and missing arguments |
Date: |
Mon, 28 Aug 2006 06:48:23 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Thunderbird/1.5.0.5 Mnenhy/0.7.4.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 8/25/2006 4:06 PM:
>
> And with that declaration, here goes. This patch touches a lot of files,
> but the core things it does are fix struct m4_builtin to be 0-based, add a
> bit to state when a macro must be called for side effects even when
> warning about too few arguments, then fix patsubst to be reliable, and fix
> the fallout. There are still a number of issues in modules/m4.c that need
> porting, but I think modules/gnu.c is now fully ported.
Looking back, it doesn't make sense for a blind macro to take 0 arguments,
so I added a check for that and fixed the two macros that fell short in
this area.
2006-08-28 Eric Blake <address@hidden>
* m4/utility.c (m4_bad_argc): Move assertion out of hot path...
* m4/module.c (install_builtin_table): ...to here, and add
assertion that blind macros require arguments.
* m4/m4module.h (struct m4_builtin): Document restrictions that
must be met during module loading.
* modules/gnu.c (changeresyntax, changesyntax): These are blind,
so require an argument to avoid triggering assertion.
(debugfile): Tweak error message.
- --
Life is short - so eat dessert first!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFE8uYX84KuGfSFAYARAg0CAJoD3z3G1sdrbJbcdUflIZ5QIE2ySACfeRDr
eRd8erHlwBoLFZUeM8it+IQ=
=t1Bj
-----END PGP SIGNATURE-----
Index: m4/m4module.h
===================================================================
RCS file: /sources/m4/m4/m4/m4module.h,v
retrieving revision 1.80
diff -u -p -r1.80 m4module.h
--- m4/m4module.h 25 Aug 2006 22:06:42 -0000 1.80
+++ m4/m4module.h 28 Aug 2006 12:41:09 -0000
@@ -44,11 +44,15 @@ typedef void m4_builtin_func (m4 *, m
/* The value of m4_builtin flags is built from these: */
enum {
- /* set if macro can handle non-text tokens, such as builtin macro tokens */
+ /* Set if macro can handle non-text tokens, such as builtin macro
+ tokens; if clear, non-text tokens are flattened to the empty
+ string before invoking the builtin. */
M4_BUILTIN_GROKS_MACRO = (1 << 0),
- /* set if macro should only be recognized with arguments */
+ /* Set if macro should only be recognized with arguments; may only
+ be set if min_args is nonzero. */
M4_BUILTIN_BLIND = (1 << 1),
- /* set if macro has side effects even when there are too few arguments */
+ /* set if macro has side effects even when there are too few
+ arguments; may only be set if min_args is nonzero. */
M4_BUILTIN_SIDE_EFFECT = (1 << 2)
};
@@ -58,7 +62,8 @@ struct m4_builtin
const char * name; /* name found by builtin, printed by dumpdef */
int flags; /* bitwise OR of M4_BUILTIN_* bits */
unsigned int min_args; /* 0-based minimum number of arguments */
- unsigned int max_args; /* max arguments, UINT_MAX if unlimited */
+ /* max arguments, UINT_MAX if unlimited; must be >= min_args */
+ unsigned int max_args;
};
struct m4_macro
Index: m4/module.c
===================================================================
RCS file: /sources/m4/m4/m4/module.c,v
retrieving revision 1.40
diff -u -p -r1.40 module.c
--- m4/module.c 25 Aug 2006 22:06:42 -0000 1.40
+++ m4/module.c 28 Aug 2006 12:41:09 -0000
@@ -145,6 +145,12 @@ install_builtin_table (m4 *context, lt_d
m4_symbol_value *value = m4_symbol_value_create ();
char * name;
+ /* Sanity check that builtins meet the required interface. */
+ assert (bp->min_args <= bp->max_args);
+ assert (bp->min_args > 0
+ || (bp->flags & (M4_BUILTIN_BLIND
+ | M4_BUILTIN_SIDE_EFFECT)) == 0);
+
m4_set_symbol_value_func (value, bp->func);
VALUE_HANDLE (value) = handle;
VALUE_FLAGS (value) = bp->flags;
Index: m4/utility.c
===================================================================
RCS file: /sources/m4/m4/m4/utility.c,v
retrieving revision 1.45
diff -u -p -r1.45 utility.c
--- m4/utility.c 25 Aug 2006 22:06:42 -0000 1.45
+++ m4/utility.c 28 Aug 2006 12:41:09 -0000
@@ -42,9 +42,6 @@ bool
m4_bad_argc (m4 *context, int argc, m4_symbol_value **argv,
unsigned int min, unsigned int max, bool side_effect)
{
- assert (min <= max);
- assert (min > 0 || ! side_effect);
-
if (argc - 1 < min)
{
m4_warn (context, 0, _("Warning: %s: too few arguments: %d < %d"),
Index: modules/gnu.c
===================================================================
RCS file: /sources/m4/m4/modules/gnu.c,v
retrieving revision 1.51
diff -u -p -r1.51 gnu.c
--- modules/gnu.c 25 Aug 2006 22:06:42 -0000 1.51
+++ modules/gnu.c 28 Aug 2006 12:41:09 -0000
@@ -49,8 +49,8 @@
BUILTIN (__line__, false, false, false, 0, 0 ) \
BUILTIN (__program__, false, false, false, 0, 0 ) \
BUILTIN (builtin, false, true, false, 1, -1 ) \
- BUILTIN (changeresyntax,false,true, false, 0, 1 ) \
- BUILTIN (changesyntax,false, true, false, 0, -1 ) \
+ BUILTIN (changeresyntax,false,true, false, 1, 1 ) \
+ BUILTIN (changesyntax,false, true, false, 1, -1 ) \
BUILTIN (debugmode, false, false, false, 0, 1 ) \
BUILTIN (debugfile, false, false, false, 0, 1 ) \
BUILTIN (esyscmd, false, true, true, 1, 1 ) \
@@ -349,7 +349,7 @@ m4_resyntax_encode_safe (m4 *context, co
/**
- * changeresyntax([RESYNTAX-SPEC])
+ * changeresyntax(RESYNTAX-SPEC)
**/
M4BUILTIN_HANDLER (changeresyntax)
{
@@ -360,11 +360,10 @@ M4BUILTIN_HANDLER (changeresyntax)
}
-/* Change the current input syntax. The function m4_set_syntax () lives
- in syntax.c. For compability reasons, this function is not called,
- if not followed by a SYNTAX_OPEN. Also, any changes to comment
- delimiters and quotes made here will be overridden by a call to
- `changecom' or `changequote'. */
+/* Change the current input syntax. The function m4_set_syntax ()
+ lives in syntax.c. Any changes to comment delimiters and quotes
+ made here will be overridden by a call to `changecom' or
+ `changequote'. */
/**
* changesyntax(SYNTAX-SPEC, ...)
@@ -404,7 +403,7 @@ M4BUILTIN_HANDLER (debugfile)
if (argc == 1)
m4_debug_set_output (context, NULL);
else if (!m4_debug_set_output (context, M4ARG (1)))
- m4_error (context, 0, errno, _("%s: cannot set error file: %s"),
+ m4_error (context, 0, errno, _("%s: cannot set debug file: %s"),
M4ARG (0), M4ARG (1));
}