]> Savannah Git Hosting - gnulib.git/commitdiff
dfa: new function dfacopysyntax
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 17 Dec 2019 08:20:53 +0000 (00:20 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 17 Dec 2019 08:24:52 +0000 (00:24 -0800)
* lib/dfa.c (struct dfa): Move syntax member later so
that dfacopysyntax can easily clear earlier members.
(dfacopysyntax): New function, used by Gawk.

ChangeLog
lib/dfa.c
lib/dfa.h

index dca623c5f62150fe4e30a2afe92df2f8b4744b22..9806040bb18c59418f3d09319289bcf6646d241e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2019-12-17  Paul Eggert  <eggert@cs.ucla.edu>
+
+       dfa: new function dfacopysyntax
+       * lib/dfa.c (struct dfa): Move syntax member later so
+       that dfacopysyntax can easily clear earlier members.
+       (dfacopysyntax): New function, used by Gawk.
+
 2019-12-16  Paul Eggert  <eggert@cs.ucla.edu>
 
        dfa: port _GL_ATTRIBUTE_MALLOC to Gawk
index 8e59df0c79e48ee7ba6fda5eb4d4baab0cbc616f..00347f901471e86c7450990116454c03e0074784 100644 (file)
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -444,9 +444,6 @@ struct parser_state
 /* A compiled regular expression.  */
 struct dfa
 {
-  /* Syntax configuration */
-  struct regex_syntax syntax;
-
   /* Fields filled by the scanner.  */
   charclass *charclasses;       /* Array of character sets for CSET tokens.  */
   idx_t cindex;                        /* Index for adding new charclasses.  */
@@ -562,6 +559,10 @@ struct dfa
   state_num mb_trcount;         /* Number of transition tables for states with
                                    ANYCHAR that have actually been built.  */
 
+  /* Syntax configuration.  This is near the end so that dfacopysyntax
+     can memset up to here.  */
+  struct regex_syntax syntax;
+
   /* Information derived from the locale.  This is at the end so that
      a quick memset need not clear it specially.  */
 
@@ -4303,4 +4304,16 @@ dfasyntax (struct dfa *dfa, struct localeinfo const *linfo,
     }
 }
 
+/* Initialize TO by copying FROM's syntax settings.  */
+void
+dfacopysyntax (struct dfa *to, struct dfa const *from)
+{
+  memset (to, 0, offsetof (struct dfa, syntax));
+  to->canychar = -1;
+  to->fast = from->fast;
+  to->syntax = from->syntax;
+  to->dfaexec = from->dfaexec;
+  to->localeinfo = from->localeinfo;
+}
+
 /* vim:set shiftwidth=2: */
index 09e7991bda21723890af7b18d0337e23fee414b3..0da597fc9f462254d9872ec08a03bb2a6fdccd72 100644 (file)
--- a/lib/dfa.h
+++ b/lib/dfa.h
@@ -45,6 +45,7 @@ struct dfa;
 /* Entry points. */
 
 /* Allocate a struct dfa.  The struct dfa is completely opaque.
+   It should be initialized via dfasyntax or dfacopysyntax before other use.
    The returned pointer should be passed directly to free() after
    calling dfafree() on it. */
 extern struct dfa *dfaalloc (void) _GL_ATTRIBUTE_MALLOC;
@@ -61,8 +62,7 @@ enum
     DFA_EOL_NUL = 1 << 1
   };
 
-/* Initialize or reinitialize a DFA.  This must be called before
-   any of the routines below.  The arguments are:
+/* Initialize or reinitialize a DFA.  The arguments are:
    1. The DFA to operate on.
    2. Information about the current locale.
    3. Syntax bits described in regex.h.
@@ -70,6 +70,9 @@ enum
 extern void dfasyntax (struct dfa *, struct localeinfo const *,
                        reg_syntax_t, int);
 
+/* Initialize or reinitialize a DFA from an already-initialized DFA.  */
+extern void dfacopysyntax (struct dfa *, struct dfa const *);
+
 /* Parse the given string of given length into the given struct dfa.  */
 extern void dfaparse (char const *, ptrdiff_t, struct dfa *);