From b04f7352789b487bed0b3f19cf8ea16782d44735 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20MOTTELET?= Date: Tue, 20 Aug 2019 09:41:33 +0200 Subject: [PATCH] * Bug 16160 fixed: ppol changed values of third input variable http://bugzilla.scilab.org/show_bug.cgi?id=16160 Change-Id: Idd4443a5d3b711c4f98072123e892358dbbfb2b9 --- scilab/CHANGES.md | 2 +- scilab/modules/cacsd/sci_gateway/cpp/sci_ppol.cpp | 63 +++++++------------- .../modules/cacsd/tests/nonreg_tests/bug_16160.tst | 24 ++++++++ 3 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 scilab/modules/cacsd/tests/nonreg_tests/bug_16160.tst diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index df7149a..56953ef 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -239,6 +239,7 @@ Bug Fixes * [#16144](http://bugzilla.scilab.org/show_bug.cgi?id=16144): Addition of sparse matrices gave incorrect results. * [#16152](http://bugzilla.scilab.org/show_bug.cgi?id=16152): For sparse or boolean sparse matrix `s`, `s([])` returned `[]` instead of `sparse([])`. * [#16158](http://bugzilla.scilab.org/show_bug.cgi?id=16158): When a multicolumn array of rationals was displayed wide column per column, columns #2:$ were replaced with its column #2. +* [#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 * [#16200](http://bugzilla.scilab.org/show_bug.cgi?id=16200): Concatenation of transposed cells crashed Scilab. @@ -256,4 +257,3 @@ Bug Fixes * [#16272](http://bugzilla.scilab.org/show_bug.cgi?id=16272): `spzeros(0,n)` and `spzeros(n,0)` were different from `sparse(0,0)`. * [#16275](http://bugzilla.scilab.org/show_bug.cgi?id=16275): `fsolve(x0, fun, tol)` no longer took `tol` into account. * [#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. - diff --git a/scilab/modules/cacsd/sci_gateway/cpp/sci_ppol.cpp b/scilab/modules/cacsd/sci_gateway/cpp/sci_ppol.cpp index ad38e50..fce2cb0 100644 --- a/scilab/modules/cacsd/sci_gateway/cpp/sci_ppol.cpp +++ b/scilab/modules/cacsd/sci_gateway/cpp/sci_ppol.cpp @@ -43,8 +43,6 @@ types::Function::ReturnValue sci_ppol(types::typed_list &in, int _iRetCount, typ int iSizeP = 0; int iColB = 0; - bool isDeletable = false; - if (in.size() != 3) { Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "ppol", 3); @@ -75,7 +73,7 @@ types::Function::ReturnValue sci_ppol(types::typed_list &in, int _iRetCount, typ return types::Function::Error; } - pDblB = in[1]->clone()->getAs(); + pDblB = in[1]->getAs(); if (pDblB->isComplex()) { @@ -92,7 +90,7 @@ types::Function::ReturnValue sci_ppol(types::typed_list &in, int _iRetCount, typ return types::Function::Error; } - pDblA = in[0]->clone()->getAs(); + pDblA = in[0]->getAs(); if (pDblA->isComplex()) { @@ -119,6 +117,12 @@ types::Function::ReturnValue sci_ppol(types::typed_list &in, int _iRetCount, typ } /*** perform operations ***/ + + pDblA = pDblA->clone(); + pDblB = pDblB->clone(); + pDblP = pDblP->clone(); + pDblP->setComplex(true); + types::Double* pDblOut = new types::Double(iColB, iSizeP); double* pdblG = pDblOut->get(); @@ -129,17 +133,7 @@ types::Function::ReturnValue sci_ppol(types::typed_list &in, int _iRetCount, typ int* piW = new int[iSizeP]; double* pdblPReal = pDblP->get(); - double* pdblPImg = NULL; - if (pDblP->isComplex()) - { - pdblPImg = pDblP->getImg(); - } - else - { - pdblPImg = new double[iSizeP]; - memset(pdblPImg, 0x00, iSizeP * sizeof(double)); - isDeletable = true; - } + double* pdblPImg = pDblP->getImg(); int idc = 0; int inc = 0; @@ -154,12 +148,9 @@ types::Function::ReturnValue sci_ppol(types::typed_list &in, int _iRetCount, typ delete[] pdblZ; delete[] pdblW; delete[] piW; - if (isDeletable) - { - delete[] pdblPImg; - } - delete pDblA; - delete pDblB; + pDblA->killMe(); + pDblB->killMe(); + pDblP->killMe(); pDblOut->killMe(); return types::Function::Error; } @@ -175,34 +166,22 @@ types::Function::ReturnValue sci_ppol(types::typed_list &in, int _iRetCount, typ C2F(polmc)( &iSizeP, &iColB, &iSizeP, &iColB, pDblA->get(), pDblB->get(), pdblG, pdblPReal, pdblPImg, pdblZ, &inc, piW, &iErr, pdblW, pdblW + iColB, pdblW1, pdblW2, pdblW3, pdblW4, pdblW5); - if (iErr) - { - Scierror(999, _("%s: Uncontrollable system.\n"), "ppol"); - delete[] pdblZ; - delete[] pdblW; - delete[] piW; - if (isDeletable) - { - delete[] pdblPImg; - } - delete pDblA; - delete pDblB; - pDblOut->killMe(); - return types::Function::Error; - } - // free memory delete[] pdblZ; delete[] pdblW; delete[] piW; - if (isDeletable) + pDblA->killMe(); + pDblB->killMe(); + pDblP->killMe(); + + if (iErr) { - delete[] pdblPImg; + Scierror(999, _("%s: Uncontrollable system.\n"), "ppol"); + pDblOut->killMe(); + return types::Function::Error; } - delete pDblA; - delete pDblB; - /*** retrun output arguments ***/ + /*** return output arguments ***/ out.push_back(pDblOut); return types::Function::OK; } diff --git a/scilab/modules/cacsd/tests/nonreg_tests/bug_16160.tst b/scilab/modules/cacsd/tests/nonreg_tests/bug_16160.tst new file mode 100644 index 0000000..fbacfdd --- /dev/null +++ b/scilab/modules/cacsd/tests/nonreg_tests/bug_16160.tst @@ -0,0 +1,24 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2019 - Stéphane MOTTELET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// <-- NO CHECK REF --> +// +// <-- Non-regression test for bug 16160 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/16160 +// +// <-- Short Description --> +// ppol changes values of third input variable + + +A=rand(6,6); +B=rand(6,1); +p=[1+%i*0.5 1-%i*0.5 3 -1+%i*0.5 -1-%i*0.5 5]; +K=ppol(A,B,p); +assert_checkequal(p,[1+%i*0.5 1-%i*0.5 3 -1+%i*0.5 -1-%i*0.5 5]); \ No newline at end of file -- 1.7.9.5