m4-patches
[Top][All Lists]
Advanced

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

FYI: 33-gary-inter-module-datatypes.patch


From: Gary V. Vaughan
Subject: FYI: 33-gary-inter-module-datatypes.patch
Date: Thu, 24 Jul 2003 15:25:56 +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>
        Sometimes exporting the address of a symbol from a module isn't
        enough for other modules to call that symbol correctly.  If
        custom data types are used for function parameters, they need to
        be known to the caller.  This change introduces the concept of
        $(prefix)/include/modules/$(modulename).h to declare those
        structures.  Also we move m4_dump_symbols from libm4 to the m4
        module to show this concept in action.

        * m4/m4module.h (m4_dump_symbol_data): Moved from here...
        * modules/m4.h (m4_dump_symbol_data): ...to this new file for
        exporting data structures from modules/m4.c.
        * modules/m4.c, modules/gnu.c: Include it.
        * modules/Makefile.am (pkgmodinc_HEADERS): Install it.
        * m4/m4module.h (m4_dump_symbol_CB, m4_dump_symbols): Removed
        prototypes.
        * m4/utility.c (dumpdef_cmp, m4_dump_symbol_CB, m4_dump_symbols):
        Moved from here...
        * modules/m4.c (dumpdef_cmp_CB, dump_symbol_CB, m4_dump_symbols):
        ...to here, with slight renaming.
        (m4_export_table): Prototype and add m4_dump_symbols.
        * m4/symtab.c (m4_is_symbol_value_void): Needed for an external
        definition of m4_dump_symbols.
        * m4/m4module.h (m4_is_symbol_value_void): Prototype it.
        * m4/m4private.h (m4_is_symbol_value_void): Fast macro version.

2003-07-24  Gary V. Vaughan  <address@hidden>

Index: m4/input.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/input.c,v
retrieving revision 1.34
diff -u -p -u -r1.34 input.c
--- m4/input.c 23 Jul 2003 16:20:49 -0000 1.34
+++ m4/input.c 24 Jul 2003 14:20:36 -0000
@@ -699,7 +699,7 @@ m4_input_init (void)
   start_of_input_line = FALSE;
 }
 
- void
+void
 m4_input_exit (void)
 {
   obstack_free (&wrapup_stack, NULL);
Index: m4/m4module.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4module.h,v
retrieving revision 1.60
diff -u -p -u -r1.60 m4module.h
--- m4/m4module.h 24 Jul 2003 12:16:46 -0000 1.60
+++ m4/m4module.h 24 Jul 2003 14:20:36 -0000
@@ -203,6 +203,7 @@ extern void         m4_symbol_value_copy      (m4_
                                                   m4_symbol_value *);
 extern boolean         m4_is_symbol_value_text   (m4_symbol_value *);
 extern boolean         m4_is_symbol_value_func   (m4_symbol_value *);
+extern boolean         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 void            m4_set_symbol_value_text  (m4_symbol_value *, char *);
@@ -426,21 +427,6 @@ struct m4_search_path_info
 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 *);
-
-
-/* The structure dump_symbol_data is used to pass the information needed
-   from call to call to dump_symbol.  */
-
-struct m4_dump_symbol_data
-{
-  m4_obstack *obs;             /* obstack for table */
-  const char **base;           /* base of table */
-  int size;                    /* size of table */
-};
-
-extern void *m4_dump_symbol_CB (m4_symbol_table*, const char*, m4_symbol *, 
void *);
-extern void m4_dump_symbols (m4 *context, struct m4_dump_symbol_data *data, 
int argc, m4_symbol_value **argv, boolean complain);
-
 
 
 #define obstack_chunk_alloc    xmalloc
Index: m4/m4private.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4private.h,v
retrieving revision 1.30
diff -u -p -u -r1.30 m4private.h
--- m4/m4private.h 23 Jul 2003 16:20:50 -0000 1.30
+++ m4/m4private.h 24 Jul 2003 14:20:36 -0000
@@ -152,6 +152,7 @@ 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_get_symbol_value_text(V)  ((V)->u.text)
 #  define m4_get_symbol_value_func(V)  ((V)->u.func)
 
