summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authorClément DAVID <clement.david@esi-group.com>2020-10-05 17:45:47 +0200
committerCedric Delamarre <cedric.delamarre@esi-group.com>2021-04-26 12:06:24 +0200
commit9b4b3227fd3dda4a2de3d9b39faf7c62a42328c7 (patch)
treed3d3b2fb30351da478371876abed6c6d9db8b9d5 /scilab
parentf29166d9ca1f7a7a56047c16cc40d095bc251c0b (diff)
downloadscilab-9b4b3227fd3dda4a2de3d9b39faf7c62a42328c7.zip
scilab-9b4b3227fd3dda4a2de3d9b39faf7c62a42328c7.tar.gz
Xcos: fix opar integers encoding issues
Change-Id: I375d1c270a09a63ec5a6ca8225e8ea670ddf3380
Diffstat (limited to 'scilab')
-rw-r--r--scilab/CHANGES.md3
-rw-r--r--scilab/modules/scicos/sci_gateway/cpp/sci_scicosim.cpp27
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/ScilabTypeCoder.java34
-rw-r--r--scilab/modules/xcos/tests/nonreg_tests/bug_7202.tst51
4 files changed, 104 insertions, 11 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index 29c6df9..42a7644 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -329,6 +329,7 @@ Bug Fixes
329* [#3188](https://bugzilla.scilab.org/3188): `part()` was slower than in Scilab 4.1.2. 329* [#3188](https://bugzilla.scilab.org/3188): `part()` was slower than in Scilab 4.1.2.
330* [#4648](https://bugzilla.scilab.org/4648): Scilab missed more secure hashing functions (md5 is now broken) 330* [#4648](https://bugzilla.scilab.org/4648): Scilab missed more secure hashing functions (md5 is now broken)
331* [#5511](https://bugzilla.scilab.org/5511): printf_conversion page was poorly presented and had many issues: The described types of accepted value and printed result were often switched; nothing was told about the processing of complex numbers; special escaped sequences \n \r \t \\ were not described; possible numbering of placeholders was not described; in the pt_BR version, the itemized lists were wrongly unnested and characters typing placeholders (d,u,o,x,f,e,g..) were missing. 331* [#5511](https://bugzilla.scilab.org/5511): printf_conversion page was poorly presented and had many issues: The described types of accepted value and printed result were often switched; nothing was told about the processing of complex numbers; special escaped sequences \n \r \t \\ were not described; possible numbering of placeholders was not described; in the pt_BR version, the itemized lists were wrongly unnested and characters typing placeholders (d,u,o,x,f,e,g..) were missing.
332* [#7202](https://bugzilla.scilab.org/7202): It was not possible to send string parameters via the opar structure of an xcos block to a block of type 4.
332* [#8059](https://bugzilla.scilab.org/8059): A local `.wgetrc` config file could make troubles in `atomsDownload`. 333* [#8059](https://bugzilla.scilab.org/8059): A local `.wgetrc` config file could make troubles in `atomsDownload`.
333* [#8100](https://bugzilla.scilab.org/8100): `cumsum()` on sparse documented. 334* [#8100](https://bugzilla.scilab.org/8100): `cumsum()` on sparse documented.
334* [#8378](https://bugzilla.scilab.org/8378): Datatip `ContextMenu => Delete last datatip` was useless. 335* [#8378](https://bugzilla.scilab.org/8378): Datatip `ContextMenu => Delete last datatip` was useless.
@@ -437,7 +438,7 @@ Bug Fixes
437* [#16571](https://bugzilla.scilab.org/16571): `mfile2sci` had several issues when converting the NOT ~ operator: 1) `~(1-1)` was converted into `~1-1` instead of `~(1-1)` 2) ~ applied to an integer expression yielded an error from `convert2double` 3) `~i` was converted into `~%i` instead of `~abs(%i)`. 438* [#16571](https://bugzilla.scilab.org/16571): `mfile2sci` had several issues when converting the NOT ~ operator: 1) `~(1-1)` was converted into `~1-1` instead of `~(1-1)` 2) ~ applied to an integer expression yielded an error from `convert2double` 3) `~i` was converted into `~%i` instead of `~abs(%i)`.
438* [#16573](https://bugzilla.scilab.org/16573): `mfile2sci`: Some `axis` conversions were wrong or not reliable. 439* [#16573](https://bugzilla.scilab.org/16573): `mfile2sci`: Some `axis` conversions were wrong or not reliable.
439* [#16586](https://bugzilla.scilab.org/16586): `mfile2sci`: The `prettyprintoutput` flag badly managed appended comments. 440* [#16586](https://bugzilla.scilab.org/16586): `mfile2sci`: The `prettyprintoutput` flag badly managed appended comments.
440* [#16596](https://bugzilla.scilab.org/16596): Concatenating encoded integers with sparse numeric data was not possible. 441* [#16596](https://bugzilla.scilab.org/16596): Concatenating encoded integers with sparse numeric data was not possible.
441* [#16608](https://bugzilla.scilab.org/16608): `union` did not support input boolean, sparse boolean, nor sparse numerical matrices. The result of `union(complexA, complexB)` was wrongly conjugate. 442* [#16608](https://bugzilla.scilab.org/16608): `union` did not support input boolean, sparse boolean, nor sparse numerical matrices. The result of `union(complexA, complexB)` was wrongly conjugate.
442* [#16609](https://bugzilla.scilab.org/16609): `bitcmp` needed to be upgraded for Scilab 6. 443* [#16609](https://bugzilla.scilab.org/16609): `bitcmp` needed to be upgraded for Scilab 6.
443* [#16612](https://bugzilla.scilab.org/16612): Unlike the `.*.` operator, `kron()` was not defined for sparse numeric matrices. 444* [#16612](https://bugzilla.scilab.org/16612): Unlike the `.*.` operator, `kron()` was not defined for sparse numeric matrices.
diff --git a/scilab/modules/scicos/sci_gateway/cpp/sci_scicosim.cpp b/scilab/modules/scicos/sci_gateway/cpp/sci_scicosim.cpp
index 12eaee8..5622d3a 100644
--- a/scilab/modules/scicos/sci_gateway/cpp/sci_scicosim.cpp
+++ b/scilab/modules/scicos/sci_gateway/cpp/sci_scicosim.cpp
@@ -12,7 +12,7 @@
12 * along with this program. 12 * along with this program.
13 * 13 *
14 */ 14 */
15 15#include <vector>
16#include <string> 16#include <string>
17#include <cstdio> 17#include <cstdio>
18#include <cwchar> 18#include <cwchar>
@@ -1614,7 +1614,7 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
1614 oztyp[j] = SCSUNKNOW_N; 1614 oztyp[j] = SCSUNKNOW_N;
1615 oz[j] = il_state_oz->get(j); 1615 oz[j] = il_state_oz->get(j);
1616 ozsz[j] = 0; // rows 1616 ozsz[j] = 0; // rows
1617 ozsz[j + nopar] = 0; // cols 1617 ozsz[j + noz] = 0; // cols
1618 break; 1618 break;
1619 } 1619 }
1620 } 1620 }
@@ -1624,9 +1624,18 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
1624 /**************************** 1624 /****************************
1625 * Set opar, oparsz, opartyp 1625 * Set opar, oparsz, opartyp
1626 ****************************/ 1626 ****************************/
1627 struct UTF8AllocatedStrings : std::vector<char*> {
1628 ~UTF8AllocatedStrings() {
1629 for (char* ptr : *this)
1630 {
1631 FREE(ptr);
1632 }
1633 };
1634 };
1627 void** opar = nullptr; 1635 void** opar = nullptr;
1628 int* oparsz = nullptr; 1636 int* oparsz = nullptr;
1629 int* opartyp = nullptr; 1637 int* opartyp = nullptr;
1638 UTF8AllocatedStrings oparStrings;
1630 if (nopar > 0) 1639 if (nopar > 0)
1631 { 1640 {
1632 // Allocation of 'opar' 1641 // Allocation of 'opar'
@@ -1813,6 +1822,20 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
1813 opar[j] = (SCSUINT32_COP *) oparUInt32->get(); 1822 opar[j] = (SCSUINT32_COP *) oparUInt32->get();
1814 break; 1823 break;
1815 } 1824 }
1825 case types::InternalType::ScilabString :
1826 {
1827 types::String* oparString = il_sim_opar->get(j)->getAs<types::String>();
1828 opartyp[j] = SCSINT8_N; // int8
1829 oparsz[j] = oparString->getSize();
1830 oparsz[j + nopar] = 1;
1831 for (int i = 0; i < oparString->getSize(); ++i)
1832 {
1833 // convert string as char* buffers, owned by oparStrings
1834 oparStrings.emplace_back(wide_string_to_UTF8(oparString->get(i)));
1835 opar[j] = oparStrings.back();
1836 }
1837 break;
1838 }
1816 default: 1839 default:
1817 { 1840 {
1818 opartyp[j] = SCSUNKNOW_N; 1841 opartyp[j] = SCSUNKNOW_N;
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/ScilabTypeCoder.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/ScilabTypeCoder.java
index b7ef697..142d270 100644
--- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/ScilabTypeCoder.java
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/ScilabTypeCoder.java
@@ -384,7 +384,15 @@ public class ScilabTypeCoder {
384 } 384 }
385 385
386 ScilabType var = decodeHeader(vec); 386 ScilabType var = decodeHeader(vec);
387 decode(vec, var); 387 try
388 {
389 decode(vec, var);
390 } catch (IllegalArgumentException e)
391 {
392 e.printStackTrace();
393 LOG.log(Level.SEVERE, "Unable to decode {0}", toString(vec));
394 }
395
388 396
389 // System.err.println("vec2var:" + toString(vec) + ":" + var.toString()); 397 // System.err.println("vec2var:" + toString(vec) + ":" + var.toString());
390 if (LOG.isLoggable(Level.FINE)) { 398 if (LOG.isLoggable(Level.FINE)) {
@@ -485,7 +493,7 @@ public class ScilabTypeCoder {
485 throw new IllegalArgumentException(); 493 throw new IllegalArgumentException();
486 } 494 }
487 495
488 final int doubleLen = (sizeof * var.getHeight() * var.getWidth()) / Double.BYTES + 1; 496 final int doubleLen = requiredLength(sizeof, var.getHeight(), var.getWidth());
489 ByteBuffer view = vec.asByteBuffer(position, doubleLen); 497 ByteBuffer view = vec.asByteBuffer(position, doubleLen);
490 498
491 for (int i = 0; i < var.getHeight(); i++) { 499 for (int i = 0; i < var.getHeight(); i++) {
@@ -595,7 +603,7 @@ public class ScilabTypeCoder {
595 int listLen = 0; 603 int listLen = 0;
596 604
597 final ScilabTypeEnum type = ScilabTypeEnum.swigToEnum(nativeScilabType); 605 final ScilabTypeEnum type = ScilabTypeEnum.swigToEnum(nativeScilabType);
598 switch (type) { 606 switch (type) {
599 case sci_ints: 607 case sci_ints:
600 // special case for integer precision 608 // special case for integer precision
601 precision = (int) vec.get(position++); 609 precision = (int) vec.get(position++);
@@ -697,6 +705,15 @@ public class ScilabTypeCoder {
697 decodeToJava(vec, arguments); 705 decodeToJava(vec, arguments);
698 return String.format(format, arguments.toArray()); 706 return String.format(format, arguments.toArray());
699 } 707 }
708
709 private int requiredLength(int sizeof, int height, int width)
710 {
711 if (sizeof == Double.BYTES) {
712 return height * width * sizeof / Double.BYTES;
713 } else {
714 return (height * width * sizeof + (Double.BYTES - 1)) / Double.BYTES;
715 }
716 }
700 717
701 private void decodeToJava(VectorOfDouble vec, ArrayList<Object> arguments) { 718 private void decodeToJava(VectorOfDouble vec, ArrayList<Object> arguments) {
702 int nativeScilabType = (int) vec.get(position++); 719 int nativeScilabType = (int) vec.get(position++);
@@ -761,7 +778,8 @@ public class ScilabTypeCoder {
761 } 778 }
762 break; 779 break;
763 case sci_boolean: { 780 case sci_boolean: {
764 final int doubleLen = (Integer.BYTES * height * width) / Double.BYTES + 1; 781 final int sizeof = Integer.BYTES;
782 final int doubleLen = requiredLength(sizeof, height, width);
765 ByteBuffer view = vec.asByteBuffer(position, doubleLen); 783 ByteBuffer view = vec.asByteBuffer(position, doubleLen);
766 for (int i = 0; i < height; i++) { 784 for (int i = 0; i < height; i++) {
767 for (int j = 0; j < width; j++) { 785 for (int j = 0; j < width; j++) {
@@ -776,7 +794,7 @@ public class ScilabTypeCoder {
776 case sci_int8: 794 case sci_int8:
777 case sci_uint8: { 795 case sci_uint8: {
778 final int sizeof = Byte.BYTES; 796 final int sizeof = Byte.BYTES;
779 final int doubleLen = (sizeof * height * width) / Double.BYTES + 1; 797 final int doubleLen = requiredLength(sizeof, height, width);
780 ByteBuffer view = vec.asByteBuffer(position, doubleLen); 798 ByteBuffer view = vec.asByteBuffer(position, doubleLen);
781 for (int i = 0; i < height; i++) { 799 for (int i = 0; i < height; i++) {
782 for (int j = 0; j < width; j++) { 800 for (int j = 0; j < width; j++) {
@@ -788,7 +806,7 @@ public class ScilabTypeCoder {
788 case sci_int16: 806 case sci_int16:
789 case sci_uint16: { 807 case sci_uint16: {
790 final int sizeof = Short.BYTES; 808 final int sizeof = Short.BYTES;
791 final int doubleLen = (sizeof * height * width) / Double.BYTES + 1; 809 final int doubleLen = requiredLength(sizeof, height, width);
792 ByteBuffer view = vec.asByteBuffer(position, doubleLen); 810 ByteBuffer view = vec.asByteBuffer(position, doubleLen);
793 for (int i = 0; i < height; i++) { 811 for (int i = 0; i < height; i++) {
794 for (int j = 0; j < width; j++) { 812 for (int j = 0; j < width; j++) {
@@ -800,7 +818,7 @@ public class ScilabTypeCoder {
800 case sci_int32: 818 case sci_int32:
801 case sci_uint32: { 819 case sci_uint32: {
802 final int sizeof = Integer.BYTES; 820 final int sizeof = Integer.BYTES;
803 final int doubleLen = (sizeof * height * width) / Double.BYTES + 1; 821 final int doubleLen = requiredLength(sizeof, height, width);
804 ByteBuffer view = vec.asByteBuffer(position, doubleLen); 822 ByteBuffer view = vec.asByteBuffer(position, doubleLen);
805 for (int i = 0; i < height; i++) { 823 for (int i = 0; i < height; i++) {
806 for (int j = 0; j < width; j++) { 824 for (int j = 0; j < width; j++) {
@@ -812,7 +830,7 @@ public class ScilabTypeCoder {
812 case sci_int64: 830 case sci_int64:
813 case sci_uint64: { 831 case sci_uint64: {
814 final int sizeof = Long.BYTES; 832 final int sizeof = Long.BYTES;
815 final int doubleLen = (sizeof * height * width) / Double.BYTES + 1; 833 final int doubleLen = requiredLength(sizeof, height, width);
816 ByteBuffer view = vec.asByteBuffer(position, doubleLen); 834 ByteBuffer view = vec.asByteBuffer(position, doubleLen);
817 for (int i = 0; i < height; i++) { 835 for (int i = 0; i < height; i++) {
818 for (int j = 0; j < width; j++) { 836 for (int j = 0; j < width; j++) {
diff --git a/scilab/modules/xcos/tests/nonreg_tests/bug_7202.tst b/scilab/modules/xcos/tests/nonreg_tests/bug_7202.tst
new file mode 100644
index 0000000..7c4cc8f
--- /dev/null
+++ b/scilab/modules/xcos/tests/nonreg_tests/bug_7202.tst
@@ -0,0 +1,51 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2020 - ESI Group - Clement DAVID
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7//
8// <-- XCOS TEST -->
9// <-- NO CHECK REF -->
10//
11// <-- Non-regression test for bug 7202 -->
12//
13// <-- Bugzilla URL -->
14// http://bugzilla.scilab.org/7202
15//
16// <-- Short Description -->
17// It's not possible to send string parameters via the opar structure of an xcos
18// block.
19
20function [x,y,typ] = CUSTOM_7202(job,arg1,arg2)
21 x=[];
22 y=[];
23 typ=[];
24 select job
25 case "set" then
26 x=arg1;
27 x.model.opar(1) = "this is a string parameter"
28 case "define" then
29 model=scicos_model();
30 model.sim="trash";
31 model.dep_ut = [%t %f];
32 model.opar(1) = "this is a string parameter"
33 x=standard_define([2 3], model, "", []);
34 end
35endfunction
36
37scs_m = scicos_diagram();
38scs_m.props.tf = 1;
39scs_m.objs(1) = CUSTOM_7202("define");
40
41// check the simulation
42scicos_simulate(scs_m);
43
44// save, load and check
45fname = fullfile(TMPDIR, "sample.zcos");
46xcosDiagramToScilab(fname, scs_m);
47prev_scs_m = xcosDiagramToScilab(fname);
48
49assert_checkequal(scs_m.objs(1).model.opar(1), prev_scs_m.objs(1).model.opar(1));
50assert_checkequal(scs_m.objs(1).model.opar(1), "this is a string parameter");
51