From 4a89059362ec72afda9ebdf1cb0566b4e7ee5276 Mon Sep 17 00:00:00 2001 From: Samuel GOUGEON Date: Sat, 31 Aug 2019 14:28:48 +0200 Subject: [PATCH] * Bug 16178 fixed: sci2exp() failed with input macros w/o argout http://bugzilla.scilab.org/16178 Change-Id: I559ba07dfd92e1c318e10836ab946d8c3aa6a3ac --- scilab/CHANGES.md | 3 +- scilab/modules/functions/macros/createfun.sci | 2 +- scilab/modules/string/macros/sci2exp.sci | 7 +-- .../string/tests/nonreg_tests/bug_16178.tst | 50 ++++++++++++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 scilab/modules/string/tests/nonreg_tests/bug_16178.tst diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index 2591b72..13a2628 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -270,6 +270,7 @@ Bug Fixes * [#16160](http://bugzilla.scilab.org/show_bug.cgi?id=16160): `ppol` changed values of third input variable. * [#16164](http://bugzilla.scilab.org/show_bug.cgi?id=16164): Help pages in elementary_functions/signal_processing were mislocated. * [#16174](http://bugzilla.scilab.org/show_bug.cgi?id=16174): `libraryinfo` yielded 0x0 matrix of strings for libs without macro +* [#16178](http://bugzilla.scilab.org/show_bug.cgi?id=16178): `sci2exp` yielded an error for any input macro without output argument. * [#16197](http://bugzilla.scilab.org/show_bug.cgi?id=16197): result of extraction was not decomplexified when applicable. * [#16200](http://bugzilla.scilab.org/show_bug.cgi?id=16200): Concatenation of transposed cells crashed Scilab. * [#16208](http://bugzilla.scilab.org/show_bug.cgi?id=16208): Using 3D string matrix with old C-api gateways may crash Scilab. @@ -290,5 +291,3 @@ Bug Fixes * [#16293](http://bugzilla.scilab.org/show_bug.cgi?id=16293): Some demos run in step-by-step console mode(4) did not focus user's attention to the console to proceed. * [#16299](http://bugzilla.scilab.org/show_bug.cgi?id=16299): After `graypolarplot()`, `colorbar()` displayed an empty ungraduated color bar. * [#16303](http://bugzilla.scilab.org/show_bug.cgi?id=16303): log10(x) had wrong dimensions when x is an hypermatrix. - - diff --git a/scilab/modules/functions/macros/createfun.sci b/scilab/modules/functions/macros/createfun.sci index e7eacd1..e9cafc6 100644 --- a/scilab/modules/functions/macros/createfun.sci +++ b/scilab/modules/functions/macros/createfun.sci @@ -20,7 +20,7 @@ function %fun=createfun(t) end h=t(1) k=strindex(h,"=") - if k==[] then k1=1,else k1=k(1),end + if k==[] then k1=0,else k1=k(1),end k=strindex(h,"(") if k==[] then k2=length(h),else k2=k(1),end h=part(h,1:k1)+"%fun"+part(h,k2:length(h)) diff --git a/scilab/modules/string/macros/sci2exp.sci b/scilab/modules/string/macros/sci2exp.sci index d40753e..2ec0948 100644 --- a/scilab/modules/string/macros/sci2exp.sci +++ b/scilab/modules/string/macros/sci2exp.sci @@ -1,7 +1,7 @@ // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab // Copyright (C) INRIA - // Copyright (C) 2012 - 2016 - Scilab Enterprises -// Copyright (C) 2016, 2017 - Samuel GOUGEON +// Copyright (C) 2016, 2017, 2019 - Samuel GOUGEON // // This file is hereby licensed under the terms of the GNU GPL v2.0, // pursuant to article 5.3.4 of the CeCILL v.2.1. @@ -85,10 +85,7 @@ function t=sci2exp(a,nom,lmax) if named then name=nom; end - idx=strindex(strfun(1), "="); - idx2=strindex(part(strfun(1), idx:$), "(") + idx - 1; - str=part(strfun(1), 1:idx) + " "+ name + part(strfun(1), idx2:length(strfun(1))); - strfun(1)=str; + strfun(1) = strsubst(strfun(1), tree.name+"(", name+"("); strfun($)=[]; t=strfun; t(1) = part(t(1),10:length(t(1))) diff --git a/scilab/modules/string/tests/nonreg_tests/bug_16178.tst b/scilab/modules/string/tests/nonreg_tests/bug_16178.tst new file mode 100644 index 0000000..d47c987 --- /dev/null +++ b/scilab/modules/string/tests/nonreg_tests/bug_16178.tst @@ -0,0 +1,50 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2019 - Samuel GOUGEON +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// <-- NO CHECK REF --> + +// <-- Non-regression test for bug 16178 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/16178 +// +// <-- Short Description --> +// sci2exp() yielded an error for any input macro without argout +// ------------------------------------------------------------- + +function Q1() + a.b +endfunction +assert_checkequal(sci2exp(Q1), "createfun([""%fun()"";""a.b""])"); +assert_checkequal(sci2exp(Q1,"Q"), "createfun([""Q()"";""a.b""])"); + + +// The used internal createfun() failed for a function returning nothing: +// --------------------------------------------------------------------- +//--> f=createfun(["b=fun(a)";"b=a.b"]) +// f = +// [b]=f(a) // OK +// +//--> f=createfun(["fun(a)";"b=a.b"]) +// at line 1 of executed string +// at line 10 of function deff ( SCI\modules\functions\macros\deff.sci line 10 ) +// at line 15 of function createfun ( SCI\modules\functions\macros\createfun.sci line 27 ) +// +// function f%fun(a) +// ^~~~^ +// Error: syntax error, unexpected identifier, expecting end of line or "," or ; or line comment + +// NR Test: + +%fghw = createfun(["fun(a)";"b=a.b"]); // without output +assert_checkequal(type(%fghw), 13) + +%fghw2 = createfun(["b=fun(a)";"b=a.b"]); // with output +assert_checkequal(type(%fghw2), 13) +s.b = %pi; +assert_checkequal(%fghw2(s), %pi) -- 1.7.9.5