* Bug 16333: tree_show(xcos_block) crashed 91/21391/3
Samuel GOUGEON [Sun, 23 Feb 2020 20:55:16 +0000 (21:55 +0100)]
  http://bugzilla.scilab.org/16333

  This patch is OK for me for blocks.

  For diagrams: i succeeded only once to display the test diagram,
     and then never again. When debugging, it appears that the crash
     never occurs at the same level in the tree. It is somewhat random.
     At least on my (slow) PC.

Change-Id: I32d7fcfb8bfaa0aa4ed3e5db92d148ef98e8f9aa

scilab/CHANGES.md
scilab/modules/data_structures/help/en_US/tree_show.xml
scilab/modules/data_structures/help/ru_RU/tree_show.xml
scilab/modules/data_structures/macros/list2tree.sci
scilab/modules/data_structures/tests/nonreg_tests/bug_16333.tst [new file with mode: 0644]

index 7ca0da7..08b5296 100644 (file)
@@ -509,3 +509,4 @@ Bug Fixes
 * [#16321](https://bugzilla.scilab.org/16321): There were typo errors in the documentation.
 * [#16323](https://bugzilla.scilab.org/16323): `conj(sparse(x))` was complex when x is real.
 * [#16325](https://bugzilla.scilab.org/16325): `mgetl` could not read single line data which is greater than ~260,000 characters.
+* [#16333](https://bugzilla.scilab.org/16333): `tree_show` crashed for an input Xcos block.
index 3dbab84..6a9fc4f 100644 (file)
@@ -19,7 +19,9 @@
           xml:lang="en" xml:id="tree_show">
     <refnamediv>
         <refname>tree_show</refname>
-        <refpurpose>Displays a tree view of a list, tlist, mlist, cell or structure array</refpurpose>
+        <refpurpose>
+            Displays a tree view of a list, tlist, mlist, cell or structure array, Xcos diagram or block
+        </refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
@@ -38,7 +40,8 @@
                 <listitem>
                     <para>
                     Container to display. Supported containers: list, mlist, tlist, array of cells,
-                    array of structures. Other containers may be nested in <varname>x</varname>.
+                    array of structures, identifier of an Xcos diagram or block.
+                    Other containers may be nested in <varname>x</varname>.
                     </para>
                 </listitem>
             </varlistentry>
     </refsection>
     <refsection>
         <title>Examples</title>
-    <para>
-    <emphasis role="bold">list(), including a cells array</emphasis> :
-    </para>
-    <table>
-        <tr>
-            <td>
-                <programlisting role="example"><![CDATA[
-        films = struct("Title", "A.I. Artificial Intelligence",..
-                       "Year", 2001, ..
-                       "Director", "Steven Spielberg", ..
-                       "Duration", 140);
-        L = list([%t %f %f],                ..
-                 $:-1:3,                    ..
-                 int8([1 2 3 ; 4 5 6]),     ..
-                 [-%inf, -1, 0, %i, 7.1, 3.3e20, %inf, %nan], ..
-                 sparse([0 1 2; 3 0 4]),    ..
-                 ["This" "is" "some" "text"], ..
-                 ,              ..
-                 sin,           ..
-                 logspace,      ..
-                 iolib,         ..
-                 {%pi, "abcd" ;
-                  list(,)(1),(%i-%s)^3},    ..
-                  {},           ..
-                 films);
-        tree_show(L)
-         ]]></programlisting>
-            </td>
-            <td>
-                <inlinemediaobject>
-                    <imageobject>
-                        <imagedata fileref="../images/tree_show_list.png"/>
-                    </imageobject>
-                </inlinemediaobject>
-            </td>
-        </tr>
-    </table>
+        <para>
+            <emphasis role="bold">list(), including a cells array</emphasis> :
+        </para>
+        <table>
+            <tr>
+                <td>
+                    <programlisting role="example"><![CDATA[
+            films = struct("Title", "A.I. Artificial Intelligence",..
+                           "Year", 2001, ..
+                           "Director", "Steven Spielberg", ..
+                           "Duration", 140);
+            L = list([%t %f %f],                ..
+                     $:-1:3,                    ..
+                     int8([1 2 3 ; 4 5 6]),     ..
+                     [-%inf, -1, 0, %i, 7.1, 3.3e20, %inf, %nan], ..
+                     sparse([0 1 2; 3 0 4]),    ..
+                     ["This" "is" "some" "text"], ..
+                     ,              ..
+                     sin,           ..
+                     logspace,      ..
+                     iolib,         ..
+                     {%pi, "abcd" ;
+                      list(,)(1),(%i-%s)^3},    ..
+                      {},           ..
+                     films);
+            tree_show(L)
+             ]]></programlisting>
+                </td>
+                <td>
+                    <inlinemediaobject>
+                        <imageobject>
+                            <imagedata fileref="../images/tree_show_list.png"/>
+                        </imageobject>
+                    </inlinemediaobject>
+                </td>
+            </tr>
+        </table>
 
-    <para>
-    <emphasis role="bold">Using the <emphasis>rootTitle</emphasis> and <emphasis>styles</emphasis>
-        options
-    </emphasis> :
-    </para>
+        <para>
+            <emphasis role="bold">
+                Using the <emphasis>rootTitle</emphasis> and <emphasis>styles</emphasis> options
+            </emphasis> :
+        </para>
         <programlisting role="example"><![CDATA[
 // Data to display:
 clear films
@@ -193,17 +196,17 @@ tree_show(films, mainTitle , "<font color=""red"">$</font><i>");
 // Styling only the contents:
 mainTitle = "<html><b>Films (B)</b>";
 tree_show(films([1 4]), mainTitle, "$<font color=""green"">", %t);
- ]]></programlisting>
-    <para/>
-    <inlinemediaobject>
-        <imageobject>
-            <imagedata fileref="../images/tree_show_styling.png"/>
-        </imageobject>
-    </inlinemediaobject>
+     ]]></programlisting>
+        <para/>
+        <inlinemediaobject>
+            <imageobject>
+                <imagedata fileref="../images/tree_show_styling.png"/>
+            </imageobject>
+        </inlinemediaobject>
 
-    <para>
-    <emphasis role="bold">Array of structures</emphasis> :
-    </para>
+        <para>
+            <emphasis role="bold">Array of structures</emphasis> :
+        </para>
         <programlisting role="example"><![CDATA[
 clear films
 films(1) = struct("Title", "A.I. Artificial Intelligence",..
@@ -227,24 +230,22 @@ tree_show(films(:),"Films (I)");
 tree_show(films   ,"Films (II)");
 tree_show(films(:),"Films (III)", , %t);
 tree_show(films   ,"Films (IV)" , , %t);
- ]]></programlisting>
-    <screen><![CDATA[
+     ]]></programlisting>
+        <screen><![CDATA[
 2x2 struct array with fields:
    Title
    Director
    Year
    Duration
 ]]></screen>
-    <inlinemediaobject>
-        <imageobject>
-            <imagedata fileref="../images/tree_show_2x2.png"/>
-        </imageobject>
-    </inlinemediaobject>
-    <para/>
-
-    <para>
-    <emphasis role="bold">With a custom tlist or mlist</emphasis> :
-    </para>
+        <inlinemediaobject>
+            <imageobject>
+                <imagedata fileref="../images/tree_show_2x2.png"/>
+            </imageobject>
+        </inlinemediaobject>
+        <para>
+            <emphasis role="bold">With a custom tlist or mlist</emphasis> :
+        </para>
         <programlisting role="example"><![CDATA[
 // For a mlist:
 str = ['a','b','c','d','e','f','g','h'];
@@ -256,8 +257,21 @@ tree_show(Mm);
 // For a tlist:
 Mt = tlist(['V','name','value'],['a','b','c'],[1 2 3]);
 tree_show(Mt);
- ]]></programlisting>
-    <para/>
+     ]]></programlisting>
+        <para/>
+        <para>
+            <emphasis role="bold">For an Xcos diagram or block</emphasis> :
+        </para>
+        <programlisting role="example"><![CDATA[
+loadXcosLibs();
+
+filename = SCI+"/modules/xcos/demos/demo_Datatype.xmi";
+xcosDiag = scicosDiagramToScilab(filename);
+tree_show(xcosDiag)
+
+blk = BIGSOM_f("define");
+tree_show(blk)
+     ]]></programlisting>
     </refsection>
 
     <refsection role="see also">
index 3ea5ed5..5be3e03 100644 (file)
@@ -20,7 +20,8 @@
     <refnamediv>
         <refname>tree_show</refname>
         <refpurpose>
-            Отображает в виде дерева содержимое list, tlist, mlist, cell-массивы или массивы структур
+            Отображает в виде дерева содержимое list, tlist, mlist, cell-массивы или массивы структур,
+            Xcos diagram or block
         </refpurpose>
     </refnamediv>
     <refsynopsisdiv>
@@ -40,8 +41,8 @@
                 <listitem>
                     <para>
                         Контейнер для отображения. Поддерживаемые контейнеры list, mlist, tlist,
-                        cell-массивы или массивы структур. Другие контейнеры могут быть вложены
-                        в <varname>x</varname>.
+                        cell-массивы или массивы структур, identifier of an Xcos diagram or block.
+                        Другие контейнеры могут быть вложены в <varname>x</varname>.
                     </para>
                 </listitem>
             </varlistentry>
@@ -54,7 +55,7 @@
                         <literal>""</literal>.
                     </para>
                     <note>
-                        Для изменения стиля названия корня могут использоваться теги стилей 
+                        Для изменения стиля названия корня могут использоваться теги стилей
                         HTML.4.
                         Например: "<literal>&lt;html>&lt;font color="red">&lt;b>Название&lt;/b></literal>"
                         отобразит <emphasis>Название</emphasis> жирным красным шрифтом.
     </refsection>
     <refsection>
         <title>Примеры</title>
-    <para>
-    <emphasis role="bold">list(), включая cell-массив</emphasis> :
-    </para>
-    <table>
-        <tr>
-            <td>
-                <programlisting role="example"><![CDATA[
-        films = struct("Title", "A.I. Artificial Intelligence",..
-                       "Year", 2001, ..
-                       "Director", "Steven Spielberg", ..
-                       "Duration", 140);
-        L = list([%t %f %f],                ..
-                 $:-1:3,                    ..
-                 int8([1 2 3 ; 4 5 6]),     ..
-                 [-%inf, -1, 0, %i, 7.1, 3.3e20, %inf, %nan], ..
-                 sparse([0 1 2; 3 0 4]),    ..
-                 ["This" "is" "some" "text"], ..
-                 ,              ..
-                 sin,           ..
-                 logspace,      ..
-                 iolib,         ..
-                 {%pi, "abcd" ;
-                  list(,)(1),(%i-%s)^3},    ..
-                  {},           ..
-                 films);
-        tree_show(L)
-         ]]></programlisting>
-            </td>
-            <td>
-                <inlinemediaobject>
-                    <imageobject>
-                        <imagedata fileref="../images/tree_show_list.png"/>
-                    </imageobject>
-                </inlinemediaobject>
-            </td>
-        </tr>
-    </table>
+        <para>
+            <emphasis role="bold">list(), включая cell-массив</emphasis> :
+        </para>
+        <table>
+            <tr>
+                <td>
+                    <programlisting role="example"><![CDATA[
+films = struct("Title", "A.I. Artificial Intelligence",..
+               "Year", 2001, ..
+               "Director", "Steven Spielberg", ..
+               "Duration", 140);
+L = list([%t %f %f],                ..
+         $:-1:3,                    ..
+         int8([1 2 3 ; 4 5 6]),     ..
+         [-%inf, -1, 0, %i, 7.1, 3.3e20, %inf, %nan], ..
+         sparse([0 1 2; 3 0 4]),    ..
+         ["This" "is" "some" "text"], ..
+         ,              ..
+         sin,           ..
+         logspace,      ..
+         iolib,         ..
+         {%pi, "abcd" ;
+          list(,)(1),(%i-%s)^3},    ..
+          {},           ..
+         films);
+tree_show(L)
+             ]]></programlisting>
+                </td>
+                <td>
+                    <inlinemediaobject>
+                        <imageobject>
+                            <imagedata fileref="../images/tree_show_list.png"/>
+                        </imageobject>
+                    </inlinemediaobject>
+                </td>
+            </tr>
+        </table>
 
-    <para>
-    <emphasis role="bold">Использование опций <emphasis>rootTitle</emphasis> и <emphasis>styles</emphasis>
-    </emphasis> :
-    </para>
+        <para>
+            <emphasis role="bold">
+                Использование опций <emphasis>rootTitle</emphasis> и <emphasis>styles</emphasis>
+            </emphasis> :
+        </para>
         <programlisting role="example"><![CDATA[
 // Данные для отображения:
 clear films
@@ -196,17 +198,17 @@ tree_show(films, mainTitle , "<font color=""red"">$</font><i>");
 // Стилевое оформление только содержимого:
 mainTitle = "<html><b>Films (B)</b>";
 tree_show(films([1 4]), mainTitle, "$<font color=""green"">", %t);
- ]]></programlisting>
-    <para/>
-    <inlinemediaobject>
-        <imageobject>
-            <imagedata fileref="../images/tree_show_styling.png"/>
-        </imageobject>
-    </inlinemediaobject>
+     ]]></programlisting>
+        <para/>
+        <inlinemediaobject>
+            <imageobject>
+                <imagedata fileref="../images/tree_show_styling.png"/>
+            </imageobject>
+        </inlinemediaobject>
 
