[latex3-commits] [git/LaTeX3-latex3-latex3] master: Compare version of preloaded l3kernel with expl3 (166cd278b)
PhelypeOleinik
tex.phelype at gmail.com
Wed Jul 29 02:53:19 CEST 2020
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/166cd278bd2158af1ae87d0d8a559974723cd5fb
>---------------------------------------------------------------
commit 166cd278bd2158af1ae87d0d8a559974723cd5fb
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date: Tue Jul 28 21:53:19 2020 -0300
Compare version of preloaded l3kernel with expl3
This is a mostly cosmetic change to print a pretty error message and
grecefully recover in case the user tries to load expl3.sty with a LaTeX
with an older version of l3kernel.
>---------------------------------------------------------------
166cd278bd2158af1ae87d0d8a559974723cd5fb
l3kernel/expl3.dtx | 100 +++++++++++++++++++++++++++++++++++++++
l3kernel/testfiles/m3expl009.lvt | 78 ++++++++++++++++++++++++++++++
l3kernel/testfiles/m3expl009.tlg | 31 ++++++++++++
3 files changed, 209 insertions(+)
diff --git a/l3kernel/expl3.dtx b/l3kernel/expl3.dtx
index 127ee2eff..1f6bd55bb 100644
--- a/l3kernel/expl3.dtx
+++ b/l3kernel/expl3.dtx
@@ -1053,6 +1053,24 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\c__kernel_expl_date_tl}
+% The \LaTeXe{} loader stores a private copy of \cs{ExplFileDate},
+% which is fixed when the format is build and cannot be changed later.
+% While \cs{ExplFileDate} ensures that the loader (either
+% \texttt{2ekernel} or \texttt{package}) version matches the version
+% of \file{expl3-code.tex}, this one ensures that the version of an
+% eventual |\usepackage{expl3}| matches the version from the format.
+% It seems to be common to have stray format files in the user tree
+% which trigger errors due to mismatched versions (\emph{e.g.}
+% \url{https://github.com/latex3/latex3/issues/781}).
+% \begin{macrocode}
+%<*2ekernel>
+\global\expandafter\let\csname\detokenize
+ {c__kernel_expl_date_tl}\endcsname\ExplFileDate
+%</2ekernel>
+% \end{macrocode}
+% \end{macro}
+%
% The interlock test itself is simple: \cs{ExplLoaderFileDate} must be
% defined and identical to \cs{ExplFileDate}. As this has to work for
% both \LaTeXe{} and other formats, there is some auto-detection involved.
@@ -1226,6 +1244,88 @@
%<@@=expl>
% \end{macrocode}
%
+% Several times users reported this error when loading \pkg{expl3}:
+% \begin{verbatim}
+% ! Undefined control sequence.
+% l.67 \bool
+% _new:N \g__expl_reload_bool
+% \end{verbatim}
+% raised in the reload block below. This happens because the reload
+% check below assumes that if the boolean \cs{g_@@_reload_bool} doesn't
+% exist, this file is being loaded for the first time, and \pkg{expl3}
+% syntax is on. This is a bit of a stretch for assumptions, but it's
+% valid as long as everything's in sync. However the problem reported
+% happened because of a stray format file in the user tree which didn't
+% have the reload code defined here (commit \texttt{1d16336}), so the
+% \cs{g_@@_reload_bool} doesn't exist, but \pkg{expl3} syntax is off,
+% thus the error.
+%
+% At this point, if we have \cs{c__kernel_expl_date_tl} defined, the
+% situation is straightforward: if it matches \cs{ExplLoaderFileDate},
+% then everything's as expected, so no need to worry. If it doesn't,
+% then the current version of \pkg{expl3} differs from the one in the
+% format, so raise a fatal error: the bahaviour is too unpredictable to
+% continue safely. Also, if the error is to be raised, then we're
+% reloading, which means that \pkg{expl3} syntax is off, so we turn it
+% on for the message.
+% \begin{macrocode}
+\ifcsname\detokenize{c__kernel_expl_date_tl}\endcsname
+ \expandafter\ifx\csname\detokenize
+ {c__kernel_expl_date_tl}\endcsname\ExplLoaderFileDate
+ \else
+ \ExplSyntaxOn
+ \__kernel_msg_set:nnn { kernel } { mismatched-expl3 }
+ {
+ Mismatched~expl3~detected!~Loading~expl3~will~abort.
+ \\ \\
+ The~version~of~expl3~preloaded~in~LaTeX~is~
+ \c__kernel_expl_date_tl,~but~the~version~of~expl3~you~are~
+ trying~to~load~is~dated~\ExplLoaderFileDate.~This~is~most~
+ likely~due~to~a~stray~format~file~in~the~user~tree.~Please~
+ make~sure~that~your~LaTeX~format~is~updated.
+ }
+ \exp_after:wN \ExplSyntaxOff \use:n
+ {
+ \__kernel_msg_critical:nn { kernel } { mismatched-expl3 }
+ \use:c { fi: } \use:c { fi: }
+ }
+ \fi
+% \end{macrocode}
+% If \cs{c__kernel_expl_date_tl} does \emph{not} exist, then we're on
+% uncharted lands (that is, any time prior to the version that
+% introduced this token list :-). Two cases might be here, depending
+% whether \pkg{expl3} is loaded into the kernel or not. If we're loading
+% \pkg{expl3} \enquote{normally} as a package, \pkg{expl3} syntax is on.
+% Otherwise it's already loaded in the kernel and we're reloading
+% \file{expl3.sty} so (\file{expl3-code.tex} doesn't load again and)
+% \pkg{expl3} syntax is off.
+% \begin{macrocode}
+\else
+ \ifodd\csname\detokenize{l__kernel_expl_bool}\endcsname
+% \end{macrocode}
+% Package mode; all should be fine, since \file{expl3.sty} and
+% \file{expl3-code.tex} are both loaded in one go, so versions should
+% match (if they don't, it's detected above).
+% Also, we've just tested that \pkg{expl3} syntax is on, so the reload
+% test below will return false and \cs{bool_new:N} will run correctly.
+% \begin{macrocode}
+ \else
+% \end{macrocode}
+% In this branch we're reloading, but there are still two cases to
+% consider (sigh\ldots); whether the version preloaded in the format
+% is recent enough to have \cs{g_@@_reload_bool} (2020-06-18 and
+% later) or not. If the boolean is there, we have to do nothing
+% because right ahead we deal with this case.
+% If it is not, we just have to create it:
+% \begin{macrocode}
+ \ExplSyntaxOn
+ \bool_if_exist:NF \g_@@_reload_bool
+ { \bool_new:N \g_@@_reload_bool }
+ \ExplSyntaxOff
+ \fi
+\fi
+% \end{macrocode}
+%
% Here we can also detect whether we're reloading. This code goes into
% \texttt{expl3.ltx} and \texttt{expl3.sty}, the former loaded into the
% \LaTeXe{} format. When this code is loaded for the first time, the
diff --git a/l3kernel/testfiles/m3expl009.lvt b/l3kernel/testfiles/m3expl009.lvt
new file mode 100644
index 000000000..aa970a7c8
--- /dev/null
+++ b/l3kernel/testfiles/m3expl009.lvt
@@ -0,0 +1,78 @@
+%
+% Copyright (C) 2020 The LaTeX3 Project
+%
+
+\input{regression-test}
+
+\START
+\AUTHOR{Phelype Oleinik}
+
+% Yet another loading test :-)
+% This one checks that expl3 properly detects if it's
+% preloaded in an older format, raising an error as
+% appropriate, if the versions don't match.
+
+\ExplSyntaxOn
+\newcount\cnta
+\cs_new_protected:Npn \RELOAD
+ { \ExplSyntaxOn \RELOAD:n }
+\cs_new_protected:Npn \RELOAD:n #1
+ {
+ \ExplSyntaxOff
+ \cs_undefine:c { ver at expl3.sty }
+ \group_begin:
+ #1
+ \RequirePackage{expl3}
+ \group_end:
+ }
+\ExplSyntaxOff
+
+% The conditionals in parentheses refer to the outcome of the
+% \ifcsname and \ifx/\ifodd tests on lines 1272 onwards of
+% expl3.dtx in the commit that introduced this file.
+% Tested adding \typeouts to each branch, but they can't
+% really stay in the code :-)
+
+
+% If the version of expl3 preloaded in the kernel differs
+% from the one in expl3.sty we have a critical error:
+\RELOAD
+ { \tl_set:Nn \c__kernel_expl_date_tl { WRONG-DATE } }
+% (TRUE, FALSE)
+
+
+% If they are equal, though, nothing bad happens. This should
+% be the most common scenario.
+\RELOAD
+ { }
+% (TRUE, TRUE)
+
+
+% If, however, this token list is not defined:
+\ExplSyntaxOn
+\cs_gset_eq:NN \c__kernel_expl_date_tl \tex_undefined:D
+\ExplSyntaxOff
+% then we're on a version of expl3 prior to the one that
+% introduced this commit, so we can't check for the version
+% and have to guess (kind of) if we're in package mode or
+% just reloading expl3.sty with the kernel code in the
+% format. This emulates a somewhat recent version
+% (2020-06-18 or later):
+\RELOAD
+ { }
+% (FALSE, FALSE)
+
+
+% And this one emulates an older version, but still
+% post-expl3-in-format:
+\RELOAD
+ { \cs_set_eq:NN \g__expl_reload_bool \tex_undefined:D }
+% (FALSE, FALSE, plus defining the reload boolean)
+
+
+% Package mode (FALSE, TRUE) can't be easily emulated in
+% this test file (and it's a bit pointless), but it works
+% when loading this version of expl3 in a 2018 TL LaTeX.
+% Yours truly,
+
+\END
diff --git a/l3kernel/testfiles/m3expl009.tlg b/l3kernel/testfiles/m3expl009.tlg
new file mode 100644
index 000000000..6f35237bd
--- /dev/null
+++ b/l3kernel/testfiles/m3expl009.tlg
@@ -0,0 +1,31 @@
+This is a generated file for the LaTeX (2e + expl3) validation system.
+Don't change this file in any respect.
+Author: Phelype Oleinik
+\cnta=\count...
+(expl3.sty
+Package: expl3 ....-..-.. L3 programming layer (loader)
+! Critical LaTeX3 Error: Mismatched expl3 detected! Loading expl3 will abort.
+(LaTeX3)
+(LaTeX3) The version of expl3 preloaded in LaTeX is
+(LaTeX3) WRONG-DATE, but the version of expl3 you are trying
+(LaTeX3) to load is dated ....-..-... This is most likely
+(LaTeX3) due to a stray format file in the user tree. Please
+(LaTeX3) make sure that your LaTeX format is updated.
+Type <return> to continue.
+ ...
+l. ... }
+LaTeX does not know anything more about this error, sorry.
+Try typing <return> to proceed.
+If that doesn't work, type X <return> to quit.
+Reading the current file 'expl3' will stop.
+) (expl3.sty
+Package: expl3 ....-..-.. L3 programming layer (loader)
+(l3backend-pdfmode.def
+File: l3backend-pdfmode.def ....-..-.. L3 backend support: PDF mode
+\l__kernel_color_stack_int=\count...
+\l__pdf_internal_box=\box...
+)) (expl3.sty
+Package: expl3 ....-..-.. L3 programming layer (loader)
+) (expl3.sty
+Package: expl3 ....-..-.. L3 programming layer (loader)
+)
More information about the latex3-commits
mailing list.