summaryrefslogtreecommitdiffstats
path: root/scilab/modules/core
diff options
context:
space:
mode:
authorAllan CORNET <allan.cornet@scilab.org>2010-03-31 09:37:53 +0200
committerAllan CORNET <allan.cornet@scilab.org>2010-03-31 09:37:53 +0200
commit48f63d2816df00c1f94995e9062a0cc57b959812 (patch)
treebd2987c62600fd681fb98b3f858dc5a252b766b9 /scilab/modules/core
parent4a24d82343e0d2678980a070534cc9a85f16ebc8 (diff)
downloadscilab-48f63d2816df00c1f94995e9062a0cc57b959812.zip
scilab-48f63d2816df00c1f94995e9062a0cc57b959812.tar.gz
bug_6830
Diffstat (limited to 'scilab/modules/core')
-rw-r--r--scilab/modules/core/includes/stack2.h1
-rw-r--r--scilab/modules/core/src/c/stack2.c128
-rw-r--r--scilab/modules/core/tests/nonreg_tests/bug_6830.c81
-rw-r--r--scilab/modules/core/tests/nonreg_tests/bug_6830.dia.ref66
-rw-r--r--scilab/modules/core/tests/nonreg_tests/bug_6830.tst49
5 files changed, 267 insertions, 58 deletions
diff --git a/scilab/modules/core/includes/stack2.h b/scilab/modules/core/includes/stack2.h
index f001ab7..ee95562 100644
--- a/scilab/modules/core/includes/stack2.h
+++ b/scilab/modules/core/includes/stack2.h
@@ -220,7 +220,6 @@ int C2F(in2str)(int *n, int *line, char *str, unsigned long str_len);
220int C2F(callscifun)(char *string, unsigned long string_len); 220int C2F(callscifun)(char *string, unsigned long string_len);
221int C2F(scifunction)(int *number, int *ptr, int *mlhs, int *mrhs); 221int C2F(scifunction)(int *number, int *ptr, int *mlhs, int *mrhs);
222int C2F(scistring)(int *ifirst, char *thestring, int *mlhs, int *mrhs, unsigned long thestring_len); 222int C2F(scistring)(int *ifirst, char *thestring, int *mlhs, int *mrhs, unsigned long thestring_len);
223int C2F(getopcode)(char *string, unsigned long string_len);
224int C2F(scibuiltin)(int *number, int *ifun, int *ifin, int *mlhs, int *mrhs); 223int C2F(scibuiltin)(int *number, int *ifun, int *ifin, int *mlhs, int *mrhs);
225int C2F(sciops)(int *number, int *op, int *mlhs, int *mrhs); 224int C2F(sciops)(int *number, int *op, int *mlhs, int *mrhs);
226int C2F(getrhssys)(int *lw, int *n, int *m, int *p, int *ptra, int *ptrb, int *ptrc, int *ptrd, int *ptrx0, double *h__); 225int C2F(getrhssys)(int *lw, int *n, int *m, int *p, int *ptra, int *ptrb, int *ptrc, int *ptrd, int *ptrx0, double *h__);
diff --git a/scilab/modules/core/src/c/stack2.c b/scilab/modules/core/src/c/stack2.c
index f0ddc17..3977438 100644
--- a/scilab/modules/core/src/c/stack2.c
+++ b/scilab/modules/core/src/c/stack2.c
@@ -67,7 +67,7 @@ void strcpy_tws(char *str1,char *str2, int len);
67int C2F(copyvarfromsciptr)(int lw, int n,int l); 67int C2F(copyvarfromsciptr)(int lw, int n,int l);
68static int intersci_push(void); 68static int intersci_push(void);
69static void intersci_pop(void); 69static void intersci_pop(void);
70 70static int C2F(getopcode)(char *string, unsigned long string_len);
71 71
72static void ConvertData(unsigned char *type, int size,int l); 72static void ConvertData(unsigned char *type, int size,int l);
73/*------------------------------------------------ 73/*------------------------------------------------
@@ -2084,67 +2084,81 @@ int C2F(scifunction)(int *number,int *ptr,int *mlhs,int *mrhs)
2084 2084
2085int C2F(scistring)(int *ifirst,char *thestring,int *mlhs,int *mrhs,unsigned long thestring_len) 2085int C2F(scistring)(int *ifirst,char *thestring,int *mlhs,int *mrhs,unsigned long thestring_len)
2086{ 2086{
2087 int ret = FALSE; 2087 int ret = FALSE;
2088 int ifin, ifun, tops, moutputs, id[nsiz], lf, op, ile, ils, nnn, ninputs; 2088 int ifin = 0, ifun = 0, tops = 0, moutputs = 0;
2089 nnn = thestring_len; 2089 int id[nsiz];
2090 op = 0; 2090 int lf = 0, op = 0, ile = 0, ils = 0, nnn = thestring_len, ninputs = 0;
2091 if (nnn <= 2) { 2091
2092 op = C2F(getopcode)(thestring, thestring_len); 2092 if (nnn <= 2)
2093 }
2094 if (op == 0) {
2095 C2F(cvname)(id, thestring, &cx0, nnn);
2096 Fin = 0;
2097 tops = Top;
2098 Top = Top - Rhs + *ifirst + *mrhs - 1;
2099 C2F(funs)(id);
2100 Top = tops;
2101 if (Fin == 0)
2102 { 2093 {
2103 Scierror(999,_("%s: %s is not a Scilab function.\n"),"scistring",get_fname(thestring,thestring_len)); 2094 op = C2F(getopcode)(thestring, thestring_len);
2104 return ret; 2095 }
2105 } 2096
2106 if (C2F(com).fun <= 0) { 2097 if (op == 0)
2107 lf = *Lstk(Fin); 2098 {
2108 ils = iadr(lf) + 1; 2099 C2F(cvname)(id, thestring, &cx0, nnn);
2109 moutputs = *istk(ils); 2100 Fin = 0;
2110 ile = ils + moutputs * nsiz + 1; 2101 tops = Top;
2111 ninputs = *istk(ile); 2102 Top = Top - Rhs + *ifirst + *mrhs - 1;
2112 /* 2103 C2F(funs)(id);
2113 * ninputs=actual number of inputs, moutputs=actual number of outputs 2104 Top = tops;
2114 * of thestring: checking mlhs=ninputs and mrhs=moutputs not done. 2105
2115 */ 2106 if (Fin == 0)
2116 ret = C2F(scifunction)(ifirst, &lf, mlhs, mrhs); 2107 {
2117 } else { 2108 Scierror(999,_("%s: %s is not a Scilab function.\n"),"scistring",get_fname(thestring,thestring_len));
2118 ifin = Fin; 2109 return ret;
2119 ifun = C2F(com).fun; 2110 }
2120 ret = C2F(scibuiltin)(ifirst, &ifun, &ifin, mlhs, mrhs); 2111
2121 } 2112 if (C2F(com).fun <= 0)
2122 } else { 2113 {
2123 ret = C2F(sciops)(ifirst, &op, mlhs, mrhs); 2114 lf = *Lstk(Fin);
2124 } 2115 ils = iadr(lf) + 1;
2125 return ret; 2116 moutputs = *istk(ils);
2117 ile = ils + moutputs * nsiz + 1;
2118 ninputs = *istk(ile);
2119 /*
2120 * ninputs=actual number of inputs, moutputs=actual number of outputs
2121 * of thestring: checking mlhs=ninputs and mrhs=moutputs not done.
2122 */
2123 ret = C2F(scifunction)(ifirst, &lf, mlhs, mrhs);
2124 }
2125 else
2126 {
2127 ifin = Fin;
2128 ifun = C2F(com).fun;
2129 ret = C2F(scibuiltin)(ifirst, &ifun, &ifin, mlhs, mrhs);
2130 }
2131 }
2132 else
2133 {
2134 ret = C2F(sciops)(ifirst, &op, mlhs, mrhs);
2135 }
2136 return ret;
2126} 2137}
2127 2138
2128int C2F(getopcode)(char *string,unsigned long string_len) 2139int C2F(getopcode)(char *string,unsigned long string_len)
2129{ 2140{
2130 unsigned char ch = string[0]; 2141 unsigned char ch = string[0];
2131 int op = 0; 2142 int op = 0;
2132 if ( string_len >= 2) { 2143 if ( string_len >= 2)
2133 /* .op or op. */ 2144 {
2134 if ( ch == '.') ch = string[1]; 2145 /* .op or op. */
2135 op += 51; 2146 if ( ch == '.') ch = string[1];
2136 } 2147 op += 51;
2137 switch ( ch ) 2148 }
2138 { 2149
2139 case '*' : op += 47; break; 2150 switch ( ch )
2140 case '+' : op += 45; break; 2151 {
2141 case '-' : op += 46; break; 2152 case '*' : op += 47; break;
2142 case '\'' : op += 53; break; 2153 case '+' : op += 45; break;
2143 case '/' : op += 48; break; 2154 case '-' : op += 46; break;
2144 case '\\' : op += 49; break; 2155 case '\'' : op += 53; break;
2145 case '^' : op += 62; break; 2156 case '/' : op += 48; break;
2146 } 2157 case '\\' : op += 49; break;
2147 return op; 2158 case '^' : op += 62; break;
2159 default : op = 0; break;
2160 }
2161 return op;
2148} 2162}
2149 2163
2150/*--------------------------------------------------------------------- 2164/*---------------------------------------------------------------------
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_6830.c b/scilab/modules/core/tests/nonreg_tests/bug_6830.c
new file mode 100644
index 0000000..4e43893
--- /dev/null
+++ b/scilab/modules/core/tests/nonreg_tests/bug_6830.c
@@ -0,0 +1,81 @@
1//-------------------------------------------------------------------------------------
2/*
3 * Scilab ( http://www.scilab.org/ )
4 * Copyright (C) DIGITEO - Allan CORNET - 2009
5 *
6 * This file is released into the public domain
7 */
8#include "stack-c.h"
9#include "Scierror.h"
10#include "localization.h"
11//-------------------------------------------------------------------------------------
12static int PutOneValueOnStack(double v);
13//-------------------------------------------------------------------------------------
14int sci_callscistring(char *fname)
15{
16 int m1 = 0, n1 = 0, l1 = 0;
17 double v1 = 0.;
18
19 int one = 1, l = 0;
20
21 int rm1 = 0, rn1 = 0, rl1 = 0;
22 double r = 0.;
23
24 int positionFirstElementOnStackForScilabFunction = 0;
25 int numberOfRhsOnScilabFunction = 0;
26 int numberOfLhsOnScilabFunction = 0;
27 int pointerOnScilabFunction = 0;
28 char *name = NULL;
29
30 CheckRhs(1,1);
31 //CheckLhs(1,1);
32
33 if (GetType(1) != sci_strings)
34 {
35 Scierror(999,_("%s: Wrong type for input argument #%d: A scilab function expected.\n"),fname,1);
36 return 0;
37 }
38
39 GetRhsVar(1,STRING_DATATYPE, &m1, &n1, &l1);
40 name = cstk(l1);
41
42
43 // creates a variable (double) on stack @ Rhs + 1
44 CreateVar(Rhs + 1 , MATRIX_OF_DOUBLE_DATATYPE, &one, &one,&l);
45 *stk(l) = 3.0;
46
47 // creates a variable (double) on stack @ Rhs + 2
48 CreateVar(Rhs + 2 , MATRIX_OF_DOUBLE_DATATYPE, &one, &one,&l);
49 *stk(l) = 2.0;
50
51 positionFirstElementOnStackForScilabFunction = Rhs + 1 ;
52
53 numberOfRhsOnScilabFunction = 2;
54
55 numberOfLhsOnScilabFunction = 1;
56
57
58 C2F(scistring)(&positionFirstElementOnStackForScilabFunction, name,
59 &numberOfLhsOnScilabFunction, &numberOfRhsOnScilabFunction,
60 (unsigned long) strlen(name) );
61
62 // result r is now on first position on stack
63 GetRhsVar(Rhs + 1 , MATRIX_OF_DOUBLE_DATATYPE, &rm1, &rn1, &rl1);
64 r = *stk(rl1);
65 printf("r = %d\n",r);
66 PutOneValueOnStack(r);
67
68 return 0;
69}
70//-------------------------------------------------------------------------------------
71static int PutOneValueOnStack(double v)
72{
73 int m = 1,n = 1, l = 0;
74
75 CreateVar( Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &m, &n, &l );
76 *stk(l) = v;
77 LhsVar(1) = Rhs + 1;
78 C2F(putlhsvar)();
79 return 0;
80}
81//-------------------------------------------------------------------------------------
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_6830.dia.ref b/scilab/modules/core/tests/nonreg_tests/bug_6830.dia.ref
new file mode 100644
index 0000000..9819a12
--- /dev/null
+++ b/scilab/modules/core/tests/nonreg_tests/bug_6830.dia.ref
@@ -0,0 +1,66 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Allan CORNET
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// <-- Non-regression test for bug 6830 -->
8//
9// <-- Bugzilla URL -->
10// http://bugzilla.scilab.org/show_bug.cgi?id=6830
11//
12// <-- Short Description -->
13// C2F(scistring) in stack2.c was broken for macro names of exactly 2 characters.
14cd(TMPDIR);
15mkdir('bug_6830');
16cd('bug_6830');
17copyfile(SCI+'/modules/core/tests/nonreg_tests/bug_6830.c',TMPDIR + '/bug_6830/bug_6830.c');
18files=['bug_6830.c'];
19ilib_verbose(0);
20ilib_build('bug6830',['callscistring','sci_callscistring'],files,[]);
21function r = scilabfoo(x,y)
22 disp("x =");
23 disp(x);
24 disp("y =");
25 disp(y);
26 r = x + y;
27 disp("r =");
28 disp(r);
29endfunction
30ierr = execstr("callscistring(''scilabfoo'')","errcatch");
31
32 x =
33
34 3.
35
36 y =
37
38 2.
39
40 r =
41
42 5.
43if ierr <> 0 then bugmes();quit;end
44function r = fo(x,y)
45 disp("x =");
46 disp(x);
47 disp("y =");
48 disp(y);
49 r = x + y;
50 disp("r =");
51 disp(r);
52endfunction
53ierr = execstr("callscistring(''fo'')","errcatch");
54
55 x =
56
57 3.
58
59 y =
60
61 2.
62
63 r =
64
65 5.
66if ierr <> 0 then bugmes();quit;end
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_6830.tst b/scilab/modules/core/tests/nonreg_tests/bug_6830.tst
new file mode 100644
index 0000000..9866da61
--- /dev/null
+++ b/scilab/modules/core/tests/nonreg_tests/bug_6830.tst
@@ -0,0 +1,49 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Allan CORNET
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7
8// <-- Non-regression test for bug 6830 -->
9//
10// <-- Bugzilla URL -->
11// http://bugzilla.scilab.org/show_bug.cgi?id=6830
12//
13// <-- Short Description -->
14// C2F(scistring) in stack2.c was broken for macro names of exactly 2 characters.
15
16cd(TMPDIR);
17mkdir('bug_6830');
18cd('bug_6830');
19copyfile(SCI+'/modules/core/tests/nonreg_tests/bug_6830.c',TMPDIR + '/bug_6830/bug_6830.c');
20files=['bug_6830.c'];
21ilib_verbose(0);
22ilib_build('bug6830',['callscistring','sci_callscistring'],files,[]);
23exec('loader.sce');
24
25function r = scilabfoo(x,y)
26 disp("x =");
27 disp(x);
28 disp("y =");
29 disp(y);
30 r = x + y;
31 disp("r =");
32 disp(r);
33endfunction
34
35ierr = execstr("callscistring(''scilabfoo'')","errcatch");
36if ierr <> 0 then pause,end
37
38function r = fo(x,y)
39 disp("x =");
40 disp(x);
41 disp("y =");
42 disp(y);
43 r = x + y;
44 disp("r =");
45 disp(r);
46endfunction
47
48ierr = execstr("callscistring(''fo'')","errcatch");
49if ierr <> 0 then pause,end \ No newline at end of file