* Bug #10243 fixed - Functions: fix for fun2string 10/13210/2
Samuel GOUGEON [Fri, 22 Nov 2013 15:20:53 +0000 (16:20 +0100)]
fun2string(X) called X before returning its code.

Change-Id: I4874fa5176338b9d3bdf9f361db8f0701e06b97d

scilab/CHANGES_5.5.X
scilab/modules/functions/macros/fun2string.sci
scilab/modules/functions/tests/nonreg_tests/bug_10243.dia.ref [new file with mode: 0644]
scilab/modules/functions/tests/nonreg_tests/bug_10243.tst [new file with mode: 0644]

index aafbcae..e620abe 100644 (file)
@@ -101,6 +101,8 @@ Scilab Bug Fixes
 
 * Bug #10234 fixed - reglin function moved from CACSD to Statistics module.
 
+* Bug #10243 fixed - fun2string(X) called X before returning its code.
+
 * Bug #10271 fixed - ordmmd now checks the consistency of the third input argument with the
                      input matrix defined by the two first input arguments.
 
index 3fdb799..c66f93b 100644 (file)
@@ -1,4 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Samuel GOUGEON: http://bugzilla.scilab.org/10243 fixed
 // Copyright (C) 1999-2010 INRIA - Serge STEER <serge.steer@inria.fr>
 //
 // This file must be used under the terms of the CeCILL.
@@ -7,7 +8,7 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function txt=fun2string(fun,nam)
+function txt = fun2string(fun,nam)
 
     // form  syntax to scilab of a compiled function
     //%Parameters
@@ -283,8 +284,16 @@ function [txt,ilst]=cod2sci(lst,ilst)
                                 end
                             end
                         elseif type(P(1))==10 then
-                            if execstr(P(1), "errcatch") == 0 & typeof(evstr(P(1)))==10 then
-                                p="."+evstr(P(1))
+                            testOK = execstr("tmp = evstr(P(1))","errcatch")==0
+                            if testOK
+                                testOK = type(tmp)==10
+                                clear tmp
+                                if testOK
+                                    testOK = (execstr(P(1), "errcatch")==0)
+                                end
+                            end
+                            if testOK then
+                                p = "."+evstr(P(1))
                             else
                                 if P(1)=="eye()" then P(1)=":",end
                                 p="("+P(1)+")"
@@ -369,13 +378,24 @@ function [stk,txt,ilst]=exp2sci(lst,ilst)
                             stk(top)=list(op(2),"0")
                             m=%f
                         elseif type(stk(top)(1))==10 then
-                            if op(4)=="1"&funptr(op(2))==0&exists(op(2))==0|(execstr(op(2),"errcatch")==0&and(type(evstr(op(2)))<>[11 13 130])) then
+                            testOK = (op(4)=="1" & ~funptr(op(2)) & ~exists(op(2)))
+                            if ~testOK then
+                                testOK = execstr("tmp = evstr(op(2))", "errcatch")==0
+                                if testOK
+                                    testOK = and(type(tmp)<>[11 13 130])
+                                    clear tmp
+                                    if testOK
+                                        testOK =  (execstr(op(2),"errcatch")==0)
+                                    end
+                                end
+                            end
+                            if testOK then
                                 top=top+1
                                 stk(top)=list(op(2),"0")
                                 m=%f
-                                //        stk(top)(1)=op(2)+'.'+stk(top)(1)
-                                //        pause
-                                //        m=%f
+                                // stk(top)(1)=op(2)+'.'+stk(top)(1)
+                                // pause
+                                // m = %f
                             end
                         end
                     end
@@ -908,11 +928,21 @@ function [stk,txt,top]=_e2sci()
                 end
             end
             stk=list(ex,"0")
-        elseif type(s2(1))==10&execstr(s2(1),"errcatch")==0&type(evstr(s2(1)))==10 then // recursive extraction
-            stk=list(sn(1)+"."+evstr(s2(1)),"0")
         else
-            if s2(1)=="eye()" then s2(1)=":",end
-            stk=list(sn(1)+"("+s2(1)+")","0")
+            testOK = type(s2(1))==10 & (execstr("tmp = evstr(s2(1))", "errcatch")==0)
+            if testOK
+                testOK = type(tmp)==10
+                clear tmp
+                if testOK
+                    testOK = (execstr(s2(1),"errcatch")==0)
+                end
+            end
+            if testOK then // recursive extraction
+                stk=list(sn(1)+"."+evstr(s2(1)),"0")
+            else
+                if s2(1)=="eye()" then s2(1)=":",end
+                stk=list(sn(1)+"("+s2(1)+")","0")
+            end
         end
     elseif rhs==0 then
         sn(1)=sn(1)+"()";
diff --git a/scilab/modules/functions/tests/nonreg_tests/bug_10243.dia.ref b/scilab/modules/functions/tests/nonreg_tests/bug_10243.dia.ref
new file mode 100644 (file)
index 0000000..c943b93
--- /dev/null
@@ -0,0 +1,21 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- ENGLISH IMPOSED -->
+//
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 10243 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=10243
+//
+// <-- Short Description -->
+// fun2string(fun) called fun before returning its code.
+// Checking that fun2string(members) does not display anything.
+// If it did, then it would mean that members() has been called.
+fun2string(members);
diff --git a/scilab/modules/functions/tests/nonreg_tests/bug_10243.tst b/scilab/modules/functions/tests/nonreg_tests/bug_10243.tst
new file mode 100644 (file)
index 0000000..081ed46
--- /dev/null
@@ -0,0 +1,22 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- ENGLISH IMPOSED -->
+//
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 10243 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=10243
+//
+// <-- Short Description -->
+// fun2string(fun) called fun before returning its code.
+
+// Checking that fun2string(members) does not display anything.
+// If it did, then it would mean that members() has been called.
+fun2string(members);