[latex3-commits] [git/LaTeX3-latex3-latex3] master: Check local/global scope of variables in l3intarray and tl_build (8f4d8c4)
Bruno Le Floch
bruno at le-floch.fr
Sun Apr 1 21:26:21 CEST 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/8f4d8c4bb2de1bfe3b5ad63bccf2567adf0f7d30
>---------------------------------------------------------------
commit 8f4d8c4bb2de1bfe3b5ad63bccf2567adf0f7d30
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Sun Apr 1 15:26:21 2018 -0400
Check local/global scope of variables in l3intarray and tl_build
>---------------------------------------------------------------
8f4d8c4bb2de1bfe3b5ad63bccf2567adf0f7d30
l3kernel/l3candidates.dtx | 29 +++--
l3kernel/l3intarray.dtx | 3 +
l3kernel/testfiles/m3tl-build001.lvt | 38 +++++--
l3kernel/testfiles/m3tl-build001.tlg | 196 ++++++++++++++++++++++++++++++++++
4 files changed, 247 insertions(+), 19 deletions(-)
diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index 289fdde..e5933a5 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -4159,10 +4159,12 @@
% definition does not seem useful so we just do |#3| |#1| |{}| to
% clear it locally or globally as appropriate.
% \begin{macrocode}
-\cs_new_protected:Npn \tl_build_begin:N
- { \@@_build_begin:NN \cs_set_nopar:Npx }
-\cs_new_protected:Npn \tl_build_gbegin:N
- { \@@_build_begin:NN \cs_gset_nopar:Npx }
+\__kernel_patch:nnNNpn { \__kernel_chk_var_local:N #1 } { }
+\cs_new_protected:Npn \tl_build_begin:N #1
+ { \@@_build_begin:NN \cs_set_nopar:Npx #1 }
+\__kernel_patch:nnNNpn { \__kernel_chk_var_global:N #1 } { }
+\cs_new_protected:Npn \tl_build_gbegin:N #1
+ { \@@_build_begin:NN \cs_gset_nopar:Npx #1 }
\cs_new_protected:Npn \@@_build_begin:NN #1#2
{ \exp_args:Nc \@@_build_begin:NNN { \cs_to_str:N #2 ' } #2 #1 }
\cs_new_protected:Npn \@@_build_begin:NNN #1#2#3
@@ -4202,21 +4204,25 @@
% implies that the assignment does not simply set the token list to an
% |x|-expansion of the second argument.
% \begin{macrocode}
+\__kernel_patch:nnNNpn { \__kernel_chk_var_local:N #1 } { }
\cs_new_protected:Npn \tl_build_put_right:Nn #1#2
{
\cs_set_nopar:Npx #1
{ \exp_after:wN \exp_not:n \exp_after:wN { \exp:w #1 #2 } }
}
+\__kernel_patch:nnNNpn { \__kernel_chk_var_local:N #1 } { }
\cs_new_protected:Npn \tl_build_put_right:Nx #1#2
{
\cs_set_nopar:Npx #1
{ \exp_after:wN \exp_not:n \exp_after:wN { \exp:w #1 } #2 }
}
+\__kernel_patch:nnNNpn { \__kernel_chk_var_global:N #1 } { }
\cs_new_protected:Npn \tl_build_gput_right:Nn #1#2
{
\cs_gset_nopar:Npx #1
{ \exp_after:wN \exp_not:n \exp_after:wN { \exp:w #1 #2 } }
}
+\__kernel_patch:nnNNpn { \__kernel_chk_var_global:N #1 } { }
\cs_new_protected:Npn \tl_build_gput_right:Nx #1#2
{
\cs_gset_nopar:Npx #1
@@ -4256,11 +4262,13 @@
% add the \meta{right} material after the \Arg{left} in the
% |x|-expanding assignment.
% \begin{macrocode}
-\cs_new_protected:Npn \tl_build_put_left:Nn
- { \@@_build_put_left:NNn \cs_set_nopar:Npx }
+\__kernel_patch:nnNNpn { \__kernel_chk_var_local:N #1 } { }
+\cs_new_protected:Npn \tl_build_put_left:Nn #1
+ { \@@_build_put_left:NNn \cs_set_nopar:Npx #1 }
\cs_generate_variant:Nn \tl_build_put_left:Nn { Nx }
-\cs_new_protected:Npn \tl_build_gput_left:Nn
- { \@@_build_put_left:NNn \cs_gset_nopar:Npx }
+\__kernel_patch:nnNNpn { \__kernel_chk_var_global:N #1 } { }
+\cs_new_protected:Npn \tl_build_gput_left:Nn #1
+ { \@@_build_put_left:NNn \cs_gset_nopar:Npx #1 }
\cs_generate_variant:Nn \tl_build_gput_left:Nn { Nx }
\cs_new_protected:Npn \@@_build_put_left:NNn #1#2#3
{
@@ -4304,11 +4312,12 @@
% \begin{macro}{\tl_build_end:N, \tl_build_gend:N, \@@_build_end_loop:NN}
% Get the data then clear the \meta{next~tl} recursively until finding
% an empty one. It is perhaps wasteful to repeatedly use
-% \cs{cs_to_sr:N}.
+% \cs{cs_to_sr:N}. The local/global scope is checked by
+% \cs{tl_set:Nx} or \cs{tl_gset:Nx}.
% \begin{macrocode}
\cs_new_protected:Npn \tl_build_end:N #1
{
- \tl_build_get:NN #1 #1
+ \@@_build_get:NNN \tl_set:Nx #1 #1
\exp_args:Nc \@@_build_end_loop:NN { \cs_to_str:N #1 ' } \tl_clear:N
}
\cs_new_protected:Npn \tl_build_gend:N #1
diff --git a/l3kernel/l3intarray.dtx b/l3kernel/l3intarray.dtx
index 56bb160..645d7f6 100644
--- a/l3kernel/l3intarray.dtx
+++ b/l3kernel/l3intarray.dtx
@@ -155,7 +155,10 @@
% It seems \LuaTeX{}'s |cmr10| has an extra \tn{fontdimen} parameter
% number $8$ compared to other engines (for a math font we would
% replace $8$ by $22$ or some such).
+% Every \texttt{intarray} must be global; it's enough to run this
+% check in \cs{intarray_new:Nn}.
% \begin{macrocode}
+\__kernel_patch:nnNNpn { \__kernel_chk_var_scope:NN g #1 } { }
\cs_new_protected:Npn \intarray_new:Nn #1#2
{
\__kernel_chk_if_free_cs:N #1
diff --git a/l3kernel/testfiles/m3tl-build001.lvt b/l3kernel/testfiles/m3tl-build001.lvt
index 063b6f2..86a25dc 100644
--- a/l3kernel/testfiles/m3tl-build001.lvt
+++ b/l3kernel/testfiles/m3tl-build001.lvt
@@ -15,7 +15,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\TEST { Building~a~token~list }
{
- \tl_build_begin:N \l_tmpa_tl
+ \group_begin:
+ \tl_build_begin:N \l_tmpa_tl
\tl_build_put_right:Nn \l_tmpa_tl { # }
\tl_build_put_right:Nn \l_tmpa_tl { AB }
\tl_build_put_right:Nn \l_tmpa_tl { \par }
@@ -23,17 +24,36 @@
\tl_build_put_right:Nn \l_tmpa_tl { \c_space_tl }
\tl_build_put_right:Nn \l_tmpa_tl { ## }
\tl_build_put_left:Nn \l_tmpa_tl { \foo }
- \tl_build_end:N \l_tmpa_tl
- \TYPE { \tl_to_str:N \l_tmpa_tl }
- \tl_build_begin:N \l_tmpa_tl
+ \tl_build_end:N \l_tmpa_tl
+ \TYPE { \tl_to_str:N \l_tmpa_tl }
+ \tl_build_gbegin:N \g_tmpb_tl
\int_step_inline:nnnn { 1 } { 1 } { 154 }
{
- \tl_build_put_right:Nn \l_tmpa_tl { #1 : }
- \tl_build_put_left:Nn \l_tmpa_tl { #1 ~ }
- \tl_build_put_right:Nx \l_tmpa_tl { \tl_reverse:n {#1} ~ }
+ \tl_build_gput_right:Nn \g_tmpb_tl { #1 : }
+ \tl_build_gput_left:Nn \g_tmpb_tl { #1 ~ }
+ \tl_build_gput_right:Nx \g_tmpb_tl { \tl_reverse:n {#1} ~ }
}
- \tl_build_end:N \l_tmpa_tl
- \TYPE { \tl_to_str:N \l_tmpa_tl }
+ \tl_build_gend:N \g_tmpb_tl
+ \group_end:
+ \tl_if_empty:NF \l_tmpa_tl { \ERROR }
+ \TYPE { \tl_to_str:N \g_tmpb_tl }
+ }
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\TEST { Building~a~token~list~scope~errors }
+ {
+ \tl_build_begin:N \g_tmpb_tl
+ \tl_build_put_left:Nn \g_tmpb_tl { a }
+ \tl_build_put_left:Nx \g_tmpb_tl { a }
+ \tl_build_put_right:Nn \g_tmpb_tl { a }
+ \tl_build_put_right:Nx \g_tmpb_tl { a }
+ \tl_build_end:N \g_tmpb_tl
+ \tl_build_gbegin:N \l_tmpa_tl
+ \tl_build_gput_left:Nn \l_tmpa_tl { a }
+ \tl_build_gput_left:Nx \l_tmpa_tl { a }
+ \tl_build_gput_right:Nn \l_tmpa_tl { a }
+ \tl_build_gput_right:Nx \l_tmpa_tl { a }
+ \tl_build_gend:N \l_tmpa_tl
}
\END
diff --git a/l3kernel/testfiles/m3tl-build001.tlg b/l3kernel/testfiles/m3tl-build001.tlg
index 0765e38..3eadf90 100644
--- a/l3kernel/testfiles/m3tl-build001.tlg
+++ b/l3kernel/testfiles/m3tl-build001.tlg
@@ -7,3 +7,199 @@ TEST 1: Building a token list
\foo \##AB\par \c_space_tl ####
154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 1:1 2:2 3:3 4:4 5:5 6:6 7:7 8:8 9:9 10:01 11:11 12:21 13:31 14:41 15:51 16:61 17:71 18:81 19:91 20:02 21:12 22:22 23:32 24:42 25:52 26:62 27:72 28:82 29:92 30:03 31:13 32:23 33:33 34:43 35:53 36:63 37:73 38:83 39:93 40:04 41:14 42:24 43:34 44:44 45:54 46:64 47:74 48:84 49:94 50:05 51:15 52:25 53:35 54:45 55:55 56:65 57:75 58:85 59:95 60:06 61:16 62:26 63:36 64:46 65:56 66:66 67:76 68:86 69:96 70:07 71:17 72:27 73:37 74:47 75:57 76:67 77:77 78:87 79:97 80:08 81:18 82:28 83:38 84:48 85:58 86:68 87:78 88:88 89:98 90:09 91:19 92:29 93:39 94:49 95:59 96:69 97:79 98:89 99:99 100:001 101:101 102:201 103:301 104:401 105:501 106:601 107:701 108:801 109:901 110:011 111:111 112:211 113:311 114:411 115:511 116:611 117:711 118:811 119:911 120:021 121:121 122:221 123:321 124:421 125:521 126:621 127:721 128:821 129:921 130:031 131:131 132:231 133:331 134:431 135:531 136:631 137:731 138:831 139:931 140:041 141:141 142:241 143:341 144:441 145:541 146:641 147:741 148:841 149:941 150:051 151:151 152:251 153:351 154:451
============================================================
+============================================================
+TEST 2: Building a token list scope errors
+============================================================
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Local assignment to a global variable '\g_tmpb_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Local assignment to a global variable '\g_tmpb_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Local assignment to a global variable '\g_tmpb_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Local assignment to a global variable '\g_tmpb_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Local assignment to a global variable '\g_tmpb_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Local assignment to a global variable '\g_tmpb_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Global assignment to a local variable '\l_tmpa_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Global assignment to a local variable '\l_tmpa_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Global assignment to a local variable '\l_tmpa_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Global assignment to a local variable '\l_tmpa_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Global assignment to a local variable '\l_tmpa_tl'.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/local-global"
+!
+! Inconsistent local/global assignment
+!
+! See the LaTeX3 documentation for further information.
+!
+! For immediate help type H <return>.
+!...............................................
+l. ... }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+|
+| Global assignment to a local variable '\l_tmpa_tl'.
+|...............................................
+============================================================
More information about the latex3-commits
mailing list