From 4218be3d957499c912b7aebef33f34cca860457e Mon Sep 17 00:00:00 2001 From: Samuel GOUGEON Date: Fri, 22 May 2020 20:29:02 +0200 Subject: [PATCH] * Bug 16358 fixed: isdef([],..) yielded an error http://bugzilla.scilab.org/16358 Change-Id: I2b5f5dadab9b8d3b9fb7376afd5dad63bc4dd511 --- scilab/CHANGES.md | 1 + scilab/modules/core/sci_gateway/cpp/sci_exists.cpp | 26 +++++--- .../modules/core/tests/nonreg_tests/bug_16358.tst | 22 +++++++ .../modules/core/tests/unit_tests/exists.dia.ref | 67 -------------------- scilab/modules/core/tests/unit_tests/exists.tst | 10 ++- 5 files changed, 49 insertions(+), 77 deletions(-) create mode 100644 scilab/modules/core/tests/nonreg_tests/bug_16358.tst delete mode 100644 scilab/modules/core/tests/unit_tests/exists.dia.ref diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index 6974a44..6742f75 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -279,6 +279,7 @@ Bug Fixes * [#16337](https://bugzilla.scilab.org/16337): The 3rd output of `[U,km,ku] = unique(..)` was not implemented. * [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2. * [#16350](https://bugzilla.scilab.org/16350): in if/while conditions, the empty sparse boolean was considered as TRUE. +* [#16358](https://bugzilla.scilab.org/16358): `isdef([],..)` yielded an error instead of returning []. * [#16365](https://bugzilla.scilab.org/16365): `median(m,"r")` and `median(m,"c")` yielded wrong results (6.1.0 regression) * [#16366](https://bugzilla.scilab.org/16366): `plot([0 1], ":")` plotted a dash-dotted curve instead of a dotted one. * [#16369](https://bugzilla.scilab.org/16369): Right divisions / involving one or two sparse numerical matrices were no longer supported. diff --git a/scilab/modules/core/sci_gateway/cpp/sci_exists.cpp b/scilab/modules/core/sci_gateway/cpp/sci_exists.cpp index 59a5db6..006ba4c 100644 --- a/scilab/modules/core/sci_gateway/cpp/sci_exists.cpp +++ b/scilab/modules/core/sci_gateway/cpp/sci_exists.cpp @@ -63,6 +63,12 @@ static types::Function::ReturnValue isdef(types::typed_list& in, int _iRetCount, return types::Function::Error; } + if (in[0]->isDouble() && in[0]->getAs()->isEmpty()) + { + out.push_back(types::Double::Empty()); + return types::Function::OK; + } + if (!in[0]->isString()) { Scierror(999, _("%s: Wrong type for argument #%d: Matrix of strings expected.\n"), fname, 1); @@ -130,17 +136,19 @@ types::Function::ReturnValue sci_exists(types::typed_list &in, int _iRetCount, t if (retVal == types::Function::OK) { - types::Bool* pBOut = out[0]->getAs(); - types::Double* pDblOut = new types::Double(pBOut->getDims(), pBOut->getDimsArray()); - for (int i = 0; i < pBOut->getSize(); i++) + if (out[0]->isDouble() == false) { - pDblOut->set(i, (double)pBOut->get(i)); - } + types::Bool* pBOut = out[0]->getAs(); + types::Double* pDblOut = new types::Double(pBOut->getDims(), pBOut->getDimsArray()); + for (int i = 0; i < pBOut->getSize(); i++) + { + pDblOut->set(i, (double)pBOut->get(i)); + } + pBOut->killMe(); + out.pop_back(); - pBOut->killMe(); - out.pop_back(); - out.push_back(pDblOut); + out.push_back(pDblOut); + } } - return retVal; } diff --git a/scilab/modules/core/tests/nonreg_tests/bug_16358.tst b/scilab/modules/core/tests/nonreg_tests/bug_16358.tst new file mode 100644 index 0000000..a91a862 --- /dev/null +++ b/scilab/modules/core/tests/nonreg_tests/bug_16358.tst @@ -0,0 +1,22 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2020 - Samuel GOUGEON +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- Non-regression test for bug 16358 --> +// +// <-- CLI SHELL MODE --> +// <-- NO CHECK REF --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/16358 +// +// <-- Short Description --> +// isdef([],..) yielded an error instead of returning [] + +assert_checkequal(isdef([]), []); +assert_checkequal(isdef([],"a"), []); +assert_checkequal(isdef([],"l"), []); +assert_checkequal(isdef([],"n"), []); diff --git a/scilab/modules/core/tests/unit_tests/exists.dia.ref b/scilab/modules/core/tests/unit_tests/exists.dia.ref deleted file mode 100644 index 3d02d4f..0000000 --- a/scilab/modules/core/tests/unit_tests/exists.dia.ref +++ /dev/null @@ -1,67 +0,0 @@ -//<-- CLI SHELL MODE --> -// ============================================================================= -// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab -// Copyright (C) 2008 - INRIA -// Copyright (C) 2010 - DIGITEO - Bruno JOFRET -// -// This file is distributed under the same license as the Scilab package. -// ============================================================================= -//exists -a=1; -assert_checkequal(exists('a'), 1); -clear a; -assert_checkequal(exists('a'), 0); -a=1; b=1; -assert_checkequal(exists(['a', 'b']), [1, 1]); -assert_checkequal(exists(['a'; 'b']), [1; 1]); -assert_checkequal(exists(['a', 'b'; 'a', 'b']), [1, 1; 1, 1]); -clear b; -assert_checkequal(exists(['a', 'b']), [1, 0]); -assert_checkequal(exists(['a'; 'b']), [1; 0]); -assert_checkequal(exists(['b', 'a']), [0, 1]); -assert_checkequal(exists(['b'; 'a']), [0; 1]); -assert_checkequal(exists(['a', 'b'; 'a', 'b']), [1, 0; 1, 0]); -clear a; -assert_checkequal(exists(['a', 'b']), [0, 0]); -assert_checkequal(exists(['a'; 'b']), [0; 0]); -assert_checkequal(exists(['a', 'b'; 'a', 'b']), [0, 0; 0, 0]); -function __check_exists__(x, scope) - assert_checkequal(exists("a", scope), 1); -endfunction -function __check_exists2__(x, scope) - a=42; b=42; - assert_checkequal(exists(['a', 'b'], scope), [1, 1]); - assert_checkequal(exists(['a'; 'b'], scope), [1; 1]); - assert_checkequal(exists(['a', 'b'; 'a' 'b'], scope), [1, 1; 1, 1]); -endfunction -function __check_not_exists__(x, scope) - assert_checkequal(exists("a", scope), 0); -endfunction -function __check_not_exists2__(x, scope) - a=51; b=51; - assert_checkequal(exists(['a', 'b'], scope), [0, 0]); - assert_checkequal(exists(['a'; 'b'], scope), [0; 0]); - assert_checkequal(exists(['a', 'b'; 'a', 'b'], scope), [0, 0; 0, 0]); -endfunction -// Define a ONLY in calling scope -a = 42; b=42; -__check_exists__([], "all"); -__check_exists__([], "nolocal"); -__check_not_exists__([], "local"); -clear a; clear b; -// Define a ONLY in function local scope -__check_exists__(a = 42, "all"); -__check_exists__(a = 42, "local"); -__check_not_exists__(a = 42, "nolocal"); -__check_exists2__([], "all"); -__check_exists2__([], "local"); -__check_not_exists2__([], "nolocal"); -// Define a BOTH in calling and local scope -a = 42; b=42; -__check_exists__(a = 51, "all"); -__check_exists__(a = 51, "local"); -__check_exists__(a = 51, "nolocal"); -__check_exists2__([], "all"); -__check_exists2__([], "local"); -__check_exists2__([], "nolocal"); -clear a; clear b; diff --git a/scilab/modules/core/tests/unit_tests/exists.tst b/scilab/modules/core/tests/unit_tests/exists.tst index dfc2414..7b2271f 100644 --- a/scilab/modules/core/tests/unit_tests/exists.tst +++ b/scilab/modules/core/tests/unit_tests/exists.tst @@ -1,4 +1,3 @@ -//<-- CLI SHELL MODE --> // ============================================================================= // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab // Copyright (C) 2008 - INRIA @@ -7,8 +6,17 @@ // This file is distributed under the same license as the Scilab package. // ============================================================================= +// <-- CLI SHELL MODE --> +// <-- NO CHECK REF --> + //exists +// [] +assert_checkequal(exists([]),[]); +assert_checkequal(exists([],"a"), []); +assert_checkequal(exists([],"l"), []); +assert_checkequal(exists([],"n"), []); + a=1; assert_checkequal(exists('a'), 1); clear a; -- 1.7.9.5