m4-patches
[Top][All Lists]
Advanced

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

Re: branch-1_4 allow C++ on Linux


From: Eric Blake
Subject: Re: branch-1_4 allow C++ on Linux
Date: Sat, 11 Nov 2006 09:21:00 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Thunderbird/1.5.0.8 Mnenhy/0.7.4.666

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

According to Eric Blake on 11/2/2006 6:17 AM:
>> Cool.  I should try to swallow my loathing of C++ from time to time if
>> I am ever to dare patches like this ;-)
> 
>> Have you tried HEAD too?  
> 
> Not yet - head has changed enough from branch that I am not sure how a C++
> build will fare; plus the fact that it pulls in libtool and more of
> gnulib, so it has more potential points of failure.  It's not my highest
> priority, but it is on the list of cool things to try before 2.0.

Well, this isn't a complete patch, but it gets closer.

2006-11-11  Eric Blake  <address@hidden>

        One step closer to allowing C++ compilation - don't blindly
        convert between char* and unsigned char*.
        * m4/m4module.h (m4_set_syntax): Change signature.
        * m4/m4private.h (m4_string): Use signed char.
        (m4_get_syntax_lquote, m4_get_syntax_rquote, m4_get_syntax_bcomm)
        (m4_get_syntax_ecomm): No longer a need to cast.
        * m4/syntax.c (m4_set_syntax, m4_syntax_create, m4_set_quotes):
        Reflect this change.
        * m4/macro.c (expand_argument): Simplify.
        (expand_token): Use proper type.
        * src/freeze.c (reload_frozen_state): Likewise.
        * m4/input.c (MATCH, match_input): Likewise.
        * modules/m4.c (translit): Likewise.
        * modules/gnu.c (substitute): Simplify.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFVfhr84KuGfSFAYARAm+vAKDBDwamfGothftvSQ/jJa9X/055qgCeOW0T
