m4-patches
[Top][All Lists]
Advanced

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

Re: branch-1_4 and frozen files


From: Eric Blake
Subject: Re: branch-1_4 and frozen files
Date: Fri, 28 Jul 2006 08:04:50 -0600
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 6/22/2006 4:42 PM:
> This patch does two things: It tightens the allowable syntax of frozen files, 
> as mentioned here:
> http://www.nabble.com/frozen-files-format-2-p4992582.html
> 
> And it makes it possible to avoid warnings when loading a frozen file created 
> by another version of m4 with more builtins, as mentioned here:
> http://www.nabble.com/Re%3A-m4-1.4.4b-problems-p4994425.html

Ported to head in a different manner.  I created a new symbol type that
tracks the name of the requested builtin.  This could open the door to
future enhancements that a placeholder can be replaced with an actual
function by properly loading a newer module.  With this patch, the
testsuite once again passes all tests (which is a sign that it is
incomplete, because I'm not done porting from the branch).

2006-07-28  Eric Blake  <address@hidden>

        Port idea from branch that a frozen file can request an unknown
        builtin without producing a warning unless the builtin is
        actually used.
        * m4/m4private.h (m4__symbol_type): Add M4_SYMBOL_PLACEHOLDER.
        (m4_is_symbol_value_placeholder, m4_get_symbol_value_placeholder)
        (m4_set_symbol_value_placeholder): New accessors.
        * m4/m4module.h (m4_is_symbol_placeholder),
        (m4_get_symbol_value_placeholder),
        (m4_set_symbol_value_placeholder),
        (m4_get_symbol_placeholder): Likewise.
        * m4/symtab.c (m4_is_symbol_value_placeholder),
        (m4_get_symbol_value_placeholder),
        (m4_set_symbol_value_placeholder): Likewise.
        (dump_symbol_CB): Handle new symbol type.
        * m4/macro.c (trace_pre): Likewise.
        (m4_macro_call): Warn when invoking a placeholder.
        * modules/m4.c (dumpdef): Handle dumping a placeholder.
        (defn): Warn when referencing a placeholder.
        * src/freeze.c (dump_symbol_CB): Ignore placeholder when
        freezing.
        (reload_frozen_state): When reloading unknown builtin, install a
        placeholder instead of warning.
        * tests/freeze.at (loading format 1): Allow warning when
        popdef'ing undefined function.

- --
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

iD8DBQFEyhmB84KuGfSFAYARAgtzAJ9IUwPu4bGMqvfAkWU/ciTr4mPETACg0Lqo
IfZaXMTaspSWjalzWIiUmNk=
=aG21
-----END PGP SIGNATURE-----
Index: m4/m4module.h
===================================================================
RCS file: /sources/m4/m4/m4/m4module.h,v
retrieving revision 1.75
diff -u -p -b -r1.75 m4module.h
--- m4/m4module.h       13 Jul 2006 23:35:16 -0000      1.75
+++ m4/m4module.h       28 Jul 2006 13:41:30 -0000
@@ -198,10 +198,14 @@ extern bool               m4_set_symbol_name_traced (
        (m4_is_symbol_value_text (m4_get_symbol_value (symbol)))
 #define m4_is_symbol_func(symbol)                                      \
        (m4_is_symbol_value_func (m4_get_symbol_value (symbol)))
+#define m4_is_symbol_placeholder(symbol)                               \
+       (m4_is_symbol_value_placeholder (m4_get_symbol_value (symbol)))
 #define m4_get_symbol_text(symbol)                                     \
        (m4_get_symbol_value_text (m4_get_symbol_value (symbol)))
 #define m4_get_symbol_func(symbol)                                     \
        (m4_get_symbol_value_func (m4_get_symbol_value (symbol)))
+#define m4_get_symbol_placeholder(symbol)                              \
+       (m4_get_symbol_value_placeholder (m4_get_symbol_value (symbol)))
 
 extern m4_symbol_value *m4_symbol_value_create   (void);
 extern void            m4_symbol_value_delete    (m4_symbol_value *);
@@ -209,12 +213,16 @@ extern void               m4_symbol_value_copy      (m4_
                                                   m4_symbol_value *);
 extern bool            m4_is_symbol_value_text   (m4_symbol_value *);
 extern bool            m4_is_symbol_value_func   (m4_symbol_value *);
+extern bool            m4_is_symbol_value_placeholder  (m4_symbol_value *);
 extern bool            m4_is_symbol_value_void   (m4_symbol_value *);
 extern char           *m4_get_symbol_value_text  (m4_symbol_value *);
 extern m4_builtin_func *m4_get_symbol_value_func  (m4_symbol_value *);
+extern char           *m4_get_symbol_value_placeholder  (m4_symbol_value *);
 extern void            m4_set_symbol_value_text  (m4_symbol_value *, char *);
 extern void            m4_set_symbol_value_func  (m4_symbol_value *,
                                                   m4_builtin_func *);
+extern void            m4_set_symbol_value_placeholder  (m4_symbol_value *,
+                                                         char *);
 
 
 
Index: m4/m4private.h
===================================================================
RCS file: /sources/m4/m4/m4/m4private.h,v
retrieving revision 1.51
diff -u -p -b -r1.51 m4private.h
--- m4/m4private.h      22 Jul 2006 19:23:04 -0000      1.51
+++ m4/m4private.h      28 Jul 2006 13:41:30 -0000
@@ -39,9 +39,10 @@ extern int errno;
 typedef struct m4__search_path_info m4__search_path_info;
 
 typedef enum {
-  M4_SYMBOL_VOID,
-  M4_SYMBOL_TEXT,
-  M4_SYMBOL_FUNC
+  M4_SYMBOL_VOID, /* Traced but undefined.  */
+  M4_SYMBOL_TEXT, /* Plain text.  */
+  M4_SYMBOL_FUNC, /* Builtin function.  */
+  M4_SYMBOL_PLACEHOLDER, /* Placeholder for unknown builtin during -R.  */
 } m4__symbol_type;
 
 #define BIT_TEST(flags, bit)   (((flags) & (bit)) == (bit))
@@ -160,8 +161,8 @@ struct m4_symbol_value {
 
   m4__symbol_type      type;
   union {
-    char *             text;
-    m4_builtin_func *  func;
+    char *             text; /* Valid when type is TEXT, PLACEHOLDER.  */
+    m4_builtin_func *  func; /* Valid when type is FUNC.  */
   } u;
 };
 
@@ -191,13 +192,19 @@ struct m4_symbol_value {
 #  define m4_is_symbol_value_text(V)   ((V)->type == M4_SYMBOL_TEXT)
 #  define m4_is_symbol_value_func(V)   ((V)->type == M4_SYMBOL_FUNC)
 #  define m4_is_symbol_value_void(V)   ((V)->type == M4_SYMBOL_VOID)
+#  define m4_is_symbol_value_placeholder(V)                            \
+                                       ((V)->type == M4_SYMBOL_PLACEHOLDER)
 #  define m4_get_symbol_value_text(V)  ((V)->u.text)
 #  define m4_get_symbol_value_func(V)  ((V)->u.func)
+#  define m4_get_symbol_value_placeholder(V)                           \
+                                       ((V)->u.text)
 
 #  define m4_set_symbol_value_text(V, T)                               \
        ((V)->type = M4_SYMBOL_TEXT, (V)->u.text = (T))
 #  define m4_set_symbol_value_func(V, F)                               \
        ((V)->type = M4_SYMBOL_FUNC, (V)->u.func = (F))
+#  define m4_set_symbol_value_placeholder(V, T)                                
\
+       ((V)->type = M4_SYMBOL_PLACEHOLDER, (V)->u.text = (T))
 #endif
 
 
Index: m4/macro.c
===================================================================
RCS file: /sources/m4/m4/m4/macro.c,v
retrieving revision 1.45
diff -u -p -b -r1.45 macro.c
--- m4/macro.c  10 Jun 2006 13:41:06 -0000      1.45
+++ m4/macro.c  28 Jul 2006 13:41:30 -0000
@@ -329,6 +329,12 @@ m4_macro_call (m4 *context, m4_symbol *s
     {
       (*m4_get_symbol_func (symbol)) (context, expansion, argc, argv);
     }
+  else if (m4_is_symbol_placeholder (symbol))
+    {
+      M4WARN ((m4_get_warning_status_opt (context), 0, _("\
+Warning: %s: builtin `%s' requested by frozen file not found"),
+              M4ARG(0), m4_get_symbol_placeholder (symbol)));
+    }
   else
     {
       M4ERROR ((m4_get_warning_status_opt (context), 0,
@@ -594,6 +600,11 @@ INTERNAL ERROR: Builtin not found in bui
                }
              trace_format (context, "<%s>", bp->name);
            }
+         else if (m4_is_symbol_value_placeholder (argv[i]))
+           {
+             trace_format (context, "<placeholder for %s>",
+                           m4_get_symbol_value_placeholder (argv[i]));
+           }
          else
            {
              M4ERROR ((m4_get_warning_status_opt (context), 0,
Index: m4/symtab.c
===================================================================
RCS file: /sources/m4/m4/m4/symtab.c,v
retrieving revision 1.54
diff -u -p -b -r1.54 symtab.c
--- m4/symtab.c 22 Jul 2006 19:23:04 -0000      1.54
+++ m4/symtab.c 28 Jul 2006 13:41:30 -0000
@@ -471,6 +471,14 @@ m4_is_symbol_value_func (m4_symbol_value
   return (value->type == M4_SYMBOL_FUNC);
 }
 
+#undef m4_is_symbol_value_placeholder
+bool
+m4_is_symbol_value_placeholder (m4_symbol_value *value)
+{
+  assert (value);
+  return (value->type == M4_SYMBOL_PLACEHOLDER);
+}
+
 #undef m4_is_symbol_value_void
 bool
 m4_is_symbol_value_void (m4_symbol_value *value)
@@ -483,7 +491,7 @@ m4_is_symbol_value_void (m4_symbol_value
 char *
 m4_get_symbol_value_text (m4_symbol_value *value)
 {
-  assert (value);
+  assert (value && value->type == M4_SYMBOL_TEXT);
   return value->u.text;
 }
 
@@ -491,10 +499,18 @@ m4_get_symbol_value_text (m4_symbol_valu
 m4_builtin_func *
 m4_get_symbol_value_func (m4_symbol_value *value)
 {
-  assert (value);
+  assert (value && value->type == M4_SYMBOL_FUNC);
   return value->u.func;
 }
 
+#undef m4_get_symbol_value_placeholder
+char *
+m4_get_symbol_value_placeholder (m4_symbol_value *value)
+{
+  assert (value && value->type == M4_SYMBOL_PLACEHOLDER);
+  return value->u.text;
+}
+
 #undef m4_set_symbol_value_text
 void
 m4_set_symbol_value_text (m4_symbol_value *value, char *text)
@@ -517,6 +533,17 @@ m4_set_symbol_value_func (m4_symbol_valu
   value->u.func = func;
 }
 
+#undef m4_set_symbol_value_placeholder
+void
+m4_set_symbol_value_placeholder (m4_symbol_value *value, char *text)
+{
+  assert (value);
+  assert (text);
+
+  value->type   = M4_SYMBOL_PLACEHOLDER;
+  value->u.text = text;
+}
+
 
 
 #ifdef DEBUG_SYM
@@ -530,7 +557,8 @@ symtab_dump (m4_symbol_table *symtab)
   return symtab_apply (symtab, dump_symbol_CB, NULL);
 }
 
-static void *dump_symbol_CB (m4_symbol_table *symtab, const char *name,
+static void *
+dump_symbol_CB (m4_symbol_table *symtab, const char *name,
                             m4_symbol *symbol, void *ignored)
 {
   m4_symbol_value *value       = m4_get_symbol_value (symbol);
@@ -558,6 +586,10 @@ static void *dump_symbol_CB (m4_symbol_t
        fprintf (stderr, "<%s>",
                 bp ? bp->name : "!ERROR!");
        break;
+      case M4_SYMBOL_PLACEHOLDER:
+       fprintf (stderr, "<placeholder for %s>",
+                m4_get_symbol_placeholder (symbol));
+       break;
       case M4_SYMBOL_VOID:
        fputs ("<!VOID!>", stderr);
        break;
Index: modules/m4.c
===================================================================
RCS file: /sources/m4/m4/modules/m4.c,v
retrieving revision 1.62
diff -u -p -b -r1.62 m4.c
--- modules/m4.c        10 Jun 2006 21:23:30 -0000      1.62
+++ modules/m4.c        28 Jul 2006 13:41:30 -0000
@@ -385,9 +385,14 @@ M4BUILTIN_HANDLER (dumpdef)
          assert (bp);
          fprintf (stderr, "<%s>\n", bp->name);
        }
+      else if (m4_is_symbol_placeholder (symbol))
+       {
+         fprintf (stderr, "<placeholder for %s>\n",
+                  m4_get_symbol_placeholder (symbol));
+       }
       else
        {
-         assert (!"illegal token in builtin_dumpdef");
+         assert (!"invalid token in builtin_dumpdef");
        }
     }
 }
@@ -412,6 +417,10 @@ M4BUILTIN_HANDLER (defn)
        m4_shipout_string (context, obs, m4_get_symbol_text (symbol), 0, true);
       else if (m4_is_symbol_func (symbol))
        m4_push_builtin (m4_get_symbol_value (symbol));
+      else if (m4_is_symbol_placeholder (symbol))
+       M4WARN ((m4_get_warning_status_opt (context), 0, _("\
+Warning: %s: builtin `%s' requested by frozen file not found"),
+                name, m4_get_symbol_placeholder (symbol)));
       else
        assert (!"Bad token data type in m4_defn");
     }
Index: src/freeze.c
===================================================================
RCS file: /sources/m4/m4/src/freeze.c,v
retrieving revision 1.45
diff -u -p -b -r1.45 freeze.c
--- src/freeze.c        27 Jul 2006 13:29:31 -0000      1.45
+++ src/freeze.c        28 Jul 2006 13:41:30 -0000
@@ -208,6 +208,8 @@ dump_symbol_CB (m4_symbol_table *symtab,
        fputs (module_name, file);
       fputc ('\n', file);
     }
+  else if (m4_is_symbol_placeholder (symbol))
+    ; /* Nothing to do for a builtin we couldn't reload earlier.  */
   else
     return "INTERNAL ERROR: Bad token data type in produce_symbol_dump ()";
 
@@ -535,32 +537,32 @@ ill-formed frozen file, version 2 direct
          {
            const m4_builtin *bp;
            lt_dlhandle handle   = 0;
+           m4_symbol_value *token = xzalloc (sizeof *token);
 
            if (number[2] > 0)
              handle = m4__module_find (string[2]);
 
            bp = m4_builtin_find_by_name (handle, string[1]);
+           VALUE_HANDLE (token) = handle;
 
            if (bp)
              {
-               m4_symbol_value *token = xzalloc (sizeof *token);
-
                if (bp->groks_macro_args)
                  BIT_SET (VALUE_FLAGS (token), VALUE_MACRO_ARGS_BIT);
                if (bp->blind_if_no_args)
                  BIT_SET (VALUE_FLAGS (token), VALUE_BLIND_ARGS_BIT);
 
                m4_set_symbol_value_func (token, bp->func);
-               VALUE_HANDLE (token)    = handle;
                VALUE_MIN_ARGS (token)  = bp->min_args;
                VALUE_MAX_ARGS (token)  = bp->max_args;
-
-               m4_symbol_pushdef (M4SYMTAB, string[0], token);
              }
            else
-             M4ERROR ((m4_get_warning_status_opt (context), 0,
-                       _("`%s' from frozen file not found in builtin table!"),
-                       string[0]));
+             {
+               m4_set_symbol_value_placeholder (token, string[1]);
+               VALUE_MIN_ARGS (token) = -1;
+               VALUE_MAX_ARGS (token) = -1;
+             }
+           m4_symbol_pushdef (M4SYMTAB, string[0], token);
          }
          break;
 
Index: tests/freeze.at
===================================================================
RCS file: /sources/m4/m4/tests/freeze.at,v
retrieving revision 1.2
diff -u -p -b -r1.2 freeze.at
--- tests/freeze.at     13 Jul 2006 23:35:16 -0000      1.2
+++ tests/freeze.at     28 Jul 2006 13:41:30 -0000
@@ -99,6 +99,8 @@ define 1
  3
 my_define(bar, 4) 3
 bar
+]],
+[[m4: input.m4: 5: Warning: popdef: undefined name: my_define
 ]])
 
 AT_CLEANUP

reply via email to

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