]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libgettextpo: Remove static variables 'buf', 'bufmax'.
authorBruno Haible <bruno@clisp.org>
Thu, 1 Aug 2024 15:40:17 +0000 (17:40 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 1 Aug 2024 20:31:22 +0000 (22:31 +0200)
* gettext-tools/src/po-gram.h (struct po_parser_state): Add fields buf, bufmax.
* gettext-tools/src/po-lex.c (lex_start): Initialize them.
(lex_end): Free the buf field.
(po_gram_lex): Use these fields instead of static variables.

gettext-tools/src/po-gram.h
gettext-tools/src/po-lex.c

index 02469e13e74832fabd6b01e32434730aeafc4e24..d265aade1e075a78b740b339ac8633da6d225134 100644 (file)
@@ -108,6 +108,10 @@ struct po_parser_state
      or silently tolerated.  */
   bool signal_eilseq;
 
+  /* A buffer for po_gram_lex().  */
+  char *buf;
+  size_t bufmax;
+
   mbfile_t mbf;
   bool po_lex_obsolete;
   bool po_lex_previous;
index fb3019dd3372160cdffd395dbbbc8a0a542db2d9..6dbd939ce07e3064ef98127a63de992856ac33b3 100644 (file)
@@ -839,6 +839,8 @@ lex_start (struct po_parser_state *ps,
   ps->po_lex_obsolete = false;
   ps->po_lex_previous = false;
   po_lex_charset_init (ps);
+  ps->buf = NULL;
+  ps->bufmax = 0;
 }
 
 /* Terminate lexical analysis.  */
@@ -848,6 +850,7 @@ lex_end (struct po_parser_state *ps)
   gram_pos.file_name = NULL;
   gram_pos.line_number = 0;
   po_lex_charset_close (ps);
+  free (ps->buf);
 }
 
 
@@ -1075,8 +1078,10 @@ control_sequence (struct po_parser_state *ps)
 int
 po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps)
 {
-  static char *buf;
-  static size_t bufmax;
+  /* Cache ps->buf and ps->bufmax in local variables.  */
+  char *buf = ps->buf;
+  size_t bufmax = ps->bufmax;
+
   mbchar_t mbc;
   size_t bufpos;
 
@@ -1148,6 +1153,8 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps)
                       {
                         bufmax += 100;
                         buf = xrealloc (buf, bufmax);
+                        ps->bufmax = bufmax;
+                        ps->buf = buf;
                       }
                     if (mb_iseof (mbc) || mb_iseq (mbc, '\n'))
                       break;
@@ -1188,6 +1195,8 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps)
                   {
                     bufmax += 100;
                     buf = xrealloc (buf, bufmax);
+                    ps->bufmax = bufmax;
+                    ps->buf = buf;
                   }
                 if (mb_iseof (mbc))
                   {
@@ -1246,6 +1255,8 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps)
                   {
                     bufmax += 100;
                     buf = xrealloc (buf, bufmax);
+                    ps->bufmax = bufmax;
+                    ps->buf = buf;
                   }
                 buf[bufpos++] = c;
                 lex_getc (ps, mbc);
@@ -1303,6 +1314,8 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps)
                   {
                     bufmax += 100;
                     buf = xrealloc (buf, bufmax + 1);
+                    ps->bufmax = bufmax;
+                    ps->buf = buf;
                   }
                 buf[bufpos++] = c;
                 lex_getc (ps, mbc);