S2BD/6WTTTBPdcXC/ty7am8=
=+HnH
-----END PGP SIGNATURE-----
Index: m4/input.c
===================================================================
RCS file: /sources/m4/m4/m4/input.c,v
retrieving revision 1.57
diff -u -p -r1.57 input.c
--- m4/input.c  11 Nov 2006 14:00:28 -0000      1.57
+++ m4/input.c  11 Nov 2006 16:11:42 -0000
@@ -106,7 +106,7 @@ static      void    composite_unget         (m4_input_b
 static void    composite_print         (m4_input_block *, m4 *, m4_obstack *);
 
 static void    init_builtin_token      (m4 *, m4_symbol_value *);
-static bool    match_input             (m4 *, const unsigned char *, bool);
+static bool    match_input             (m4 *, const char *, bool);
 static int     next_char               (m4 *, bool);
 static int     peek_char               (m4 *);
 static void    pop_input               (m4 *);
@@ -863,16 +863,16 @@ m4_skip_line (m4 *context, const char *n
    not properly restore the current input file and line when we
    restore unconsumed characters.  */
 static bool
-match_input (m4 *context, const unsigned char *s, bool consume)
+match_input (m4 *context, const char *s, bool consume)
 {
   int n;                       /* number of characters matched */
   int ch;                      /* input character */
-  const unsigned char *t;
+  const char *t;
   m4_obstack *st;
   bool result = false;
 
   ch = peek_char (context);
-  if (ch != *s)
+  if (ch != to_uchar (*s))
     return false;                      /* fail */
 
   if (s[1] == '\0')
@@ -883,7 +883,7 @@ match_input (m4 *context, const unsigned
     }
 
   next_char (context, true);
-  for (n = 1, t = s++; (ch = peek_char (context)) == *s++; )
+  for (n = 1, t = s++; (ch = peek_char (context)) == to_uchar (*s++); )
     {
       next_char (context, true);
       n++;
@@ -911,7 +911,7 @@ match_input (m4 *context, const unsigned
   will discard the matched string.  Otherwise, CH is the result of
   peek_char, and the input stream is effectively unchanged.  */
 #define MATCH(C, ch, s, consume)                                       \
-  ((s)[0] == (ch)                                                      \
+  (to_uchar ((s)[0]) == (ch)                                           \
    && (ch) != '\0'                                                     \
    && ((s)[1] == '\0' || (match_input (C, (s) + (consume), consume))))
 
Index: m4/m4module.h
===================================================================
RCS file: /sources/m4/m4/m4/m4module.h,v
retrieving revision 1.99
diff -u -p -r1.99 m4module.h
--- m4/m4module.h       27 Oct 2006 17:03:51 -0000      1.99
+++ m4/m4module.h       11 Nov 2006 16:11:44 -0000
@@ -391,7 +391,7 @@ enum {
 
 extern void    m4_set_quotes   (m4_syntax_table*, const char*, const char*);
 extern void    m4_set_comment  (m4_syntax_table*, const char*, const char*);
-extern int     m4_set_syntax   (m4_syntax_table*, char, const unsigned char*);
+extern int     m4_set_syntax   (m4_syntax_table*, const char, const char*);
 
 
 
Index: m4/m4private.h
===================================================================
RCS file: /sources/m4/m4/m4/m4private.h,v
retrieving revision 1.71
diff -u -p -r1.71 m4private.h
--- m4/m4private.h      11 Nov 2006 14:00:28 -0000      1.71
+++ m4/m4private.h      11 Nov 2006 16:11:44 -0000
@@ -279,16 +279,18 @@ extern void m4__symtab_remove_module_ref
 #define DEF_ECOMM "\n"
 
 typedef struct {
-    unsigned char *string;     /* characters of the string */
-    size_t length;             /* length of the string */
+  char *string;                /* characters of the string */
+  size_t length;       /* length of the string */
 } m4_string;
 
 struct m4_syntax_table {
   /* Please read the comment at the top of input.c for details */
   unsigned short table[CHAR_RETRY];
 
-  m4_string lquote, rquote;
-  m4_string bcomm, ecomm;
+  m4_string lquote;
+  m4_string rquote;
+  m4_string bcomm;
+  m4_string ecomm;
 
   /* true iff strlen(rquote) == strlen(lquote) == 1 */
   bool is_single_quotes;
@@ -303,10 +305,10 @@ struct m4_syntax_table {
 /* Fast macro versions of syntax table accessor functions,
    that also have an identically named function exported in m4module.h.  */
 #ifdef NDEBUG
-#  define m4_get_syntax_lquote(S)      ((const char *) (S)->lquote.string)
-#  define m4_get_syntax_rquote(S)      ((const char *) (S)->rquote.string)
-#  define m4_get_syntax_bcomm(S)       ((const char *) (S)->bcomm.string)
-#  define m4_get_syntax_ecomm(S)       ((const char *) (S)->ecomm.string)
+#  define m4_get_syntax_lquote(S)              ((S)->lquote.string)
+#  define m4_get_syntax_rquote(S)              ((S)->rquote.string)
+#  define m4_get_syntax_bcomm(S)               ((S)->bcomm.string)
+#  define m4_get_syntax_ecomm(S)               ((S)->ecomm.string)
 
 #  define m4_is_syntax_single_quotes(S)                ((S)->is_single_quotes)
 #  define m4_is_syntax_single_comments(S)      ((S)->is_single_comments)
Index: m4/macro.c
===================================================================
RCS file: /sources/m4/m4/m4/macro.c,v
retrieving revision 1.63
diff -u -p -r1.63 macro.c
--- m4/macro.c  11 Nov 2006 14:00:28 -0000      1.63
+++ m4/macro.c  11 Nov 2006 16:11:44 -0000
@@ -115,9 +115,9 @@ expand_token (m4 *context, m4_obstack *o
 
     case M4_TOKEN_WORD:
       {
-       const unsigned char *textp = text;
+       const char *textp = text;
 
-       if (m4_has_syntax (M4SYNTAX, *textp, M4_SYNTAX_ESCAPE))
+       if (m4_has_syntax (M4SYNTAX, to_uchar (*textp), M4_SYNTAX_ESCAPE))
          ++textp;
 
        symbol = m4_symbol_lookup (M4SYMTAB, textp);
@@ -153,7 +153,7 @@ expand_argument (m4 *context, m4_obstack
 {
   m4__token_type type;
   m4_symbol_value token;
-  const unsigned char *text;
+  const char *text;
   int paren_level = 0;
   const char *file = m4_get_current_file (context);
   int line = m4_get_current_line (context);
@@ -190,10 +190,9 @@ expand_argument (m4 *context, m4_obstack
          /* fallthru */
        case M4_TOKEN_OPEN:
        case M4_TOKEN_SIMPLE:
-         text = m4_get_symbol_value_text (&token);
-         if (m4_has_syntax (M4SYNTAX, *text, M4_SYNTAX_OPEN))
+         if (type == M4_TOKEN_OPEN)
            paren_level++;
-         else if (m4_has_syntax (M4SYNTAX, *text, M4_SYNTAX_CLOSE))
+         else if (type == M4_TOKEN_CLOSE)
            paren_level--;
          expand_token (context, obs, type, &token);
          break;
Index: m4/syntax.c
===================================================================
RCS file: /sources/m4/m4/m4/syntax.c,v
retrieving revision 1.17
diff -u -p -r1.17 syntax.c
--- m4/syntax.c 12 Oct 2006 21:14:50 -0000      1.17
+++ m4/syntax.c 11 Nov 2006 16:11:44 -0000
@@ -140,10 +140,14 @@ m4_syntax_create (void)
   syntax->is_single_comments   = true;
   syntax->is_macro_escaped     = false;
 
-  add_syntax_attribute (syntax, syntax->lquote.string[0], M4_SYNTAX_LQUOTE);
-  add_syntax_attribute (syntax, syntax->rquote.string[0], M4_SYNTAX_RQUOTE);
-  add_syntax_attribute (syntax, syntax->bcomm.string[0], M4_SYNTAX_BCOMM);
-  add_syntax_attribute (syntax, syntax->ecomm.string[0], M4_SYNTAX_ECOMM);
+  add_syntax_attribute (syntax, to_uchar (syntax->lquote.string[0]),
+                       M4_SYNTAX_LQUOTE);
+  add_syntax_attribute (syntax, to_uchar (syntax->rquote.string[0]),
+                       M4_SYNTAX_RQUOTE);
+  add_syntax_attribute (syntax, to_uchar (syntax->bcomm.string[0]),
+                       M4_SYNTAX_BCOMM);
+  add_syntax_attribute (syntax, to_uchar (syntax->ecomm.string[0]),
+                       M4_SYNTAX_ECOMM);
 
   return syntax;
 }
@@ -228,7 +232,7 @@ remove_syntax_attribute (m4_syntax_table
 }
 
 int
-m4_set_syntax (m4_syntax_table *syntax, char key, const unsigned char *chars)
+m4_set_syntax (m4_syntax_table *syntax, const char key, const char *chars)
 {
   int ch, code;
 
@@ -242,7 +246,7 @@ m4_set_syntax (m4_syntax_table *syntax, 
     }
 
   if (*chars != '\0')
-    while ((ch = *chars++))
+    while ((ch = to_uchar (*chars++)))
       add_syntax_attribute (syntax, ch, code);
   else
     for (ch = 256; --ch > 0; )
@@ -299,8 +303,10 @@ m4_set_quotes (m4_syntax_table *syntax, 
 
   if (syntax->is_single_quotes)
     {
-      add_syntax_attribute (syntax, syntax->lquote.string[0], 
M4_SYNTAX_LQUOTE);
-      add_syntax_attribute (syntax, syntax->rquote.string[0], 
M4_SYNTAX_RQUOTE);
+      add_syntax_attribute (syntax, to_uchar (syntax->lquote.string[0]),
+                           M4_SYNTAX_LQUOTE);
+      add_syntax_attribute (syntax, to_uchar (syntax->rquote.string[0]),
+                           M4_SYNTAX_RQUOTE);
     }
 
   if (syntax->is_macro_escaped)
@@ -331,8 +337,10 @@ m4_set_comment (m4_syntax_table *syntax,
 
   if (syntax->is_single_comments)
     {
-      add_syntax_attribute (syntax, syntax->bcomm.string[0], M4_SYNTAX_BCOMM);
-      add_syntax_attribute (syntax, syntax->ecomm.string[0], M4_SYNTAX_ECOMM);
+      add_syntax_attribute (syntax, to_uchar (syntax->bcomm.string[0]),
+                           M4_SYNTAX_BCOMM);
+      add_syntax_attribute (syntax, to_uchar (syntax->ecomm.string[0]),
+                           M4_SYNTAX_ECOMM);
     }
 
   if (syntax->is_macro_escaped)
Index: src/freeze.c
===================================================================
RCS file: /sources/m4/m4/src/freeze.c,v
retrieving revision 1.55
diff -u -p -r1.55 freeze.c
--- src/freeze.c        11 Nov 2006 14:00:28 -0000      1.55
+++ src/freeze.c        11 Nov 2006 16:11:44 -0000
@@ -332,7 +332,7 @@ decode_char (FILE *in)
          int next;
 
          /* first octal digit */
-         ch  = (ch - '0') * 64;
+         ch = (ch - '0') * 64;
 
          /* second octal digit */
          next = fgetc (in);
@@ -364,7 +364,7 @@ reload_frozen_state (m4 *context, const 
   int character;
   int operation;
   char syntax;
-  unsigned char *string[3];
+  char *string[3];
   int allocated[3];
   int number[3] = {0};
 
@@ -627,7 +627,7 @@ ill-formed frozen file, version 2 direct
                    m4_error (context, EXIT_FAILURE, 0,
                              _("premature end of frozen file"));
 
-                 string[0][i] = (unsigned char) ch;
+                 string[0][i] = ch;
                }
            }
          string[0][number[0]] = '\0';
Index: modules/gnu.c
===================================================================
RCS file: /sources/m4/m4/modules/gnu.c,v
retrieving revision 1.66
diff -u -p -r1.66 gnu.c
--- modules/gnu.c       27 Oct 2006 17:03:51 -0000      1.66
+++ modules/gnu.c       11 Nov 2006 16:11:44 -0000
@@ -171,7 +171,7 @@ static void
 substitute (m4 *context, m4_obstack *obs, const char *caller,
            const char *victim, const char *repl, m4_pattern_buffer *buf)
 {
-  unsigned int ch;
+  int ch;
 
   for (;;)
     {
Index: modules/m4.c
===================================================================
RCS file: /sources/m4/m4/modules/m4.c,v
retrieving revision 1.92
diff -u -p -r1.92 m4.c
--- modules/m4.c        11 Nov 2006 14:00:28 -0000      1.92
+++ modules/m4.c        11 Nov 2006 16:11:44 -0000
@@ -960,11 +960,12 @@ m4_expand_ranges (const char *s, m4_obst
    deleted from the first (pueh)  */
 M4BUILTIN_HANDLER (translit)
 {
-  const unsigned char *data;
-  const unsigned char *from;
-  const unsigned char *to;
+  const char *data;
+  const char *from;
+  const char *to;
   char map[256] = {0};
   char found[256] = {0};
+  unsigned char ch;
 
   from = M4ARG (2);
   if (strchr (from, '-') != NULL)
@@ -982,27 +983,27 @@ M4BUILTIN_HANDLER (translit)
 
   /* Calling strchr(from) for each character in data is quadratic,
      since both strings can be arbitrarily long.  Instead, create a
-     from-to mapping in one pass of data, then use that map in one
-     pass of from, for linear behavior.  Traditional behavior is that
+     from-to mapping in one pass of from, then use that map in one
+     pass of data, for linear behavior.  Traditional behavior is that
      only the first instance of a character in from is consulted,
      hence the found map.  */
-  for ( ; *from; from++)
+  for ( ; (ch = *from) != '\0'; from++)
     {
-      if (! found[*from])
+      if (! found[ch])
        {
-         found[*from] = 1;
-         map[*from] = *to;
+         found[ch] = 1;
+         map[ch] = *to;
        }
       if (*to != '\0')
        to++;
     }
 
-  for (data = M4ARG (1); *data; data++)
+  for (data = M4ARG (1); (ch = *data) != '\0'; data++)
     {
-      if (! found[*data])
-       obstack_1grow (obs, *data);
-      else if (map[*data])
-       obstack_1grow (obs, map[*data]);
+      if (! found[ch])
+       obstack_1grow (obs, ch);
+      else if (map[ch])
+       obstack_1grow (obs, map[ch]);
     }
 }
 

reply via email to

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