Skip to content

Commit

Permalink
More defensive \scan_stop: (fixes #417)
Browse files Browse the repository at this point in the history
Some past commit only added \scan_stop: to \dim_set:Nn, but there is also
\dim_add:Nn, \dim_set_eq:NN, \dim_zero:N and friends.
  • Loading branch information
Bruno Le Floch committed Nov 29, 2017
1 parent 815ad41 commit bf69f14
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions l3kernel/l3skip.dtx
Expand Up @@ -1075,12 +1075,15 @@
%
% \begin{macro}{\dim_zero:N, \dim_zero:c}
% \begin{macro}{\dim_gzero:N, \dim_gzero:c}
% Reset the register to zero.
% Reset the register to zero. Using \cs{c_zero_skip} deals with the
% case where the variable passed is incorrectly a skip (for example a
% \LaTeXe{} length).
% \begin{macrocode}
\__debug_patch:nnNNpn { \__debug_chk_var_local:N #1 } { }
\cs_new_protected:Npn \dim_zero:N #1 { #1 \c_zero_dim }
\cs_new_protected:Npn \dim_zero:N #1 { #1 \c_zero_skip }
\__debug_patch:nnNNpn { \__debug_chk_var_global:N #1 } { }
\cs_new_protected:Npn \dim_gzero:N #1 { \tex_global:D #1 \c_zero_dim }
\cs_new_protected:Npn \dim_gzero:N #1
{ \tex_global:D #1 \c_zero_skip }
\cs_generate_variant:Nn \dim_zero:N { c }
\cs_generate_variant:Nn \dim_gzero:N { c }
% \end{macrocode}
Expand Down Expand Up @@ -1132,7 +1135,7 @@
% \begin{macro}{\dim_gset:Nn, \dim_gset:cn}
% Setting dimensions is easy enough but when debugging we want both to
% check that the variable is correctly local/global and to wrap the
% expression in some code. The |\scan_stop:| deals with the case
% expression in some code. The \cs{scan_stop:} deals with the case
% where the variable passed is a skip (for example a \LaTeXe{}
% length).
% \begin{macrocode}
Expand All @@ -1151,14 +1154,17 @@
% \begin{macro}{\dim_set_eq:NN, \dim_set_eq:cN, \dim_set_eq:Nc, \dim_set_eq:cc}
% \begin{macro}
% {\dim_gset_eq:NN, \dim_gset_eq:cN, \dim_gset_eq:Nc, \dim_gset_eq:cc}
% All straightforward.
% All straightforward, with a \cs{scan_stop:} to deal with the case
% where |#1| is (incorrectly) a skip.
% \begin{macrocode}
\__debug_patch:nnNNpn { \__debug_chk_var_local:N #1 } { }
\cs_new_protected:Npn \dim_set_eq:NN #1#2 { #1 = #2 }
\cs_new_protected:Npn \dim_set_eq:NN #1#2
{ #1 = #2 \scan_stop: }
\cs_generate_variant:Nn \dim_set_eq:NN { c }
\cs_generate_variant:Nn \dim_set_eq:NN { Nc , cc }
\__debug_patch:nnNNpn { \__debug_chk_var_global:N #1 } { }
\cs_new_protected:Npn \dim_gset_eq:NN #1#2 { \tex_global:D #1 = #2 }
\cs_new_protected:Npn \dim_gset_eq:NN #1#2
{ \tex_global:D #1 = #2 \scan_stop: }
\cs_generate_variant:Nn \dim_gset_eq:NN { c }
\cs_generate_variant:Nn \dim_gset_eq:NN { Nc , cc }
% \end{macrocode}
Expand All @@ -1169,26 +1175,27 @@
% \begin{macro}{\dim_gadd:Nn, \dim_gadd:cn}
% \begin{macro}{\dim_sub:Nn, \dim_sub:cn}
% \begin{macro}{\dim_gsub:Nn, \dim_gsub:cn}
% Using |by| here deals with the (incorrect) case |\dimen123|. Since
% Using |by| here deals with the (incorrect) case |\dimen123|.
% Using \cs{scan_stop:} deals with skip variables. Since
% debugging checks that the variable is correctly local/global, the
% global versions cannot be defined as \cs{tex_global:D} followed by
% the local versions. The debugging code is inserted by
% \cs{@@_tmp:w}.
% \begin{macrocode}
\@@_tmp:w \__debug_chk_var_local:N
\cs_new_protected:Npn \dim_add:Nn #1#2
{ \tex_advance:D #1 by \@@_eval:w #2 \@@_eval_end: }
{ \tex_advance:D #1 by \@@_eval:w #2 \@@_eval_end: \scan_stop: }
\@@_tmp:w \__debug_chk_var_global:N
\cs_new_protected:Npn \dim_gadd:Nn #1#2
{ \tex_global:D \tex_advance:D #1 by \@@_eval:w #2 \@@_eval_end: }
{ \tex_global:D \tex_advance:D #1 by \@@_eval:w #2 \@@_eval_end: \scan_stop: }
\cs_generate_variant:Nn \dim_add:Nn { c }
\cs_generate_variant:Nn \dim_gadd:Nn { c }
\@@_tmp:w \__debug_chk_var_local:N
\cs_new_protected:Npn \dim_sub:Nn #1#2
{ \tex_advance:D #1 by - \@@_eval:w #2 \@@_eval_end: }
{ \tex_advance:D #1 by - \@@_eval:w #2 \@@_eval_end: \scan_stop: }
\@@_tmp:w \__debug_chk_var_global:N
\cs_new_protected:Npn \dim_gsub:Nn #1#2
{ \tex_global:D \tex_advance:D #1 by - \@@_eval:w #2 \@@_eval_end: }
{ \tex_global:D \tex_advance:D #1 by - \@@_eval:w #2 \@@_eval_end: \scan_stop: }
\cs_generate_variant:Nn \dim_sub:Nn { c }
\cs_generate_variant:Nn \dim_gsub:Nn { c }
% \end{macrocode}
Expand Down

0 comments on commit bf69f14

Please sign in to comment.