Index: m4/symtab.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/symtab.c,v
retrieving revision 1.41
diff -u -p -u -r1.41 symtab.c
--- m4/symtab.c 26 Jun 2003 14:57:32 -0000 1.41
+++ m4/symtab.c 24 Jul 2003 14:20:36 -0000
@@ -441,6 +441,14 @@ m4_is_symbol_value_func (m4_symbol_value
   return (value->type == M4_SYMBOL_FUNC);
 }
 
+#undef m4_is_symbol_value_void
+boolean
+m4_is_symbol_value_void (m4_symbol_value *value)
+{
+  assert (value);
+  return (value->type == M4_SYMBOL_VOID);
+}
+
 #undef m4_get_symbol_value_text
 char *
 m4_get_symbol_value_text (m4_symbol_value *value)
Index: m4/utility.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/utility.c,v
retrieving revision 1.32
diff -u -p -u -r1.32 utility.c
--- m4/utility.c 24 Jul 2003 11:37:44 -0000 1.32
+++ m4/utility.c 24 Jul 2003 14:20:36 -0000
@@ -145,67 +145,3 @@ m4_expand_ranges (const char *s, m4_obst
   obstack_1grow (obs, '\0');
   return obstack_finish (obs);
 }
-
-/* qsort comparison routine, for sorting the table made in m4_dumpdef ().  */
-static int
-dumpdef_cmp (const void *s1, const void *s2)
-{
-  return strcmp (*(const char **) s1, *(const char **) s2);
-}
-
-/* The function dump_symbol () is for use by "dumpdef".  It builds up a
-   table of all defined symbol names.  */
-void *
-m4_dump_symbol_CB (m4_symbol_table *ignored, const char *name, m4_symbol 
*symbol,
-                  void *userdata)
-{
-  assert (name);
-  assert (symbol);
-  assert (symbol->value);
-
-  if (symbol->value->type != M4_SYMBOL_VOID)
-    {
-      struct m4_dump_symbol_data *symbol_data
-       = (struct m4_dump_symbol_data *) userdata;
-
-      obstack_blank (symbol_data->obs, sizeof (const char *));
-      symbol_data->base = (const char **) obstack_base (symbol_data->obs);
-      symbol_data->base[symbol_data->size++] = (const char *) name;
-    }
-
-  return NULL;
-}
-
-/* If there are no arguments, build a sorted list of all defined
-   symbols, otherwise, only the specified symbols.  */
-void
-m4_dump_symbols (m4 *context, struct m4_dump_symbol_data *data, int argc,
-                m4_symbol_value **argv, boolean complain)
-{
-  data->base = (const char **) obstack_base (data->obs);
-  data->size = 0;
-
-  if (argc == 1)
-    {
-      m4_symtab_apply (M4SYMTAB, m4_dump_symbol_CB, data);
-    }
-  else
-    {
-      int i;
-      m4_symbol *symbol;
-
-      for (i = 1; i < argc; i++)
-       {
-         symbol = m4_symbol_lookup (M4SYMTAB, M4ARG (i));
-         if (symbol != NULL && symbol->value->type != M4_SYMBOL_VOID)
-           m4_dump_symbol_CB (NULL, M4ARG (i), symbol, data);
-         else if (complain)
-           M4WARN ((m4_get_warning_status_opt (context), 0,
-                    _("Warning: %s: undefined name: %s"),
-                    M4ARG (0), M4ARG (i)));
-       }
-    }
-
-  obstack_finish (data->obs);
-  qsort ((void *) data->base, data->size, sizeof (const char *), dumpdef_cmp);
-}
Index: modules/Makefile.am
===================================================================
RCS file: /cvsroot/m4/m4/modules/Makefile.am,v
retrieving revision 1.19
diff -u -p -u -r1.19 Makefile.am
--- modules/Makefile.am 24 Jul 2003 11:37:44 -0000 1.19
+++ modules/Makefile.am 24 Jul 2003 14:20:36 -0000
@@ -22,6 +22,7 @@ DISTCLEANFILES = perlxsi.c
 MAINTAINERCLEANFILES = Makefile.in
 
 testsubdir = testSubDir
+pkgmodincdir = $(includedir)/@PACKAGE@/modules
 
 ETAGS_ARGS = --regex='/M4BUILTIN_HANDLER[ \t]*(\([^)]*\)/\1/'
 
