m4-patches
[Top][All Lists]
Advanced

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

FYI: 34-gary-refactor-path-api.patch


From: Gary V. Vaughan
Subject: FYI: 34-gary-refactor-path-api.patch
Date: Tue, 29 Jul 2003 16:59:12 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5a) Gecko/20030718

Applied to HEAD.
--
  ())_.  Gary V. Vaughan    gary@(oranda.demon.co.uk|gnu.org)
  ( '/   Research Scientist http://www.oranda.demon.co.uk       ,_())____
  / )=   GNU Hacker         http://www.gnu.org/software/libtool  \'      `&
`(_~)_   Tech' Author       http://sources.redhat.com/autobook   =`---d__/
Index: ChangeLog
from  Gary V. Vaughan  <address@hidden>

        Aside from auditing path.c for m4module.h api obfuscation, this
        delta introduces the concept of private struct members in opaque
        data types to GNU m4: See the STYLE file for details.

        * TODO: Remind ourselves that a rewrite of path.c is needed.
        * m4/m4module.h (m4_search_path, struct m4_search_path_info):
        Moved from here...
        * m4/m4private.h (m4__search_path, m4__search_path_info): ...to
        here and renamed.  These type definitions are for internal api use
        only.  Changed all callers.
        * m4/m4module.h (m4_search_path_env_init, m4_search_path_add):
        Moved from here...
        * m4/path.c (search_path_env_init, search_path_add): ...to here
        and renamed.  These calls were never used outside this file.
        Changed all callers.
        (dirpath): Moved functionality of this static declaration...
        * m4/m4private.h (struct m4): ...to this new internal only
        search_path field.  Changed all callers.
        (m4__get_search_path): Added new internal api accessor.
        * m4/path.c (m4_search_path_info_new):  Removed.  Not used.
        (m4_include_init): Removed...
        * m4/m4.c (m4_create): ...because the new m4 field is now
        initialised here.
        (m4_delete): Recycle search_path memory.
        * src/main.c (main): Don't call m4_include_init now that it's
        gone!
        * doc/STYLE: Document convention for private fields in opaque
        ADTs.

Index: TODO
===================================================================
RCS file: /cvsroot/m4/m4/TODO,v
retrieving revision 1.11
diff -u -p -u -r1.11 TODO
--- TODO 24 Jul 2003 11:37:43 -0000 1.11
+++ TODO 29 Jul 2003 15:57:04 -0000
@@ -92,6 +92,12 @@ for any of these ideas or if you have ot
     We should be making the library reentrant so that multiple instances
     of m4 can be run in the same process at the same time.
 
+  + The path management stuff (in path.c/m4private.h) is reinventing the
+    wheel.  There are a bunch of fast path management and search functions
+    in ltdl.c:  These need to be sanitized, exported through ltdl.h, and
+    then wrapped by the m4module.h path api.  path.c can probably be removed
+    entirely at that point.
+
 * MODULE SPECIFIC ISSUES
 
   + Some way of linking a module statically is needed, for systems
Index: doc/STYLE
===================================================================
RCS file: /cvsroot/m4/m4/doc/STYLE,v
retrieving revision 1.1
diff -u -p -u -r1.1 STYLE
--- doc/STYLE 26 Jun 2003 14:56:15 -0000 1.1
+++ doc/STYLE 29 Jul 2003 15:57:04 -0000
@@ -20,7 +20,7 @@ following restrictions on coding style a
     but are not part of the supported library api have the prefix
     `m4__',
 
-  + Function names should be verb phrases; m4_get_module_field.
+  + Function names should be verb phrases; m4_module_get_field.
 
   + Functions which exist to be used as callbacks from API functions, and
     hence which likely have strange looking parameters are named with the
@@ -48,6 +48,13 @@ following restrictions on coding style a
   + Structures are typedeffed separately, and the structure itself
     generally not exported unless in the `m4__' namespace to support
     fast accessor macros.