-    <para>
-    <emphasis role="bold">Массив структур</emphasis> :
-    </para>
+        <para>
+            <emphasis role="bold">Массив структур</emphasis> :
+        </para>
         <programlisting role="example"><![CDATA[
 clear films
 films(1) = struct("Title", "A.I. Artificial Intelligence",..
@@ -230,24 +232,23 @@ tree_show(films(:),"Films (I)");
 tree_show(films   ,"Films (II)");
 tree_show(films(:),"Films (III)", , %t);
 tree_show(films   ,"Films (IV)" , , %t);
- ]]></programlisting>
-    <screen><![CDATA[
+     ]]></programlisting>
+        <screen><![CDATA[
 2x2 struct array with fields:
    Title
    Director
    Year
    Duration
-]]></screen>
-    <inlinemediaobject>
-        <imageobject>
-            <imagedata fileref="../images/tree_show_2x2.png"/>
-        </imageobject>
-    </inlinemediaobject>
-    <para/>
-
-    <para>
-    <emphasis role="bold">С пользовательским tlist или mlist</emphasis> :
-    </para>
+    ]]></screen>
+        <inlinemediaobject>
+            <imageobject>
+                <imagedata fileref="../images/tree_show_2x2.png"/>
+            </imageobject>
+        </inlinemediaobject>
+        <para/>
+        <para>
+            <emphasis role="bold">С пользовательским tlist или mlist</emphasis> :
+        </para>
         <programlisting role="example"><![CDATA[
 // Для mlist:
 str = ['a','b','c','d','e','f','g','h'];
@@ -259,8 +260,21 @@ tree_show(Mm);
 // Для tlist:
 Mt = tlist(['V','name','value'],['a','b','c'],[1 2 3]);
 tree_show(Mt);
- ]]></programlisting>
-    <para/>
+     ]]></programlisting>
+        <para/>
+        <para>
+            <emphasis role="bold">For an Xcos diagram or block</emphasis> :
+        </para>
+        <programlisting role="example"><![CDATA[
+loadXcosLibs();
+
+filename = SCI+"/modules/xcos/demos/demo_Datatype.xmi";
+xcosDiag = scicosDiagramToScilab(filename);
+tree_show(xcosDiag)
+
+blk = BIGSOM_f("define");
+tree_show(blk)
+         ]]></programlisting>
     </refsection>
 
     <refsection role="see also">