@@ -32,6 +33,7 @@ INCLUDES      = -I$(top_builddir) -I$(top_src
 LIBS = $(top_builddir)/m4/libm4.la
 AM_LDFLAGS = -no-undefined
 
+pkgmodinc_HEADERS = m4.h
 pkglibexec_LTLIBRARIES = gnu.la load.la m4.la \
                          traditional.la perl.la \
                          modtest.la shadow.la stdlib.la time.la
Index: modules/gnu.c
===================================================================
RCS file: /cvsroot/m4/m4/modules/gnu.c,v
retrieving revision 1.28
diff -u -p -u -r1.28 gnu.c
--- modules/gnu.c 24 Jul 2003 12:16:46 -0000 1.28
+++ modules/gnu.c 24 Jul 2003 14:20:36 -0000
@@ -28,6 +28,7 @@
 #endif
 
 #include <m4module.h>
+#include <modules/m4.h>
 
 #if HAVE_ERRNO_H
 #  include <errno.h>
@@ -367,9 +368,6 @@ M4BUILTIN_HANDLER (eregexp)
    third argument, with \& substituted by the matched text, and \N
    substituted by the text matched by the Nth parenthesized sub-expression.  */
 
-/**
- * patsubst(STRING, REGEXP, [REPLACEMENT])
- **/
 static void
 m4_patsubst_do (m4 *context, m4_obstack *obs, int argc,
                m4_symbol_value **argv, int syntax)
@@ -444,22 +442,26 @@ M4BUILTIN_HANDLER (patsubst)
 }
 
 /**
- * patsubst(STRING, REGEXP, [REPLACEMENT])
+ * epatsubst(STRING, REGEXP, [REPLACEMENT])
  **/
 M4BUILTIN_HANDLER (epatsubst)
 {
   m4_patsubst_do (context, obs, argc, argv, RE_SYNTAX_ERE);
 }
 
-/* Implementation of "symbols" itself.  It builds up a table of pointers to
-   symbols, sorts it and ships out the symbols name.  */
+/* Implementation of "symbols".  It builds up a table of pointers to
+   symbols, sorts it and ships out the symbol names.  */
+
+/* TODO:  Import this through the m4_export list of m4 module.  */
+extern void m4_dump_symbols (m4 *context, m4_dump_symbol_data *data, int argc,
+                            m4_symbol_value **argv, boolean complain);
 
 /**
  * symbols([...])
  **/
 M4BUILTIN_HANDLER (symbols)
 {
-  struct m4_dump_symbol_data data;
+  m4_dump_symbol_data data;
   m4_obstack data_obs;
 
   obstack_init (&data_obs);
Index: modules/m4.c
===================================================================
RCS file: /cvsroot/m4/m4/modules/m4.c,v
retrieving revision 1.50
diff -u -p -u -r1.50 m4.c
--- modules/m4.c 24 Jul 2003 12:16:46 -0000 1.50
+++ modules/m4.c 24 Jul 2003 14:20:36 -0000
@@ -35,6 +35,7 @@ extern int errno;
 #include <assert.h>
 
 #include <m4module.h>
+#include <modules/m4.h>
 
 #ifdef NDEBUG
 /* Include this header for speed, which gives us direct access to
@@ -49,12 +50,16 @@ extern int errno;
 #define m4_builtin_table       m4_LTX_m4_builtin_table
 
 /* Exit code from last "syscmd" command.  */
-int m4_sysval = 0;
+int  m4_sysval = 0;
+
 void m4_sysval_flush (m4 *context);
+void m4_dump_symbols (m4 *context, m4_dump_symbol_data *data, int argc,
+                     m4_symbol_value **argv, boolean complain);
 
 m4_export m4_export_table[] = {
   { "m4_sysval",               &m4_sysval },
   { "m4_sysval_flush",         &m4_sysval_flush },
+  { "m4_dump_symbols",         &m4_dump_symbols },
 
   { NULL,                      NULL }
 };
@@ -107,11 +112,13 @@ typedef long int number;
 typedef unsigned long int unumber;
 #endif
 
-
 static void    include         (m4 *context, int argc, m4_symbol_value **argv,
                                 boolean silent);
+static int     dumpdef_cmp_CB  (const void *s1, const void *s2);
 static void *  set_trace_CB    (m4_symbol_table *symtab, const char *ignored,
                                 m4_symbol *symbol, void *userdata);
+static void *  dump_symbol_CB  (m4_symbol_table *ignored, const char*name,
+                                m4_symbol *symbol, void *userdata);
 static const char *ntoa                (number value, int radix);
 static void    numb_obstack    (m4_obstack *obs, const number value,
                                 const int radix, int min);
@@ -281,11 +288,77 @@ M4BUILTIN_HANDLER (ifelse)
 }
 
 