+
+  + An opaque abstract data type (ADT) can have public and private fields:
+    By convention public fields will have exported accessor functions (and
+    maybe also fast macro versions of the same), and private fields will
+    not export accessors at all.  However, there should be non-exported
+    (or at least in the `m4__' namespace) accessor functions for even the
+    private fields of an ADI to aid possible later refactoring.
 
 * ARCHITECTURE
 
Index: m4/m4.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4.c,v
retrieving revision 1.6
diff -u -p -u -r1.6 m4.c
--- m4/m4.c 23 Jul 2003 11:51:26 -0000 1.6
+++ m4/m4.c 29 Jul 2003 15:57:04 -0000
@@ -33,6 +33,8 @@ m4_create (void)
 
   context->nesting_limit = M4_DEFAULT_NESTING_LIMIT;
 
+  context->search_path           = XCALLOC (m4__search_path_info, 1);
+
   return context;
 }
 
@@ -52,6 +54,21 @@ m4_delete (m4 *context)
 
   obstack_free (&context->trace_messages, NULL);
 
+  if (context->search_path)
+    {
+      m4__search_path *path = context->search_path->list;
+
+      while (path)
+       {
+         m4__search_path *stale = path;
+         path = path->next;
+
+         xfree ((void*) stale->dir);
+         xfree (stale);
+       }
+      xfree (context->search_path);
+    }
+
   xfree (context);
 }
 
@@ -72,7 +89,6 @@ m4_delete (m4 *context)
 #undef m4_get_interactive_opt
 #undef m4_get_sync_output_opt
 #undef m4_get_posixly_correct_opt
-
 
 #define M4FIELD(type, base, field)                                     \
        type CONC(m4_get_, base) (m4 *context)                          \
Index: m4/m4module.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4module.h,v
retrieving revision 1.61
diff -u -p -u -r1.61 m4module.h
--- m4/m4module.h 24 Jul 2003 14:21:02 -0000 1.61
+++ m4/m4module.h 29 Jul 2003 15:57:04 -0000
@@ -401,32 +401,14 @@ extern void       m4_insert_file       (FILE *)
 extern void    m4_freeze_diversions (FILE *);
 extern void    m4_undivert_all      (void);
 
-extern void    m4_include_init          (void);
+
+
+/* --- PATH MANAGEMENT --- */
+
 extern void    m4_include_env_init      (m4 *);
 extern void    m4_add_include_directory (m4 *, const char *);
 extern FILE *   m4_path_search           (m4 *, const char *, char **);
 
-/* These are for other search paths */
-
-struct m4_search_path
-{
-  struct m4_search_path *next; /* next directory to search */
-  const char *dir;             /* directory */
-  int len;
-};
-
-typedef struct m4_search_path m4_search_path;
-
-struct m4_search_path_info
-{
-  m4_search_path *list;                /* the list of path directories */
-  m4_search_path *list_end;    /* the end of same */
-  int max_length;              /* length of longest directory name */
-};
-
-extern struct m4_search_path_info *m4_search_path_info_new (void);
-extern void    m4_search_path_env_init (struct m4_search_path_info *, char *, 
boolean);
-extern void    m4_search_path_add (struct m4_search_path_info *, const char *);
 
 
 #define obstack_chunk_alloc    xmalloc
Index: m4/m4private.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4private.h,v
retrieving revision 1.31
diff -u -p -u -r1.31 m4private.h
--- m4/m4private.h 24 Jul 2003 14:21:02 -0000 1.31
+++ m4/m4private.h 29 Jul 2003 15:57:04 -0000
@@ -28,6 +28,8 @@
 
 #include "m4module.h"
 
+typedef struct m4__search_path_info m4__search_path_info;
+
 typedef enum {
   M4_SYMBOL_VOID,
   M4_SYMBOL_TEXT,
@@ -42,11 +44,11 @@ typedef enum {
 /* --- CONTEXT MANAGEMENT --- */
 
 struct m4 {
-  m4_symbol_table *symtab;
-  m4_syntax_table *syntax;
+  m4_symbol_table *    symtab;
+  m4_syntax_table *    syntax;
 
-  FILE *        debug_file;            /* File for debugging output.  */
-  m4_obstack trace_messages;
+  FILE *               debug_file;     /* File for debugging output.  */
+  m4_obstack           trace_messages;
 
   /* Option flags  (set in src/main.c).  */
   int          warning_status;                 /* -E */
@@ -55,6 +57,9 @@ struct m4 {
   int          debug_level;                    /* -d */
   int          max_debug_arg_length;           /* -l */
   int          opt_flags;
+
+  /* __PRIVATE__: */
+  m4__search_path_info *search_path;   /* The list of path directories. */
 };
 
 #define M4_OPT_PREFIX_BUILTINS_BIT     (1 << 0) /* -P */
@@ -64,6 +69,8 @@ struct m4 {
 #define M4_OPT_SYNC_OUTPUT_BIT         (1 << 4) /* -s */
 #define M4_OPT_POSIXLY_CORRECT_BIT     (1 << 5) /* POSIXLY_CORRECT */
 
+/* Fast macro versions of accessor functions for public fields of m4,
+   that also have an identically named function exported in m4module.h.  */
 #ifdef NDEBUG
 #  define m4_get_symbol_table(C)               ((C)->symtab)
 #  define m4_get_syntax_table(C)               ((C)->syntax)
@@ -89,6 +96,10 @@ struct m4 {
                (BIT_TEST((C)->opt_flags, M4_OPT_POSIXLY_CORRECT_BIT))
 #endif
 
+/* Accessors for private fields of m4, which have no function version
+   exported in m4module.h.  */
+#define m4__get_search_path(C)                 ((C)->search_path)
+
 
 
 /* --- MODULE MANAGEMENT --- */
@@ -185,7 +196,7 @@ struct m4_symbol_arg {
 #define SYMBOL_ARG_REST_BIT    (1 << 0)
 #define SYMBOL_ARG_KEY_BIT     (1 << 1)
 
-extern void    m4__symtab_remove_module_references (m4_symbol_table*, 
lt_dlhandle);
+extern void m4__symtab_remove_module_references (m4_symbol_table*, 
lt_dlhandle);
 
 
 
@@ -242,6 +253,24 @@ typedef enum {
 } m4__token_type;
 
 extern m4__token_type m4__next_token (m4 *context, m4_symbol_value *);
+
+
+
+/* --- PATH MANAGEMENT --- */
+
+typedef struct m4__search_path m4__search_path;
+
+struct m4__search_path {
+  m4__search_path *next;       /* next directory to search */
+  const char *dir;             /* directory */
+  int len;
+};
+
+struct m4__search_path_info {
+  m4__search_path *list;       /* the list of path directories */
+  m4__search_path *list_end;   /* the end of same */
+  int max_length;              /* length of longest directory name */
+};
 
 
 
Index: m4/path.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/path.c,v
retrieving revision 1.4
diff -u -p -u -r1.4 path.c
--- m4/path.c 20 Jun 2003 15:43:20 -0000 1.4
+++ m4/path.c 29 Jul 2003 15:57:04 -0000
@@ -39,36 +39,23 @@
 #include "m4module.h"
 #include "m4private.h"
 
-static struct m4_search_path_info dirpath; /* the list of path directories */
+static void search_path_add (m4__search_path_info *, const char *);
+static void search_path_env_init (m4__search_path_info *, char *, boolean);
 
 
 /*
  * General functions for search paths
  */
 
-struct m4_search_path_info *
-m4_search_path_info_new (void)
-{
-  struct m4_search_path_info *info;
-
-  info = (struct m4_search_path_info *)
-    xmalloc (sizeof (struct m4_search_path_info));
-  info->list = NULL;
-  info->list_end = NULL;
-  info->max_length = 0;
-
-  return info;
-}
-
-void
-m4_search_path_add (struct m4_search_path_info *info, const char *dir)
+static void
+search_path_add (m4__search_path_info *info, const char *dir)
 {
-  m4_search_path *path;
+  m4__search_path *path;
 
   if (*dir == '\0')
     dir = ".";
 
-  path = (struct m4_search_path *) xmalloc (sizeof (struct m4_search_path));
+  path = XMALLOC (m4__search_path, 1);
   path->next = NULL;
   path->len = strlen (dir);
   path->dir = xstrdup (dir);
@@ -83,9 +70,8 @@ m4_search_path_add (struct m4_search_pat
   info->list_end = path;
 }
 
-void
-m4_search_path_env_init (struct m4_search_path_info *info, char *path,
-                        boolean isabs)
+static void
+search_path_env_init (m4__search_path_info *info, char *path, boolean isabs)
 {
   char *path_end;
 
@@ -98,22 +84,13 @@ m4_search_path_env_init (struct m4_searc
       if (path_end)
        *path_end = '\0';
       if (!isabs || *path == '/')
-       m4_search_path_add (info, path);
+       search_path_add (info, path);
       path = path_end + 1;
     }
   while (path_end);
 }
 
 
-void
-m4_include_init (void)
-{
-  dirpath.list = NULL;
-  dirpath.list_end = NULL;
-  dirpath.max_length = 0;
-}
-
-
 /* Functions for normal input path search */
 
 void
@@ -122,7 +99,8 @@ m4_include_env_init (m4 *context)
   if (m4_get_no_gnu_extensions_opt (context))
     return;
 
-  m4_search_path_env_init (&dirpath, getenv ("M4PATH"), FALSE);
+  search_path_env_init (m4__get_search_path (context),
+                       getenv ("M4PATH"), FALSE);
 }
 
 void
@@ -131,7 +109,7 @@ m4_add_include_directory (m4 *context, c
   if (m4_get_no_gnu_extensions_opt (context))
     return;
 
-  m4_search_path_add (&dirpath, dir);
+  search_path_add (m4__get_search_path (context), dir);
 
 #ifdef DEBUG_INCL
   fprintf (stderr, "add_include_directory (%s);\n", dir);
@@ -142,7 +120,7 @@ FILE *
 m4_path_search (m4 *context, const char *dir, char **expanded_name)
 {
   FILE *fp;
-  struct m4_search_path *incl;
+  m4__search_path *incl;
   char *name;                  /* buffer for constructed name */
 
   /* Look in current working directory first.  */
@@ -158,9 +136,9 @@ m4_path_search (m4 *context, const char 
   if (*dir == '/' || m4_get_no_gnu_extensions_opt (context))
     return NULL;
 
-  name = (char *) xmalloc (dirpath.max_length + 1 + strlen (dir) + 1);
+  name = (char *) xmalloc (m4__get_search_path (context)->max_length + 1 + 
strlen (dir) + 1);
 
-  for (incl = dirpath.list; incl != NULL; incl = incl->next)
+  for (incl = m4__get_search_path (context)->list; incl != NULL; incl = 
incl->next)
     {
       strncpy (name, incl->dir, incl->len);
       name[incl->len] = '/';
@@ -193,10 +171,10 @@ m4_path_search (m4 *context, const char 
 static void
 include_dump (void)
 {
-  struct m4_search_path *incl;
+  m4__search_path *incl;
 
   fprintf (stderr, "include_dump:\n");
-  for (incl = dirpath.list; incl != NULL; incl = incl->next)
+  for (incl = m4__get_search_path (context)->list; incl != NULL; incl = 
incl->next)
     fprintf (stderr, "\t%s\n", incl->dir);
 }
 
Index: src/main.c
===================================================================
RCS file: /cvsroot/m4/m4/src/main.c,v
retrieving revision 1.47
diff -u -p -u -r1.47 main.c
--- src/main.c 23 Jul 2003 16:20:50 -0000 1.47
+++ src/main.c 29 Jul 2003 15:57:04 -0000
@@ -239,7 +239,6 @@ main (int argc, char *const *argv, char 
   context = m4_create ();
 
   m4__module_init (context);
-  m4_include_init ();
 
 #ifdef USE_STACKOVF
   setup_stackovf_trap (argv, envp, stackovf_handler);
@@ -527,7 +526,6 @@ warranty; not even for MERCHANTABILITY o
          }
        m4_macro_expand_input (context);
       }
-#undef NEXTARG
 
   /* Now handle wrapup text.  */
 

reply via email to

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