index 3484555..bef691f 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2019 - Samuel GOUGEON
+// Copyright (C) 2019 - 2020 - Samuel GOUGEON
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
 // pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -107,7 +107,7 @@ function tree = list2tree_inc(x, Path, tree, styles, arrayByFields)
             v = container_get_ijk_labels(size(x))
         end
 
-    elseif type(x)==17 & typeof(x)=="st" then
+    elseif (type(x)==17 & typeof(x)=="st") then
         // Structures are displayed first by k indices, then
         // for each x(k), by field. In this way, each x(k) is
         // displayed as a whole object/record, instead of being split.
@@ -139,7 +139,7 @@ function tree = list2tree_inc(x, Path, tree, styles, arrayByFields)
             end
             tree($).label = tree($).label + tmp
         end
-        
+
     elseif typeof(x)=="rational"
         v = getfield(1,x);
         II = 2:4
@@ -154,6 +154,17 @@ function tree = list2tree_inc(x, Path, tree, styles, arrayByFields)
         end
         tree($).label = tree($).label + tmp
 
+    elseif type(x)==128 & or(typeof(x)==["diagram" "Block"])
+        tmp = _(" [Xcos diagram]")
+        if typeof(x)=="Block" then
+            tmp = _(" [Xcos block]")
+        end
+        struct_array = %f
+        v = ["" ; fieldnames(x)]
+        II = 2:size(v,"*")  // fields indices
+        //list_field_content = size(x)
+        tree($).label = tree($).label + tmp
+
     else // or(type(x)==[16 17])
         v = getfield(1,x);
         II = 2:size(v,"*")
