summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authorCedric Delamarre <cdl@esi-group.com>2020-10-22 14:23:14 +0200
committerClément DAVID <clement.david@esi-group.com>2020-12-14 15:41:40 +0100
commitdd78cec6dd8f56a54566b26bc2857957451d5b8b (patch)
tree87ab4a77b46d96b1442bd8b783f7350c15a82b37 /scilab
parenteb815e807bf62218d690ddc0caaaaf7dc00d6e97 (diff)
downloadscilab-dd78cec6dd8f56a54566b26bc2857957451d5b8b.zip
scilab-dd78cec6dd8f56a54566b26bc2857957451d5b8b.tar.gz
extraction on implicit list fixed.
https://bugzilla.scilab.org/show_bug.cgi?id=16141 https://bugzilla.scilab.org/show_bug.cgi?id=16396 test_run("ast", ["bug_16396" "bug_16141" "extract"]) Change-Id: I2c63e1c27f93727dba4eeb24a625ee384a91a44d
Diffstat (limited to 'scilab')
-rw-r--r--scilab/CHANGES.md2
-rw-r--r--scilab/modules/ast/includes/types/implicitlist.hxx2
-rw-r--r--scilab/modules/ast/src/cpp/types/arrayof.cpp4
-rw-r--r--scilab/modules/ast/src/cpp/types/implicitlist.cpp148
-rw-r--r--scilab/modules/ast/src/cpp/types/types_tools.cpp20
-rw-r--r--scilab/modules/ast/tests/nonreg_tests/bug_16141.tst20
-rw-r--r--scilab/modules/ast/tests/nonreg_tests/bug_16396.tst24
-rw-r--r--scilab/modules/ast/tests/unit_tests/extract.tst54
8 files changed, 229 insertions, 45 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index 34e4bd7..c62a8d8 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -300,6 +300,7 @@ Bug Fixes
300* [#16069](https://bugzilla.scilab.org/16069): [].figure_name crashes Scilab. 300* [#16069](https://bugzilla.scilab.org/16069): [].figure_name crashes Scilab.
301* [#16106](https://bugzilla.scilab.org/16106): Xcos sciblk4 user-defined blocks did not handle opar and odstate/oz correctly. 301* [#16106](https://bugzilla.scilab.org/16106): Xcos sciblk4 user-defined blocks did not handle opar and odstate/oz correctly.
302* [#16122](https://bugzilla.scilab.org/16122): concat polynomials with <> var did not raise an error. 302* [#16122](https://bugzilla.scilab.org/16122): concat polynomials with <> var did not raise an error.
303* [#16141](https://bugzilla.scilab.org/16141): recursive extraction `(m:n)($)` crashed Scilab
303* [#16151](https://bugzilla.scilab.org/16151): `isequal(1:$, 2:$)` returned `%T`. 304* [#16151](https://bugzilla.scilab.org/16151): `isequal(1:$, 2:$)` returned `%T`.
304* [#16193](https://bugzilla.scilab.org/16193): `covStart()` clear previous coverage information. `profileEnable()` could be use to append a macro later on. 305* [#16193](https://bugzilla.scilab.org/16193): `covStart()` clear previous coverage information. `profileEnable()` could be use to append a macro later on.
305* [#16196](https://bugzilla.scilab.org/16196): `covStart()` help page was incomplete about the API usage. 306* [#16196](https://bugzilla.scilab.org/16196): `covStart()` help page was incomplete about the API usage.
@@ -316,6 +317,7 @@ Bug Fixes
316* [#16370](https://bugzilla.scilab.org/16370): `msprintf()` did not handle LaTeX dollars anymore. 317* [#16370](https://bugzilla.scilab.org/16370): `msprintf()` did not handle LaTeX dollars anymore.
317* [#16374](https://bugzilla.scilab.org/16374): Any plot with datatips saved in Scilab 5.5 could not be loaded in Scilab 6. 318* [#16374](https://bugzilla.scilab.org/16374): Any plot with datatips saved in Scilab 5.5 could not be loaded in Scilab 6.
318* [#16391](https://bugzilla.scilab.org/16391): `csvRead()` was crashing with CSV files containing empty lines. 319* [#16391](https://bugzilla.scilab.org/16391): `csvRead()` was crashing with CSV files containing empty lines.
320* [#16396](https://bugzilla.scilab.org/16396): recursive extraction `(m:n)(:)` crashed Scilab
319* [#16397](https://bugzilla.scilab.org/16397): display of long (real) column vectors was slow (regression). 321* [#16397](https://bugzilla.scilab.org/16397): display of long (real) column vectors was slow (regression).
320* [#16399](https://bugzilla.scilab.org/16399): `mtlb_zeros([])` was crashing Scilab. 322* [#16399](https://bugzilla.scilab.org/16399): `mtlb_zeros([])` was crashing Scilab.
321* [#16401](https://bugzilla.scilab.org/16401): global `external_object_java` class was crashing Scilab. 323* [#16401](https://bugzilla.scilab.org/16401): global `external_object_java` class was crashing Scilab.
diff --git a/scilab/modules/ast/includes/types/implicitlist.hxx b/scilab/modules/ast/includes/types/implicitlist.hxx
index 5f2c0f1..69f77d06 100644
--- a/scilab/modules/ast/includes/types/implicitlist.hxx
+++ b/scilab/modules/ast/includes/types/implicitlist.hxx
@@ -124,7 +124,7 @@ public :
124 } 124 }
125 125
126 //extract single value in a InternalType 126 //extract single value in a InternalType
127 void extractValue(int _iOccur, InternalType*); //Single value 127 bool extractValue(int _iOccur, InternalType*); //Single value
128 void extractValueAsDouble(int _iOccur, Double*); 128 void extractValueAsDouble(int _iOccur, Double*);
129 template<typename T> 129 template<typename T>
130 void extractValueAsInteger(int _iOccur, T* val); 130 void extractValueAsInteger(int _iOccur, T* val);
diff --git a/scilab/modules/ast/src/cpp/types/arrayof.cpp b/scilab/modules/ast/src/cpp/types/arrayof.cpp
index 24d0474..7df4a81 100644
--- a/scilab/modules/ast/src/cpp/types/arrayof.cpp
+++ b/scilab/modules/ast/src/cpp/types/arrayof.cpp
@@ -1413,6 +1413,10 @@ GenericType* ArrayOf<T>::extract(typed_list* _pArgs)
1413 1413
1414 //free pArg content 1414 //free pArg content
1415 cleanIndexesArguments(_pArgs, &pArg); 1415 cleanIndexesArguments(_pArgs, &pArg);
1416 if(pOut)
1417 {
1418 pOut->killMe();
1419 }
1416 return NULL; 1420 return NULL;
1417 } 1421 }
1418 } 1422 }
diff --git a/scilab/modules/ast/src/cpp/types/implicitlist.cpp b/scilab/modules/ast/src/cpp/types/implicitlist.cpp
index 42ca980..b1f74a0 100644
--- a/scilab/modules/ast/src/cpp/types/implicitlist.cpp
+++ b/scilab/modules/ast/src/cpp/types/implicitlist.cpp
@@ -467,14 +467,9 @@ InternalType* ImplicitList::getInitalType()
467} 467}
468 468
469//extract single value in a InternalType 469//extract single value in a InternalType
470void ImplicitList::extractValue(int _iOccur, InternalType* pIT) 470bool ImplicitList::extractValue(int _iOccur, InternalType* pIT)
471{ 471{
472 if (pIT == nullptr) 472 if (pIT && compute() && m_iSize >= _iOccur)
473 {
474 return;
475 }
476
477 if (compute())
478 { 473 {
479 switch (m_eOutType) 474 switch (m_eOutType)
480 { 475 {
@@ -506,7 +501,10 @@ void ImplicitList::extractValue(int _iOccur, InternalType* pIT)
506 extractValueAsDouble(_iOccur, pIT->getAs<Double>()); 501 extractValueAsDouble(_iOccur, pIT->getAs<Double>());
507 break; 502 break;
508 } 503 }
504 return true;
509 } 505 }
506
507 return false;
510} 508}
511 509
512//extract matrix in a Internaltype 510//extract matrix in a Internaltype
@@ -652,7 +650,6 @@ InternalType* ImplicitList::extract(typed_list* _pArgs)
652 int iDims = (int)_pArgs->size(); 650 int iDims = (int)_pArgs->size();
653 typed_list pArg; 651 typed_list pArg;
654 InternalType* pOut = NULL; 652 InternalType* pOut = NULL;
655 int index = 0;
656 653
657 int* piMaxDim = new int[iDims]; 654 int* piMaxDim = new int[iDims];
658 int* piCountDim = new int[iDims]; 655 int* piCountDim = new int[iDims];
@@ -663,59 +660,126 @@ InternalType* ImplicitList::extract(typed_list* _pArgs)
663 { 660 {
664 //free pArg content 661 //free pArg content
665 cleanIndexesArguments(_pArgs, &pArg); 662 cleanIndexesArguments(_pArgs, &pArg);
663 delete[] piMaxDim;
664 delete[] piCountDim;
666 return createEmptyDouble(); 665 return createEmptyDouble();
667 } 666 }
668 667
669 if (iDims == 1 && iSeqCount == 1) 668 // computable
669 if(compute())
670 { 670 {
671 if (piMaxDim[0] > 0 && piMaxDim[0] <= 3) 671 if(iSeqCount == 1 && iDims == 1) // (0:9)(5)
672 { 672 {
673 //standard case a(1) 673 int index = (int)pArg[0]->getAs<Double>()->get()[0] - 1;
674 Double* pDbl = pArg[0]->getAs<Double>(); 674 if(index < m_iSize)
675 index = (int)pDbl->get()[0] - 1; 675 {
676 pOut = getInitalType();
677 if(extractValue(index, pOut) == false)
678 {
679 pOut->killMe();
680 pOut = NULL;
681 }
682 }
676 } 683 }
677 else 684 else
678 { 685 {
679 index = 0; 686 // for more complex argument, expand the implicit list
687 // to perform the extraction on a more common type.
688 InternalType* pIT = extractFullMatrix();
689 pOut = pIT->getAs<GenericType>()->extract(_pArgs);
690 pIT->killMe();
680 } 691 }
681 } 692 }
682 else 693 else if((piMaxDim[0] > 0 && piMaxDim[0] <= 3) && iSeqCount != -1)
683 { 694 {
684 int* piDims = new int[iDims]; 695 // check dims indexes other than the first one
685 int* pIndex = new int[iDims]; 696 // (1:$)(2,1) works but not (1:$)(1,2)
686 for (int i = 0 ; i < iDims ; i++) 697 bool bOk = true;
698 for(int i = 1; i < iDims; i++)
687 { 699 {
688 piDims[i] = 1; 700 if(pArg[i]->getAs<Double>()->get(0) != 1)
701 {
702 bOk = false;
703 break;
704 }
689 } 705 }
690 706
691 for (int i = 0 ; i < iSeqCount ; i++) 707 if(bOk)
692 { 708 {
693 for (int j = 0 ; j < iDims ; j++) 709 std::vector<int> indexes;
710 indexes.reserve(iSeqCount);
711 bool isOutPoly = false;
712 double* pDbl = pArg[0]->getAs<Double>()->get();
713 for (int i = 0 ; i < iSeqCount ; i++)
694 { 714 {
695 Double* pDbl = pArg[j]->getAs<Double>(); 715 indexes.push_back((int)pDbl[i] - 1);
696 pIndex[j] = (int)pDbl->get()[i] - 1;
697 } 716 }
698 717
699 index = getIndexWithDims(pIndex, piDims, iDims); 718 std::vector<InternalType*> vect;
719 for (int i = 0 ; i < iSeqCount ; i++)
720 {
721 switch (indexes[i])
722 {
723 case 0 : // start
724 vect.push_back(getStart());
725 // pPoly->set(i, start);
726 break;
727 case 1 : // step
728 vect.push_back(getStep());
729 break;
730 case 2 : // end
731 vect.push_back(getEnd());
732 break;
733 default :
734 vect.clear();
735 break;
736 }
737 }
738
739 Polynom* pPoly = nullptr;
740 for(auto elem : vect)
741 {
742 if(elem->isPoly())
743 {
744 // (0:$)(:) vs (0:$)(1:$)
745 int iRows = (*_pArgs)[0]->isColon() ? iSeqCount : 1;
746 int iCols = (*_pArgs)[0]->isColon() ? 1 : iSeqCount;
747 pPoly = new Polynom(L"$", iRows, iCols);
748 break;
749 }
750 }
751
752 if(pPoly)
753 {
754 for (int i = 0 ; i < iSeqCount ; i++)
755 {
756 if(vect[i]->isPoly())
757 {
758 pPoly->set(i, vect[i]->getAs<Polynom>()->get(0));
759 }
760 else
761 {
762 double* coef = nullptr;
763 SinglePoly* singlePoly = new SinglePoly(&coef, 0);
764 coef[0] = vect[i]->getAs<Double>()->get(0);
765 pPoly->set(i, singlePoly);
766 singlePoly->killMe();
767 }
768 }
769
770 pOut = pPoly;
771 }
772 else if(vect.empty() == false)
773 {
774 Double* pDbl = new Double(1, iSeqCount);
775 for (int i = 0 ; i < iSeqCount ; i++)
776 {
777 pDbl->set(i, vect[i]->getAs<Double>()->get(0));
778 }
779
780 pOut = pDbl;
781 }
700 } 782 }
701 delete[] pIndex;
702 delete[] piDims;
703 }
704
705 switch (index)
706 {
707 case 0 :
708 pOut = getStart();
709 break;
710 case 1 :
711 pOut = getStep();
712 break;
713 case 2 :
714 pOut = getEnd();
715 break;
716 default :
717 pOut = NULL;
718 break;
719 } 783 }
720 784
721 //free pArg content 785 //free pArg content
diff --git a/scilab/modules/ast/src/cpp/types/types_tools.cpp b/scilab/modules/ast/src/cpp/types/types_tools.cpp
index 8482336..56576fc 100644
--- a/scilab/modules/ast/src/cpp/types/types_tools.cpp
+++ b/scilab/modules/ast/src/cpp/types/types_tools.cpp
@@ -574,7 +574,17 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
574 else 574 else
575 { 575 {
576 //evalute polynom with "MaxDim" 576 //evalute polynom with "MaxDim"
577 int iMaxDim = _pRef->getAs<GenericType>()->getVarMaxDim(i, iDims); 577 int iMaxDim = 0;
578 if(_pRef->isImplicitList())
579 {
580 ImplicitList* pIL = _pRef->getAs<ImplicitList>();
581 iMaxDim = pIL->compute() ? pIL->getSize() : 3;
582 }
583 else
584 {
585 iMaxDim = _pRef->getAs<GenericType>()->getVarMaxDim(i, iDims);
586 }
587
578#if defined(_SCILAB_DEBUGREF_) 588#if defined(_SCILAB_DEBUGREF_)
579 Double* pdbl = new Double(iMaxDim); 589 Double* pdbl = new Double(iMaxDim);
580#else 590#else
@@ -687,10 +697,16 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
687 Polynom* pMP = pIT->getAs<types::Polynom>(); 697 Polynom* pMP = pIT->getAs<types::Polynom>();
688 int iMaxDim = 0; 698 int iMaxDim = 0;
689 //if pRef == NULL, use 0 insteadof, to allow a($+1) on new variable 699 //if pRef == NULL, use 0 insteadof, to allow a($+1) on new variable
690 if (_pRef) 700 if (_pRef && _pRef->isGenericType())
691 { 701 {
692 iMaxDim = _pRef->getAs<GenericType>()->getVarMaxDim(i, iDims); 702 iMaxDim = _pRef->getAs<GenericType>()->getVarMaxDim(i, iDims);
693 } 703 }
704 else if(_pRef && _pRef->isImplicitList())
705 {
706 ImplicitList* pIL = _pRef->getAs<ImplicitList>();
707 // pIL is not computable, iMaxDim = 3 is the implicit list end.
708 iMaxDim = pIL->compute() ? pIL->getSize() : 3;
709 }
694 710
695#ifdef _SCILAB_DEBUGREF_ 711#ifdef _SCILAB_DEBUGREF_
696 Double* pdbl = new Double(iMaxDim); // $ 712 Double* pdbl = new Double(iMaxDim); // $
diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_16141.tst b/scilab/modules/ast/tests/nonreg_tests/bug_16141.tst
new file mode 100644
index 0000000..8ebf0dc
--- /dev/null
+++ b/scilab/modules/ast/tests/nonreg_tests/bug_16141.tst
@@ -0,0 +1,20 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2020 - Cedric Delamarre
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 16141 -->
12//
13// <-- Bugzilla URL -->
14// http://bugzilla.scilab.org/16141
15//
16// <-- Short Description -->
17// extraction on implicit list crashes Scilab
18
19assert_checkequal((3:17)($), 17);
20assert_checkequal((3:17)($-3:$), 14:17); \ No newline at end of file
diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_16396.tst b/scilab/modules/ast/tests/nonreg_tests/bug_16396.tst
new file mode 100644
index 0000000..de71b87
--- /dev/null
+++ b/scilab/modules/ast/tests/nonreg_tests/bug_16396.tst
@@ -0,0 +1,24 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2020 - Cedric Delamarre
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 16396 -->
12//
13// <-- Bugzilla URL -->
14// http://bugzilla.scilab.org/16396
15//
16// <-- Short Description -->
17// array extraction with : crash the software
18
19computed = 1:10;
20assert_checkequal(((1:10))(1), computed(1));
21assert_checkequal(((1:10))(1:10), computed);
22assert_checkequal(((1:10)')(1:10), computed');
23assert_checkequal(((1:10))(:), computed');
24assert_checkequal((1:10)(:), computed'); \ No newline at end of file
diff --git a/scilab/modules/ast/tests/unit_tests/extract.tst b/scilab/modules/ast/tests/unit_tests/extract.tst
new file mode 100644
index 0000000..8574e77
--- /dev/null
+++ b/scilab/modules/ast/tests/unit_tests/extract.tst
@@ -0,0 +1,54 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) 2020 - ESI Group - Cedric Delamarre
3//
4// This file is hereby licensed under the terms of the GNU GPL v2.0,
5// pursuant to article 5.3.4 of the CeCILL v.2.1.
6// This file was originally licensed under the terms of the CeCILL v2.1,
7// and continues to be available under such terms.
8// For more information, see the COPYING file which you should have received
9// along with this program.
10//
11// <-- CLI SHELL MODE -->
12// <-- NO CHECK REF -->
13//
14
15//---------------------------//
16// Implicit list extraction //
17//---------------------------//
18
19invalid_index = msprintf(_("Invalid index.\n"));
20
21result = 0:9;
22assert_checkequal((0:9)(1), result(1));
23assert_checkequal((0:9)(2), result(2));
24assert_checkequal((0:9)(3), result(3));
25assert_checkequal((0:9)(4), result(4));
26assert_checkequal((0:9)($), result($));
27assert_checkerror("(0:9)($+1)", invalid_index);
28assert_checkerror("(0:9)($+1,$)", invalid_index);
29assert_checkerror("(0:9)($-1,$)", invalid_index);
30assert_checkequal((0:9)($-1), result($-1));
31assert_checkerror("(0:9)(42)", invalid_index);
32assert_checkequal((0:9)(:), result(:));
33assert_checkequal((0:9)(1:$), result(1:$));
34assert_checkequal((0:9)($:-1:1), result($:-1:1));
35assert_checkequal((0:9)([1,2,2,1]), result([1, 2, 2, 1]));
36assert_checkerror("(0:9)(1,2,2,1)", invalid_index);
37assert_checkequal((0:9)(1,1), result(1,1));
38
39assert_checkequal((0:$)(1), 0);
40assert_checkequal((0:$)(2), 1);
41assert_checkequal((0:$)(3), $);
42assert_checkerror("(0:$)(4)", invalid_index);
43assert_checkequal((0:$)($), $);
44assert_checkerror("(0:$)($+1)", invalid_index);
45assert_checkerror("(0:$)($+1,$)", invalid_index);
46assert_checkerror("(0:$)($-1,$)", invalid_index);
47assert_checkequal((0:$)($-1), 1);
48assert_checkerror("(0:$)(42)", invalid_index);
49assert_checkequal((0:$)(:), [0; 1; $]);
50assert_checkequal((0:$)(1:$), [0, 1, $]);
51assert_checkequal((0:$)($:-1:1), [$, 1, 0]);
52assert_checkequal((0:$)([1,2,2,1]), [0, 1, 1, 0]);
53assert_checkerror("(0:$)(1,2,2,1)", invalid_index);
54assert_checkequal((0:$)(1,1), 0); \ No newline at end of file