+/* qsort comparison routine, for sorting the table made in m4_dumpdef ().  */
+static int
+dumpdef_cmp_CB (const void *s1, const void *s2)
+{
+  return strcmp (*(const char **) s1, *(const char **) s2);
+}
+
+/* The function m4_dump_symbols () is for use by "dumpdef".  It builds up a
+   table of all defined symbol names.  */
+static void *
+dump_symbol_CB (m4_symbol_table *ignored, const char *name, m4_symbol *symbol,
+               void *userdata)
+{
+  assert (name);
+  assert (symbol);
+
+  if (!m4_is_symbol_value_void (m4_get_symbol_value (symbol)))
+    {
+      m4_dump_symbol_data *symbol_data = (m4_dump_symbol_data *) userdata;
+
+      obstack_blank (symbol_data->obs, sizeof (const char *));
+      symbol_data->base = (const char **) obstack_base (symbol_data->obs);
+      symbol_data->base[symbol_data->size++] = (const char *) name;
+    }
+
+  return NULL;
+}
+
+/* If there are no arguments, build a sorted list of all defined
+   symbols, otherwise, only the specified symbols.  */
+void
+m4_dump_symbols (m4 *context, m4_dump_symbol_data *data, int argc,
+                m4_symbol_value **argv, boolean complain)
+{
+  data->base = (const char **) obstack_base (data->obs);
+  data->size = 0;
+
+  if (argc == 1)
+    {
+      m4_symtab_apply (M4SYMTAB, dump_symbol_CB, data);
+    }
+  else
+    {
+      int i;
+      m4_symbol *symbol;
+
+      for (i = 1; i < argc; i++)
+       {
+         symbol = m4_symbol_lookup (M4SYMTAB, M4ARG (i));
+         if (symbol != NULL
+             && !m4_is_symbol_value_void (m4_get_symbol_value (symbol)))
+           {
+             dump_symbol_CB (NULL, M4ARG (i), symbol, data);
+           }
+         else if (complain)
+           M4WARN ((m4_get_warning_status_opt (context), 0,
+                    _("Warning: %s: undefined name: %s"),
+                    M4ARG (0), M4ARG (i)));
+       }
+    }
+
+  obstack_finish (data->obs);
+  qsort ((void*) data->base, data->size, sizeof (const char*), dumpdef_cmp_CB);
+}
+
+
 /* Implementation of "dumpdef" itself.  It builds up a table of pointers to
    symbols, sorts it and prints the sorted table.  */
 M4BUILTIN_HANDLER (dumpdef)
 {
-  struct m4_dump_symbol_data data;
+  m4_dump_symbol_data data;
   const m4_builtin *bp;
 
   data.obs = obs;
@@ -316,7 +389,7 @@ M4BUILTIN_HANDLER (dumpdef)
        }
       else
        {
-         assert (!"illegal token in m4_dumpdef");
+         assert (!"illegal token in builtin_dumpdef");
        }
     }
 }
Index: modules/m4.h
===================================================================
RCS file: modules/m4.h
diff -N modules/m4.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ modules/m4.h 24 Jul 2003 14:20:36 -0000
@@ -0,0 +1,38 @@
+/* GNU m4 -- A simple macro processor
+   Copyright 2003 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
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307  USA
+*/
+
+#ifndef MODULES_M4_H
+#define MODULES_M4_H 1
+
+#include <m4module.h>
+
+BEGIN_C_DECLS
+
+/* This structure is used to pass the information needed
+   from call to call in m4_dump_symbols.  */
+typedef struct
+{
+  m4_obstack *obs;             /* obstack for table */
+  const char **base;           /* base of table */
+  int size;                    /* size of table */
+} m4_dump_symbol_data;
+
+END_C_DECLS
+
+#endif /* !MODULES_M4_H */

reply via email to

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