m4-patches
[Top][All Lists]
Advanced

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

minor cleanups


From: Eric Blake
Subject: minor cleanups
Date: Wed, 27 Sep 2006 06:24:39 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.666

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

Various little things I noticed.  Some of them, like avoiding side-effects
in the second argument to obstack_1grow, are not strict bug fixes (since
that particular macro only evaluates its second arg once, even on
non-gcc), but are in line with what obstack.h recommends for all of the
obstack_* calls.  Others, like asserting that an obstack is empty, will
help catch bugs if I ever get text and builtins combined into a single
argument, as part of my (ever-growing) local patch to try to fix the xfail
of the defn test.  Then using fputs instead of fprintf is a minor speedup.

2006-09-27  Eric Blake  <address@hidden>

        * modules/m4.c (m4_dump_symbols, errprint, m4wrap)
        (m4_expand_ranges): Ensure we aren't picking up partial object on
        obstack.
        * modules/stdlib.c (setenv): Allow extra arguments.
        * modules/time.c (ctime): Avoid side effect in call to
        obstack_grow.
        * modules/gnu.c (m4_regexp_substitute): Likewise.
        (renamesyms): Avoid extra obstack_init.
        * src/freeze.c (reload_frozen_state): Remove debug comment.
        (produce_frozen_state): Simplify fprintf to puts where possible.
        * modules/modtest.c (modtest_init, modtest_finish): Likewise.
        * modules/import.c (import, symbol_fail, modules_fail): Likewise.
        * m4/macro.c (trace_flush): Likewise.
        * m4/debug.c (m4_debug_message_prefix): Likewise.
        * m4/path.c (include_dump): Likewise.
        * m4/module.c (module_remove): Likewise.
        (install_builtin_table): Simplify malloc and string
        concatenation.

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

iD8DBQFFGm2H84KuGfSFAYARAsHnAJ9BeHDo5JVwzEKmdK+zg8io8+1GugCgtLj6
k/VDPMvcN6MjvP4jNvE799Y=
=IDst
-----END PGP SIGNATURE-----
Index: m4/debug.c
===================================================================
RCS file: /sources/m4/m4/m4/debug.c,v
retrieving revision 1.26
diff -u -p -r1.26 debug.c
--- m4/debug.c  26 Sep 2006 21:21:50 -0000      1.26
+++ m4/debug.c  27 Sep 2006 12:18:25 -0000
@@ -204,7 +204,7 @@ m4_debug_message_prefix (m4 *context)
   assert (context);
 
   debug_file = m4_get_debug_file (context);
