[latex3-commits] [git/LaTeX3-latex3-latex3] master: Avoid clobbering global intarray when matching cs-regex nested in bigger regex (e4a98d8)
Bruno Le Floch
bruno at le-floch.fr
Thu Oct 11 15:33:26 CEST 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/e4a98d84f055dae6a5836388048ba8f30fc1da3d
>---------------------------------------------------------------
commit e4a98d84f055dae6a5836388048ba8f30fc1da3d
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Thu Oct 11 15:23:32 2018 +0200
Avoid clobbering global intarray when matching cs-regex nested in bigger regex
>---------------------------------------------------------------
e4a98d84f055dae6a5836388048ba8f30fc1da3d
l3kernel/l3regex.dtx | 59 +++++++++++++++++++++++++++----
l3kernel/testfiles/m3expl001.luatex.tlg | 1 +
l3kernel/testfiles/m3expl001.ptex.tlg | 1 +
l3kernel/testfiles/m3expl001.tlg | 1 +
l3kernel/testfiles/m3expl001.uptex.tlg | 1 +
l3kernel/testfiles/m3expl001.xetex.tlg | 1 +
l3kernel/testfiles/m3expl003.luatex.tlg | 1 +
l3kernel/testfiles/m3expl003.ptex.tlg | 1 +
l3kernel/testfiles/m3expl003.tlg | 1 +
l3kernel/testfiles/m3expl003.uptex.tlg | 1 +
l3kernel/testfiles/m3expl003.xetex.tlg | 1 +
11 files changed, 63 insertions(+), 6 deletions(-)
diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index 4b45d45..37e2461 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -1317,7 +1317,7 @@
\@@_build_for_cs:n {#1}
\bool_set_eq:NN \l_@@_saved_success_bool
\g_@@_success_bool
- \exp_args:NV \@@_match:n \l_@@_cs_name_tl
+ \exp_args:NV \@@_match_cs:n \l_@@_cs_name_tl
\if_meaning:w \c_true_bool \g_@@_success_bool
\group_insert_after:N \@@_break_true:w
\fi:
@@ -3683,10 +3683,11 @@
% \subsubsection{Variables used while building}
%
% \begin{variable}{\l_@@_min_state_int, \l_@@_max_state_int}
-% The last state that was allocated is $\cs{l_@@_max_state_int}-1$,
-% so that \cs{l_@@_max_state_int} always points to a free state.
-% The \texttt{min_state} variable is $1$, but is included to
-% avoid hard-coding this value everywhere.
+% The last state that was allocated is
+% $\cs{l_@@_max_state_int}-1$, so that \cs{l_@@_max_state_int} always
+% points to a free state. The \texttt{min_state} variable is
+% $1$ to begin with, but gets shifted in nested calls to the matching
+% code, namely in |\c{...}| constructions.
% \begin{macrocode}
\int_new:N \l_@@_min_state_int
\int_set:Nn \l_@@_min_state_int { 1 }
@@ -3799,6 +3800,23 @@
% \end{macro}
%
% \begin{macro}{\@@_build_for_cs:n}
+% The matching code relies on some global intarray variables, but only
+% uses a range of their entries. Specifically,
+% \begin{itemize}
+% \item \cs{g_@@_state_active_intarray} from \cs{l_@@_min_state_int}
+% to $\cs{l_@@_max_state_int}-1$;
+% \item \cs{g_@@_thread_state_intarray} from \cs{l_@@_min_active_int}
+% to $\cs{l_@@_max_active_int}-1$.
+% \end{itemize}
+% In fact, some data is stored in \tn{toks} registers (local) in the
+% same ranges so these ranges mustn't overlap. This is done by
+% setting \cs{l_@@_min_active_int} to \cs{l_@@_max_state_int} after
+% building the \textsc{nfa}. Here, in this nested call to the
+% matching code, we need the new versions of these ranges to involve
+% completely new entries of the intarray variables, so we begin by
+% setting (the new) \cs{l_@@_min_state_int} to (the old)
+% \cs{l_@@_max_active_int} to use higher entries.
+%
% When using a regex to match a cs, we don't insert a wildcard, we
% anchor at the end, and since we ignore submatches, there is no need
% to surround the expression with a group. However, for branches to
@@ -3813,6 +3831,7 @@
}
\cs_new_protected:Npn \@@_build_for_cs:n #1
{
+ \int_set_eq:NN \l_@@_min_state_int \l_@@_max_active_int
\int_set_eq:NN \l_@@_max_state_int \l_@@_min_state_int
\@@_build_new_state:
\@@_build_new_state:
@@ -4615,7 +4634,7 @@
%
% \subsubsection{Matching: framework}
%
-% \begin{macro}{\@@_match:n}
+% \begin{macro}{\@@_match:n, \@@_match_cs:n}
% \begin{macro}{\@@_match_init:}
% First store the query into \tn{toks} registers and arrays (see
% \cs{@@_query_set:nnn}). Then initialize the variables that should
@@ -4647,6 +4666,34 @@
\@@_match_once:
}
\__kernel_patch:nnNNpn
+ {
+ \@@_trace_push:nnN { regex } { 1 } \@@_match_cs:n
+ \@@_trace:nnx { regex } { 1 } { analyzing~query~token~list }
+ }
+ { \@@_trace_pop:nnN { regex } { 1 } \@@_match_cs:n }
+\cs_new_protected:Npn \@@_match_cs:n #1
+ {
+ \int_zero:N \l_@@_balance_int
+ \int_set:Nn \l_@@_curr_pos_int
+ {
+ \int_max:nn { 2 * \l_@@_max_state_int - \l_@@_min_state_int }
+ { \l_@@_max_pos_int }
+ + 1
+ }
+ \@@_query_set:nnn { } { -1 } { -2 }
+ \int_set_eq:NN \l_@@_min_pos_int \l_@@_curr_pos_int
+ \str_map_inline:nn {#1}
+ {
+ \@@_query_set:nnn { \exp_not:n {##1} }
+ { \tl_if_blank:nTF {##1} { 10 } { 12 } }
+ { `##1 }
+ }
+ \int_set_eq:NN \l_@@_max_pos_int \l_@@_curr_pos_int
+ \@@_query_set:nnn { } { -1 } { -2 }
+ \@@_match_init:
+ \@@_match_once:
+ }
+\__kernel_patch:nnNNpn
{ \@@_trace:nnx { regex } { 1 } { initializing } }
{ }
\cs_new_protected:Npn \@@_match_init:
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 559f641..2d0e40b 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -4804,6 +4804,7 @@ Defining \g__regex_success_bool on line ...
Defining \l__regex_saved_success_bool on line ...
Defining \l__regex_match_success_bool on line ...
Defining \__regex_match:n on line ...
+Defining \__regex_match_cs:n on line ...
Defining \__regex_match_init: on line ...
Defining \__regex_match_once: on line ...
Defining \__regex_single_match: on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index a7691b1..58f1137 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -5100,6 +5100,7 @@ Defining \g__regex_success_bool on line ...
Defining \l__regex_saved_success_bool on line ...
Defining \l__regex_match_success_bool on line ...
Defining \__regex_match:n on line ...
+Defining \__regex_match_cs:n on line ...
Defining \__regex_match_init: on line ...
Defining \__regex_match_once: on line ...
Defining \__regex_single_match: on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 707e410..7a3d5b8 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -5100,6 +5100,7 @@ Defining \g__regex_success_bool on line ...
Defining \l__regex_saved_success_bool on line ...
Defining \l__regex_match_success_bool on line ...
Defining \__regex_match:n on line ...
+Defining \__regex_match_cs:n on line ...
Defining \__regex_match_init: on line ...
Defining \__regex_match_once: on line ...
Defining \__regex_single_match: on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 38fe4b8..96c3343 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -5097,6 +5097,7 @@ Defining \g__regex_success_bool on line ...
Defining \l__regex_saved_success_bool on line ...
Defining \l__regex_match_success_bool on line ...
Defining \__regex_match:n on line ...
+Defining \__regex_match_cs:n on line ...
Defining \__regex_match_init: on line ...
Defining \__regex_match_once: on line ...
Defining \__regex_single_match: on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 7033e37..d0aa95d 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -4815,6 +4815,7 @@ Defining \g__regex_success_bool on line ...
Defining \l__regex_saved_success_bool on line ...
Defining \l__regex_match_success_bool on line ...
Defining \__regex_match:n on line ...
+Defining \__regex_match_cs:n on line ...
Defining \__regex_match_init: on line ...
Defining \__regex_match_once: on line ...
Defining \__regex_single_match: on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 559f641..2d0e40b 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -4804,6 +4804,7 @@ Defining \g__regex_success_bool on line ...
Defining \l__regex_saved_success_bool on line ...
Defining \l__regex_match_success_bool on line ...
Defining \__regex_match:n on line ...
+Defining \__regex_match_cs:n on line ...
Defining \__regex_match_init: on line ...
Defining \__regex_match_once: on line ...
Defining \__regex_single_match: on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index a7691b1..58f1137 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -5100,6 +5100,7 @@ Defining \g__regex_success_bool on line ...
Defining \l__regex_saved_success_bool on line ...
Defining \l__regex_match_success_bool on line ...
Defining \__regex_match:n on line ...
+Defining \__regex_match_cs:n on line ...
Defining \__regex_match_init: on line ...
Defining \__regex_match_once: on line ...
Defining \__regex_single_match: on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 707e410..7a3d5b8 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -5100,6 +5100,7 @@ Defining \g__regex_success_bool on line ...
Defining \l__regex_saved_success_bool on line ...
Defining \l__regex_match_success_bool on line ...
Defining \__regex_match:n on line ...
+Defining \__regex_match_cs:n on line ...
Defining \__regex_match_init: on line ...
Defining \__regex_match_once: on line ...
Defining \__regex_single_match: on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 38fe4b8..96c3343 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -5097,6 +5097,7 @@ Defining \g__regex_success_bool on line ...
Defining \l__regex_saved_success_bool on line ...
Defining \l__regex_match_success_bool on line ...
Defining \__regex_match:n on line ...
+Defining \__regex_match_cs:n on line ...
Defining \__regex_match_init: on line ...
Defining \__regex_match_once: on line ...
Defining \__regex_single_match: on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 7033e37..d0aa95d 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -4815,6 +4815,7 @@ Defining \g__regex_success_bool on line ...
Defining \l__regex_saved_success_bool on line ...
Defining \l__regex_match_success_bool on line ...
Defining \__regex_match:n on line ...
+Defining \__regex_match_cs:n on line ...
Defining \__regex_match_init: on line ...
Defining \__regex_match_once: on line ...
Defining \__regex_single_match: on line ...
More information about the latex3-commits
mailing list