@@ -188,10 +199,10 @@ function tree = list2tree_inc(x, Path, tree, styles, arrayByFields)
         if styles <> ""
             titre = strsubst("<html>"+styles, "$", titre)
         end
-    
+
         // Reads the object
         clear o
-        if typeof(x)=="st" then
+        if typeof(x)=="st" | (type(x)==128 & or(typeof(x)==["diagram" "Block"])) then
             if ~struct_array
                 o = x(v(i))
             else
@@ -221,17 +232,17 @@ function tree = list2tree_inc(x, Path, tree, styles, arrayByFields)
 
         elseif typeof(o)=="implicitlist"
             tree = uiConcatTree(tree, uiCreateNode(titre + sci2exp(o)));
-            
+
         elseif type(o)== 13    // function
             p = macr2tree(o)
-            tmp = msprintf(_("%s() (%d lines)"), p.name, p.nblines) 
+            tmp = msprintf(_("%s() (%d lines)"), p.name, p.nblines)
             tree = uiConcatTree(tree, uiCreateNode(titre + tmp));
-            
+
         elseif type(o)== 14    // library
             tmp = string(o)
             p = strsubst(tmp(1), "\", "/"); // not escaped chars for mprintf()
             libname = xmlGetValues("/scilablib","name",p + "lib")
-            tmp = msprintf("%s library of %d functions @ %s", ..
+            tmp = msprintf(_("%s library of %d functions @ %s"), ..
                            libname, size(tmp,1)-1, p)
             tree = uiConcatTree(tree, uiCreateNode(titre + tmp));
 
diff --git a/scilab/modules/data_structures/tests/nonreg_tests/bug_16333.tst b/scilab/modules/data_structures/tests/nonreg_tests/bug_16333.tst
new file mode 100644 (file)
index 0000000..d6bf80e
--- /dev/null
@@ -0,0 +1,27 @@
+// =============================================================================
+// 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.
+// =============================================================================
+//
+// <-- NO CHECK REF -->
+//
+// <-- Non-regression test for bug 16333 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/16333
+//
+// <-- Short Description -->
+// tree_show() was broken for Xcos blocks and diagrams
+
+
+loadXcosLibs();
+
+blk = BIGSOM_f("define");
+assert_checkequal(execstr("tree_show(blk)","errcatch"), 0);
+
+//filename = SCI+"/modules/xcos/demos/demo_Datatype.xmi";
+//scs_m = scicosDiagramToScilab(filename);
+//tree_show(scs_m)
+//assert_checkequal(execstr("tree_show(scs_m)","errcatch"), 0);