-  fprintf (debug_file, "m4debug:");
+  fputs ("m4debug:", debug_file);
   if (m4_get_current_line (context))
     {
       if (m4_is_debug_bit (context, M4_DEBUG_TRACE_FILE))
Index: m4/macro.c
===================================================================
RCS file: /sources/m4/m4/m4/macro.c,v
retrieving revision 1.53
diff -u -p -r1.53 macro.c
--- m4/macro.c  7 Sep 2006 23:53:04 -0000       1.53
+++ m4/macro.c  27 Sep 2006 12:18:25 -0000
@@ -583,10 +583,11 @@ trace_flush (m4 *context)
 {
   char *line;
 
+  obstack_1grow (&context->trace_messages, '\n');
   obstack_1grow (&context->trace_messages, '\0');
   line = obstack_finish (&context->trace_messages);
   if (m4_get_debug_file (context))
-    fprintf (m4_get_debug_file (context), "%s\n", line);
+    fputs (line, m4_get_debug_file (context));
   obstack_free (&context->trace_messages, line);
 }
 
Index: m4/module.c
===================================================================
RCS file: /sources/m4/m4/m4/module.c,v
retrieving revision 1.45
diff -u -p -r1.45 module.c
--- m4/module.c 5 Sep 2006 23:16:40 -0000       1.45
+++ m4/module.c 27 Sep 2006 12:18:25 -0000
@@ -21,6 +21,7 @@
 #include "pathconf.h"
 #include "ltdl.h"
 #include "m4private.h"
+#include "xvasprintf.h"
 
 /* Define this to see runtime debug info.  Implied by DEBUG.  */
 /*#define DEBUG_MODULES */
@@ -143,7 +144,7 @@ install_builtin_table (m4 *context, lt_d
       for (; bp->name != NULL; bp++)
        {
          m4_symbol_value *value = m4_symbol_value_create ();
-         char *           name;
+         const char *     name;
 
          /* Sanity check that builtins meet the required interface.  */
          assert (bp->min_args <= bp->max_args);
@@ -159,20 +160,14 @@ install_builtin_table (m4 *context, lt_d
          VALUE_MAX_ARGS (value)        = bp->max_args;
 
          if (m4_get_prefix_builtins_opt (context))
-           {
-             static const char prefix[] = "m4_";
-             size_t len = strlen (prefix) + strlen (bp->name);
-
-             name = (char *) xmalloc (1+ len);
-             snprintf (name, 1+ len, "%s%s", prefix, bp->name);
-           }
+           name = xasprintf ("m4_%s", bp->name);
          else
-           name = (char *) bp->name;
+           name = bp->name;
 
          m4_symbol_pushdef (M4SYMTAB, name, value);
 
          if (m4_get_prefix_builtins_opt (context))
-           free (name);
+           free ((char *) name);
        }
 
       m4_debug_message (context, M4_DEBUG_TRACE_MODULE,
@@ -365,7 +360,7 @@ m4__module_init (m4 *context)
              module_dlerror ());
 
 #ifdef DEBUG_MODULES
-  fprintf (stderr, "Module loader initialized.\n");
+  fputs ("Module loader initialized.\n", stderr);
 #endif /* DEBUG_MODULES */
 }
 
Index: m4/path.c
===================================================================
RCS file: /sources/m4/m4/m4/path.c,v
retrieving revision 1.21
diff -u -p -r1.21 path.c
--- m4/path.c   26 Sep 2006 13:19:26 -0000      1.21
+++ m4/path.c   27 Sep 2006 12:18:25 -0000
@@ -215,7 +215,7 @@ include_dump (m4 *context)
 {
   m4__search_path *incl;
 
-  fprintf (stderr, "include_dump:\n");
+  fputs ("include_dump:\n", stderr);
   for (incl = m4__get_search_path (context)->list;
        incl != NULL; incl = incl->next)
     fprintf (stderr, "\t%s\n", incl->dir);
Index: modules/gnu.c
===================================================================
RCS file: /sources/m4/m4/modules/gnu.c,v
retrieving revision 1.57
diff -u -p -r1.57 gnu.c
--- modules/gnu.c       26 Sep 2006 13:19:26 -0000      1.57
+++ modules/gnu.c       27 Sep 2006 12:18:26 -0000
@@ -267,7 +267,10 @@ m4_regexp_substitute (m4 *context, m4_ob
 
       offset = buf->regs.end[0];
       if (buf->regs.start[0] == buf->regs.end[0])
-       obstack_1grow (obs, victim[offset++]);
+       {
+         obstack_1grow (obs, victim[offset]);
+         offset++;
+       }
     }
 
   if (!ignore_duplicates || subst)
@@ -641,7 +644,6 @@ M4BUILTIN_HANDLER (renamesyms)
       m4_pattern_buffer *buf;  /* compiled regular expression */
 
       m4_dump_symbol_data      data;
-      m4_obstack               data_obs;
       m4_obstack               rename_obs;
 
       int resyntax;
@@ -663,8 +665,7 @@ M4BUILTIN_HANDLER (renamesyms)
        return;
 
       obstack_init (&rename_obs);
-      obstack_init (&data_obs);
-      data.obs = &data_obs;
+      data.obs = obs;
 
       m4_dump_symbols (context, &data, 1, argv, false);
 
@@ -681,7 +682,6 @@ M4BUILTIN_HANDLER (renamesyms)
            }
        }
 
-      obstack_free (&data_obs, NULL);
       obstack_free (&rename_obs, NULL);
     }
   else
Index: modules/import.c
===================================================================
RCS file: /sources/m4/m4/modules/import.c,v
retrieving revision 1.6
diff -u -p -r1.6 import.c
--- modules/import.c    26 Sep 2006 13:19:26 -0000      1.6
+++ modules/import.c    27 Sep 2006 12:18:26 -0000
@@ -68,7 +68,7 @@ M4BUILTIN_HANDLER (import)
   obstack_grow (obs, s, strlen(s));
 
   if (export_test && export_test (M4ARG (1)))
