summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authorClement David <clement.david@esi-group.com>2020-03-03 11:00:19 +0100
committerClément David <clement.david@esi-group.com>2021-02-18 16:14:12 +0100
commit321f8cd00067cd7cc93fe8490a87ae6d202cd6e6 (patch)
tree694c9b436e66861a5bbfb7222267b1bd1ce13559 /scilab
parent5b1796f81da0774a6f931df586c936d6a8914d8b (diff)
downloadscilab-321f8cd00067cd7cc93fe8490a87ae6d202cd6e6.zip
scilab-321f8cd00067cd7cc93fe8490a87ae6d202cd6e6.tar.gz
* Bug 16357 fixed - Xcos context no longer handled exec()
http://bugzilla.scilab.org/16357 Change-Id: Ia43e42c24b187c7e2ad2efb969c3cfd73f78eff8
Diffstat (limited to 'scilab')
-rw-r--r--scilab/CHANGES.md1
-rw-r--r--scilab/modules/scicos/macros/scicos_scicos/script2var.sci57
-rw-r--r--scilab/modules/scicos/tests/nonreg_tests/bug_16357.tst39
3 files changed, 69 insertions, 28 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index b6c266f..2f9a160 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -313,6 +313,7 @@ Bug Fixes
313* [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2. 313* [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2.
314* [#16350](https://bugzilla.scilab.org/16350): in if/while conditions, the empty sparse boolean was considered as TRUE. 314* [#16350](https://bugzilla.scilab.org/16350): in if/while conditions, the empty sparse boolean was considered as TRUE.
315* [#16358](https://bugzilla.scilab.org/16358): `isdef([],..)` yielded an error instead of returning []. 315* [#16358](https://bugzilla.scilab.org/16358): `isdef([],..)` yielded an error instead of returning [].
316* [#16357](https://bugzilla.scilab.org/16357): `script2var` did get variables generated by `exec()`.
316* [#16362](https://bugzilla.scilab.org/16362): sparse empty matrix could no be concatenated. 317* [#16362](https://bugzilla.scilab.org/16362): sparse empty matrix could no be concatenated.
317* [#16365](https://bugzilla.scilab.org/16365): `median(m,"r")` and `median(m,"c")` yielded wrong results (6.1.0 regression) 318* [#16365](https://bugzilla.scilab.org/16365): `median(m,"r")` and `median(m,"c")` yielded wrong results (6.1.0 regression)
318* [#16366](https://bugzilla.scilab.org/16366): `plot([0 1], ":")` plotted a dash-dotted curve instead of a dotted one. 319* [#16366](https://bugzilla.scilab.org/16366): `plot([0 1], ":")` plotted a dash-dotted curve instead of a dotted one.
diff --git a/scilab/modules/scicos/macros/scicos_scicos/script2var.sci b/scilab/modules/scicos/macros/scicos_scicos/script2var.sci
index 1ea8f06..b6d9e34 100644
--- a/scilab/modules/scicos/macros/scicos_scicos/script2var.sci
+++ b/scilab/modules/scicos/macros/scicos_scicos/script2var.sci
@@ -2,7 +2,7 @@
2// 2//
3// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> 3// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4// Copyright (C) 2011 - INRIA - Serge Steer 4// Copyright (C) 2011 - INRIA - Serge Steer
5// Copyright (C) 2018 - Samuel GOUGEON 5// Copyright (C) 2018, 2020 - Samuel GOUGEON
6// 6//
7// This program is free software; you can redistribute it and/or modify 7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by 8// it under the terms of the GNU General Public License as published by
@@ -23,8 +23,8 @@
23 23
24function [%ll,%ierr] = script2var(%txt, %ll) 24function [%ll,%ierr] = script2var(%txt, %ll)
25 //** [%scicos_context, ierr] = script2var(context, %scicos_context) 25 //** [%scicos_context, ierr] = script2var(context, %scicos_context)
26 //** context is the scs_m.props.context (string array) associated with the current level 26 //** %txt is the scs_m.props.context (string array) associated with the current level
27 //** %scicos_context is a struct containing the values defined by the 27 //** %ll is a struct containing the values defined by the
28 // calling contexts 28 // calling contexts
29 //** 29 //**
30 //** 10 Jan 2006 30 //** 10 Jan 2006
@@ -48,7 +48,6 @@ function [%ll,%ierr] = script2var(%txt, %ll)
48 end 48 end
49 end 49 end
50 [%ll,%ierr] = getvardef(%txt,%ll) 50 [%ll,%ierr] = getvardef(%txt,%ll)
51 if %ierr<>0 then return, end
52endfunction 51endfunction
53 52
54//**-------------------------------------------------------------------------- 53//**--------------------------------------------------------------------------
@@ -59,11 +58,14 @@ function [%ll,%ierr]=getvardef(%txt,%ll)
59 //local variable names are prefixed with a % to limit conflicts with 58 //local variable names are prefixed with a % to limit conflicts with
60 //variables defined in %txt instructions 59 //variables defined in %txt instructions
61 60
62 %ierr = 0; // to make sure %ierr does not enter the difference
63 if isempty(%txt) then return,end 61 if isempty(%txt) then return,end
64 62
65 %ierr = execstr(%txt,"errcatch"); 63 global %_old_ // safe location in case of clear() in the context
66 if %ierr<>0 then 64 %_ierr_ = 0; // to make sure %ierr does not enter the difference
65 %_old_ = who("scope")
66 %_old_ = %_old_(isdef(%_old_,"l"))
67 %_ierr_ = execstr(%txt,"errcatch");
68 if %_ierr_<>0 then
67 if errInMsgbox 69 if errInMsgbox
68 messagebox(lasterror(), _("Set Xcos context"), "warning", "modal") 70 messagebox(lasterror(), _("Set Xcos context"), "warning", "modal")
69 else 71 else
@@ -71,33 +73,32 @@ function [%ll,%ierr]=getvardef(%txt,%ll)
71 end 73 end
72 return 74 return
73 end 75 end
74 76 global %_old_
75 // Use 'macrovar' to extract the variable names present in %txt: listvar(5) contains all the output variables of the context 77 %_new_ = who("scope");
76 clear("foo"); // Locally reserve the "foo" name to avoid redefinition warning 78 %_new_ = setdiff(%_new_, %_old_)
77 deff("foo()", %txt); 79 if %_new_ <> [] then
78 listvar = macrovar(foo); 80 %_new_ = %_new_(isdef(%_new_,"l"))
79 %mm = listvar(5);
80 // In case clear() has been used in the context, remove its arguments
81 if %mm <> [] then
82 %mm(~isdef(%mm, "l")) = [];
83 end 81 end
82 clearglobal %_old_
84 83
85 msg = [] 84 %_msg = []
86 tmp = _("The variable name %s cannot be used as block parameter: ignored\n") 85 %_tmp = _("The variable name %s cannot be used as block parameter: ignored\n")
87 msg0 = msprintf(tmp, "scs_m") 86 %_msg0 = msprintf(%_tmp, "scs_m")
88 for %mi=%mm' 87 %_forbid = ["scs_m"]
89 if %mi=="scs_m" then 88 %_ignore = ["ans"]
90 msg = [msg ; msg0] 89 for %mi = matrix(%_new_, 1, -1)
90 if or(%mi==%_forbid) then
91 %_msg = [%_msg ; %_msg0]
91 continue 92 continue
92 elseif %mi=="ans" then 93 elseif or(%mi==%_ignore) then
93 continue 94 continue
94 end 95 end
95 96
96 clear %v 97 clear %v
97 %v=evstr(%mi); 98 %v = evstr(%mi);
98 99
99 if typeof(%v)=="scs_m" then 100 if typeof(%v)=="scs_m" then
100 msg = [msg ; msg0] 101 %_msg = [%_msg ; %_msg0]
101 continue 102 continue
102 elseif or(type(%v)==[13 14]) then 103 elseif or(type(%v)==[13 14]) then
103 continue 104 continue
@@ -106,11 +107,11 @@ function [%ll,%ierr]=getvardef(%txt,%ll)
106 %ll(%mi)=%v; 107 %ll(%mi)=%v;
107 clear %v 108 clear %v
108 end 109 end
109 if msg ~=[] then 110 if %_msg ~=[] then
110 if errInMsgbox 111 if errInMsgbox
111 messagebox(msg, _("Set Xcos context"), "warning", "modal") 112 messagebox(%_msg, _("Set Xcos context"), "warning", "modal")
112 else 113 else
113 mprintf("%s\n", msg) 114 mprintf("%s\n", %_msg)
114 end 115 end
115 end 116 end
116endfunction 117endfunction
diff --git a/scilab/modules/scicos/tests/nonreg_tests/bug_16357.tst b/scilab/modules/scicos/tests/nonreg_tests/bug_16357.tst
new file mode 100644
index 0000000..c7091e4
--- /dev/null
+++ b/scilab/modules/scicos/tests/nonreg_tests/bug_16357.tst
@@ -0,0 +1,39 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2020 - ESI Group - Clement DAVID
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7//
8// <-- CLI SHELL MODE -->
9// <-- NO CHECK REF -->
10//
11// <-- Non-regression test for bug 16357 -->
12//
13// <-- Bugzilla URL -->
14// http://bugzilla.scilab.org/show_bug.cgi?id=16357
15//
16// <-- Short Description -->
17// script2var failed found variables defined by an exec() call
18//
19
20[st, ierr] = script2var("", struct());
21assert_checkequal(st, struct());
22
23[st, ierr] = script2var("a=1", struct());
24assert_checkequal(st.a, 1);
25
26[st, ierr] = script2var("a=1;b=2", struct());
27assert_checkequal(st.a, 1);
28assert_checkequal(st.b, 2);
29
30f=fullfile(TMPDIR, "vars.ini");
31mputl("a=1", f);
32
33[st, ierr] = script2var("exec(f, -1);b=2", struct());
34assert_checkequal(st.a, 1);
35assert_checkequal(st.b, 2);
36
37[st, ierr] = script2var("a=1; clear;b=2", struct());
38assert_checkequal(st.b, 2);
39assert_checkequal(fieldnames(st), "b");