From: Bruno Haible Date: Thu, 1 Aug 2024 15:40:17 +0000 (+0200) Subject: libgettextpo: Remove static variables 'buf', 'bufmax'. X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=9229a07a01a5ea44f42e8f612f2248b5fb979ecc;p=thirdparty%2Fgettext.git libgettextpo: Remove static variables 'buf', 'bufmax'. * 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. --- diff --git a/gettext-tools/src/po-gram.h b/gettext-tools/src/po-gram.h index 02469e13e..d265aade1 100644 --- a/gettext-tools/src/po-gram.h +++ b/gettext-tools/src/po-gram.h @@ -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; diff --git a/gettext-tools/src/po-lex.c b/gettext-tools/src/po-lex.c index fb3019dd3..6dbd939ce 100644 --- a/gettext-tools/src/po-lex.c +++ b/gettext-tools/src/po-lex.c @@ -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);