-    fprintf (stderr, "TRUE\n");
+    fputs ("TRUE\n", stderr);
 }
 
 /**
@@ -84,7 +84,7 @@ M4BUILTIN_HANDLER (symbol_fail)
   obstack_grow (obs, s, strlen(s));
 
   if (no_such && no_such (M4ARG (1)))
-    fprintf (stderr, "TRUE\n");
+    fputs ("TRUE\n", stderr);
 }
 
 /**
@@ -100,5 +100,5 @@ M4BUILTIN_HANDLER (module_fail)
   obstack_grow (obs, s, strlen(s));
 
   if (no_such && no_such (M4ARG (1)))
-    fprintf (stderr, "TRUE\n");
+    fputs ("TRUE\n", stderr);
 }
Index: modules/m4.c
===================================================================
RCS file: /sources/m4/m4/modules/m4.c,v
retrieving revision 1.73
diff -u -p -r1.73 m4.c
--- modules/m4.c        26 Sep 2006 21:21:50 -0000      1.73
+++ modules/m4.c        27 Sep 2006 12:18:26 -0000
@@ -332,6 +332,7 @@ void
 m4_dump_symbols (m4 *context, m4_dump_symbol_data *data, int argc,
                 m4_symbol_value **argv, bool complain)
 {
+  assert (obstack_object_size (data->obs) == 0);
   data->size = obstack_room (data->obs) / sizeof (const char *);
 
   if (argc == 1)
@@ -683,6 +684,7 @@ M4BUILTIN_HANDLER (maketemp)
 /* Print all arguments on standard error.  */
 M4BUILTIN_HANDLER (errprint)
 {
+  assert (obstack_object_size (obs) == 0);
   m4_dump_args (context, obs, argc, argv, " ", false);
   obstack_1grow (obs, '\0');
   fputs ((char *) obstack_finish (obs), stderr);
@@ -714,6 +716,7 @@ M4BUILTIN_HANDLER (m4exit)
    version only the first.  */
 M4BUILTIN_HANDLER (m4wrap)
 {
+  assert (obstack_object_size (obs) == 0);
   if (m4_get_no_gnu_extensions_opt (context))
     m4_shipout_string (context, obs, M4ARG (1), 0, false);
   else
@@ -820,6 +823,7 @@ m4_expand_ranges (const char *s, m4_obst
   char from;
   char to;
 
+  assert (obstack_object_size (obs) == 0);
   for (from = '\0'; *s != '\0'; from = *s++)
     {
       if (*s == '-' && from != '\0')
Index: modules/modtest.c
===================================================================
RCS file: /sources/m4/m4/modules/modtest.c,v
retrieving revision 1.14
diff -u -p -r1.14 modtest.c
--- modules/modtest.c   26 Sep 2006 13:19:26 -0000      1.14
+++ modules/modtest.c   27 Sep 2006 12:18:26 -0000
@@ -1,5 +1,6 @@
 /* GNU m4 -- A simple macro processor
-   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2006 Free Software Foundation, 
Inc.
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2006 Free Software
+   Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -67,11 +68,11 @@ m4_macro m4_macro_table[] =
  **/
 M4INIT_HANDLER (modtest)
 {
-  const char *s = "Test module loaded.";
+  const char *s = "Test module loaded.\n";
 
   /* Don't depend on OBS so that the traces are the same when used
      directly, or via a frozen file.  */
-  fprintf (stderr, "%s\n", s);
+  fputs (s, stderr);
 }
 
 
@@ -80,11 +81,11 @@ M4INIT_HANDLER (modtest)
  **/
 M4FINISH_HANDLER (modtest)
 {
-  const char *s = "Test module unloaded.";
+  const char *s = "Test module unloaded.\n";
 
   /* Don't depend on OBS so that the traces are the same when used
      directly, or via a frozen file.  */
-  fprintf (stderr, "%s\n", s);
+  fputs (s, stderr);
 }
 
 
Index: modules/stdlib.c
===================================================================
RCS file: /sources/m4/m4/modules/stdlib.c,v
retrieving revision 1.15
diff -u -p -r1.15 stdlib.c
--- modules/stdlib.c    26 Sep 2006 13:19:26 -0000      1.15
+++ modules/stdlib.c    27 Sep 2006 12:18:26 -0000
@@ -105,7 +105,7 @@ M4BUILTIN_HANDLER (setenv)
 {
   int overwrite = 1;
 
-  if (argc == 4)
+  if (argc >= 4)
     if (!m4_numeric_arg (context, argc, argv, 3, &overwrite))
       return;
 
@@ -116,6 +116,7 @@ M4BUILTIN_HANDLER (setenv)
   if (!overwrite && getenv (M4ARG (1)) != NULL)
     return;
 
+  assert (obstack_object_size (obs) == 0);
   obstack_grow (obs, M4ARG (1), strlen (M4ARG (1)));
   obstack_1grow (obs, '=');
   obstack_grow (obs, M4ARG (2), strlen (M4ARG (2)));
Index: modules/time.c
===================================================================
RCS file: /sources/m4/m4/modules/time.c,v
retrieving revision 1.16
diff -u -p -r1.16 time.c
--- modules/time.c      26 Sep 2006 13:19:26 -0000      1.16
+++ modules/time.c      27 Sep 2006 12:18:26 -0000
@@ -98,6 +98,7 @@ M4BUILTIN_HANDLER (ctime)
 {
   time_t t;
   int i;
+  const char *s;
 
   if (argc == 2)
     {
@@ -107,7 +108,8 @@ M4BUILTIN_HANDLER (ctime)
   else
     t = time (0L);
 
-  obstack_grow (obs, ctime (&t), 24);
+  s = ctime (&t);
+  obstack_grow (obs, s, 24);
 }
 
 static void
Index: src/freeze.c
===================================================================
RCS file: /sources/m4/m4/src/freeze.c,v
retrieving revision 1.50
diff -u -p -r1.50 freeze.c
--- src/freeze.c        29 Aug 2006 20:38:30 -0000      1.50
+++ src/freeze.c        27 Sep 2006 12:18:26 -0000
@@ -98,7 +98,7 @@ produce_resyntax_dump (m4 *context, FILE
        m4_error (context, EXIT_FAILURE, 0,
                  _("invalid regexp syntax code `%d'"), code);
 
-      fprintf (file, "R%d\n%s\n", strlen(resyntax), resyntax);
+      fprintf (file, "R%d\n%s\n", strlen (resyntax), resyntax);
     }
 }
 
@@ -235,7 +235,7 @@ produce_frozen_state (m4 *context, const
 
   fprintf (file, "# This is a frozen state file generated by GNU %s %s\n",
           PACKAGE, VERSION);
-  fprintf (file, "V2\n");
+  fputs ("V2\n", file);
 
   /* Dump quote delimiters.  */
 
@@ -388,7 +388,7 @@ reload_frozen_state (m4 *context, const 
 #define GET_STRING(File, Buf, BufSize, StrLen)                 \
   do                                                           \
     {                                                          \
-      CHECK_ALLOCATION((Buf), (BufSize), (StrLen));            \
+      CHECK_ALLOCATION ((Buf), (BufSize), (StrLen));           \
       if ((StrLen) > 0)                                                \
        if (!fread ((Buf), (size_t) (StrLen), 1, (File)))       \
          m4_error (context, EXIT_FAILURE, 0,                   \
@@ -463,7 +463,6 @@ reload_frozen_state (m4 *context, const 
       break;
     case 1:
       {
-       //      sleep(100);
        m4__module_open (context, "m4", NULL);
        if (m4_get_no_gnu_extensions_opt (context))
          m4__module_open (context, "traditional", NULL);
@@ -625,7 +624,7 @@ ill-formed frozen file, version 2 direct
          GET_NUMBER (number[0]);
          VALIDATE ('\n');
 
-         CHECK_ALLOCATION(string[0], allocated[0], number[0]);
+         CHECK_ALLOCATION (string[0], allocated[0], number[0]);
          if (number[0] > 0)
            {
              int i;

reply via email to

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