add a %foo_clear overloading on mlist 79/20679/14
Clément DAVID [Wed, 9 Jan 2019 10:16:32 +0000 (11:16 +0100)]
This overload will be called at the end of the scope when a variable
will not be accessible anymore for clearing allocated data.

Implementations for External Object and External Object Java are also
provided to avoid being forced to call `jremove`.

Change-Id: I13076e936f9d35a559e12a8668aaaaa6f7a6a8ab

27 files changed:
SEP/INDEX
SEP/SEP_134_add_a_%foo_delete_overloading.txt [new file with mode: 0644]
scilab/CHANGES.md
scilab/modules/ast/includes/types/mlist.hxx
scilab/modules/ast/includes/types/tlist.hxx
scilab/modules/ast/src/cpp/ast/run_AssignExp.hpp
scilab/modules/ast/src/cpp/types/mlist.cpp
scilab/modules/ast/src/cpp/types/tlist.cpp
scilab/modules/core/help/en_US/variables/clear.xml
scilab/modules/core/help/fr_FR/variables/clear.xml
scilab/modules/core/help/ja_JP/variables/clear.xml
scilab/modules/core/help/pt_BR/variables/clear.xml
scilab/modules/core/help/ru_RU/variables/clear.xml
scilab/modules/external_objects/Makefile.am
scilab/modules/external_objects/Makefile.in
scilab/modules/external_objects/external_objects.vcxproj
scilab/modules/external_objects/external_objects.vcxproj.filters
scilab/modules/external_objects/includes/ScilabGateway.hxx
scilab/modules/external_objects/includes/gw_external_objects.h
scilab/modules/external_objects/sci_gateway/cpp/sci_percent_EObj_clear.cpp [new file with mode: 0644]
scilab/modules/external_objects/sci_gateway/external_objects_gateway.xml
scilab/modules/external_objects/src/cpp/clear.cpp [new file with mode: 0644]
scilab/modules/external_objects_java/help/en_US/jremove.xml
scilab/modules/external_objects_java/help/ja_JP/jremove.xml
scilab/modules/external_objects_java/tests/unit_tests/clear.tst [new file with mode: 0644]
scilab/modules/external_objects_java/tests/unit_tests/jremove.tst [new file with mode: 0644]
scilab/modules/overloading/tests/unit_tests/clear.tst [new file with mode: 0644]

index c22ce76..5b94042 100644 (file)
--- a/SEP/INDEX
+++ b/SEP/INDEX
@@ -128,3 +128,5 @@ SEP #129: HTLM parsing functions.
 SEP #130: Replace obsolete numdiff and derivative with new function numderivative.
 SEP #131: Modified matfile2sci to have an new input argument overwrite to overwrite the output file
 SEP #132: Remove useless output argument err of add_param function.
+SEP #133: Implement profiling functions to output Scilab values
+SEP #134: Add `%foo_clear` overloading and implement it for External Objects Java
diff --git a/SEP/SEP_134_add_a_%foo_delete_overloading.txt b/SEP/SEP_134_add_a_%foo_delete_overloading.txt
new file mode 100644 (file)
index 0000000..06a90d5
--- /dev/null
@@ -0,0 +1,71 @@
+= SEP: add a `%foo_clear` overloading =\r
+\r
+= Abstract =\r
+\r
+Some Scilab features are implemented through a `mlist` object and using the overloading mechanism to call a generic gateway on an operation. This is the case for the `external_object` (and JIMS), `xml` and `hdf5` functionalities. To correctly call a destructor (to release resources, free mapping tables, etc...) a specific gateway is implemented and should be called to avoid memory leaks. This SEP propose to add an overloading `%foo_clear` called on `foo mlist` destruction to avoid the specific gateway thus let the mlist behave as other Scilab values.\r
+\r
+= Requirements =\r
+\r
+A `%foo_clear` function should be called on `foo mlist` destruction by the interpreter. If not defined, no error is produced and nothing is performed instead. This function will take an argument representing the deleted mlist value;  \r
+\r
+Atop of this deletion management, Scilab functionalities could be improved to handle this new behavior. For example, `jremove` (from external_object_java), `xmlDelete` (from xml) and `h5close` (from hdf5) could be called on deletion to avoid resource leaks and let the user `clear` the associated mlist. \r
+\r
+== Bugzilla links ==\r
+\r
+The following bugs have been entered on Bugzilla to track similar or related problems/wishlist:\r
+\r
+ * [[https://bugzilla.scilab.org/show_bug.cgi?id=10277]] bug report on clear() overloading\r
+ * [[https://bugzilla.scilab.org/show_bug.cgi?id=10258]] related issue with xmlDelete\r
+ * [[https://bugzilla.scilab.org/show_bug.cgi?id=13398]] original clear() vs xmlDelete report\r
+\r
+== Mailing list threads ==\r
+\r
+http://mailinglists.scilab.org/SEP-add-a-foo-delete-overloading-td4038898.html\r
+\r
+== Other software ==\r
+\r
+\r
+= Examples =\r
+\r
+== Explicit call ==\r
+\r
+{{{#!highlight scilab\r
+\r
+function %foo_clear(o)\r
+       disp("resource deleted")\r
+endfunction\r
+\r
+value = mlist("foo");\r
+clear value\r
+\r
+}}}\r
+\r
+== Implicit call ==\r
+\r
+{{{#!highlight scilab\r
+function %foo_clear(o)\r
+    disp("clear foo");\r
+endfunction\r
+\r
+function do_someting()\r
+    value = mlist("foo");\r
+endfunction\r
+\r
+do_someting(); // %foo_clear will be call at the end of do_something\r
+}}}\r
+\r
+{{{#!highlight scilab\r
+function %foo_clear(o)\r
+    disp("clear foo");\r
+endfunction\r
+\r
+function value = do_someting_and_return()\r
+    value = mlist("foo");\r
+endfunction\r
+\r
+x = do_someting_and_return();\r
+x = 1; //call %foo_clear overload before replace\r
+}}}\r
+\r
+----\r
+CategorySep\r
index b780440..fb929c2 100644 (file)
@@ -26,7 +26,7 @@ For a high-level description of the main new features of this release, please co
 
 In summary, the main new features are:
 * Webtools utilities added for HTTP protocol, JSON data usage
-* Profiled values are available as Scilab values 
+* Profiled values are available as Scilab values
 * Values have a cleaner display:
    - they are displayed in order on assignement
    - strings are quoted
@@ -104,6 +104,7 @@ Feature changes and additions
   - Octave native text data files can now be read.
   - Automatic detection of the input data format implemented.
   - `-toStruct` option added, to return results in a structure instead of in the calling environment.
+* `jremove` is optional and `clear` could be used to release Java objects mapped to Scilab.
 
 Help pages:
 -----------
@@ -167,11 +168,11 @@ Bug Fixes
 * [#15271](http://bugzilla.scilab.org/show_bug.cgi?id=15271): `bitget` needed to be upgraded.
 * [#15321](http://bugzilla.scilab.org/show_bug.cgi?id=15321): `lu()` was leaking memory.
 * [#15425](http://bugzilla.scilab.org/show_bug.cgi?id=15425): The Kronecker product `a.*.b` failed when `a` or `b` or both are hypermatrices, with one or both being polynomials or rationals.
-* [#15523](http://bugzilla.scilab.org/show_bug.cgi?id=15523): `%ODEOPTIONS(1)=2` didn't work with solvers 'rk' and 'rkf' 
+* [#15523](http://bugzilla.scilab.org/show_bug.cgi?id=15523): `%ODEOPTIONS(1)=2` didn't work with solvers 'rk' and 'rkf'
 * [#15248](http://bugzilla.scilab.org/show_bug.cgi?id=15248): `lsq()`was leaking memory.
 * [#15577](http://bugzilla.scilab.org/show_bug.cgi?id=15577): `edit` did not accept a line number as text, as with `edit linspace 21`.
 * [#15668](http://bugzilla.scilab.org/show_bug.cgi?id=15668): `save(filename)` saved all predefined Scilab constants %e %pi etc.. (regression)
-* [#15715](http://bugzilla.scilab.org/show_bug.cgi?id=15715): `%nan` indices crashed Scilab. 
+* [#15715](http://bugzilla.scilab.org/show_bug.cgi?id=15715): `%nan` indices crashed Scilab.
 * [#15581](http://bugzilla.scilab.org/show_bug.cgi?id=15581): display of complex matrix was ugly.
 * [#15680](http://bugzilla.scilab.org/show_bug.cgi?id=15680): `loadmatfile()` could not return variables in a structure instead of into the calling environment.
 * [#15812](http://bugzilla.scilab.org/show_bug.cgi?id=15812): On assigning variables the source variable may become become corrupted
@@ -185,7 +186,7 @@ Bug Fixes
 * [#16007](http://bugzilla.scilab.org/show_bug.cgi?id=16007): Non-integer index in sparse makes Scilab crash.
 * [#16012](http://bugzilla.scilab.org/show_bug.cgi?id=16012): `[struct() struct()]` crashed Scilab.
 * [#16013](http://bugzilla.scilab.org/show_bug.cgi?id=16013): Load previously saved environment with "File/Load environment" menu failed.
-* [#16014](http://bugzilla.scilab.org/show_bug.cgi?id=16014): after `x.a=1; x(:)=[]` x.a was an empty list. 
+* [#16014](http://bugzilla.scilab.org/show_bug.cgi?id=16014): after `x.a=1; x(:)=[]` x.a was an empty list.
 * [#16015](http://bugzilla.scilab.org/show_bug.cgi?id=116015): `intg(a,b,f)` called f(x) with x outside [a,b].
 * [#16021](http://bugzilla.scilab.org/show_bug.cgi?id=16021): `tand([-90 90])` answered [Nan Nan] instead of [-Inf, Inf]. `cotd([-90 90])` answered [Nan Nan] instead of [0 0]. `1 ./cosd([-90 90])` answered [Inf -Inf] instead of [Inf Inf].
 * [#16067](http://bugzilla.scilab.org/show_bug.cgi?id=16067): The display of matrices of signed integers was misaligned (regression of 6.0.0 vs 5.5.2)
index f2c2fc4..ffd06c8 100644 (file)
@@ -25,7 +25,7 @@ class EXTERN_AST MList : public TList
 {
 public :
     MList() : TList() {}
-    //Destructor uses ~TList()
+    ~MList();
 
     virtual MList*                  clone() override
     {
index 3ac7aaf..875792f 100644 (file)
@@ -27,8 +27,9 @@ class EXTERN_AST TList : public List
 {
 public :
     TList();
-    ~TList();
-protected :
+    virtual ~TList();
+
+protected:
     TList(TList *_oTListCopyMe) : List(_oTListCopyMe) {}
 
 public :
index 73cbf95..ae123c9 100644 (file)
@@ -91,15 +91,6 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
                 return;
             }
 
-            if (pIT->isList() && pIT->getRef() > 0)
-            {
-                // Prevent modification of all scilab variable
-                // which point to this container when it is used
-                // in setfield scilab function.
-                // A clone on a container will not clone what it contain.
-                pIT = pIT->clone();
-            }
-
             if (e.getRightExp().isReturnExp())
             {
                 //ReturnExp so, put the value in the previous scope
index 3cea732..d3a5604 100644 (file)
  *
  */
 
-#include <sstream>
 #include "mlist.hxx"
 #include "callable.hxx"
-#include "overload.hxx"
 #include "configvariable.hxx"
+#include "context.hxx"
 #include "exp.hxx"
+#include "overload.hxx"
 #include "types_tools.hxx"
+#include <sstream>
 
 #ifndef NDEBUG
 #include "inspector.hxx"
 
 namespace types
 {
+
+MList::~MList()
+{
+    typed_list in;
+    typed_list out;
+    optional_list opt;
+    IncreaseRef();
+    in.push_back(this);
+
+    try
+    {
+        Overload::generateNameAndCall(L"clear", in, 0, out);
+    }
+    catch (ast::InternalError& /*se*/)
+    {
+        // avoid error message about undefined overload %type_clear
+        ConfigVariable::resetError();
+        // reset where error filled by generateNameAndCall
+        ConfigVariable::resetWhereError();
+    }
+
+    DecreaseRef();
+}
+
 bool MList::getMemory(long long* _piSize, long long* _piSizePlusType)
 {
     *_piSize = 0;
index fab3e9f..8390293 100644 (file)
@@ -349,6 +349,8 @@ bool TList::toString(std::wostringstream& ostr)
 
         // avoid error message about undefined overload %type_p
         ConfigVariable::resetError();
+        // reset where error filled by generateNameAndCall
+        ConfigVariable::resetWhereError();
     }
 
     DecreaseRef();
index e7ecd28..2e8a7ce 100644 (file)
@@ -35,7 +35,7 @@
             <varlistentry>
                 <term>a, b, c...</term>
                 <listitem>
-                    <para>variables of any type and size, but not protected</para>
+                    <para>names of variables of any type and size, but not protected</para>
                 </listitem>
             </varlistentry>
         </variablelist>
@@ -50,8 +50,7 @@
             remove all the variables.
         </para>
         <para>
-            Normally, protected variables are standard libraries and variables with
-            the percent prefix.
+            Normally, protected variables are standard libraries and variables with the percent prefix.
         </para>
         <para>
             <note>
             </note>
         </para>
         <para>
-            The command <code>clear</code> can kill nonexistent variables, i. e.
-            <code>clear</code> kills nonexistent variables as if they exist.
+            If a name <emphasis>Var</emphasis> matches no variable, <literal>clear Var</literal>
+            does nothing silently.
         </para>
+      <note>
+        <literal>clear()</literal> can be overloaded for any <literal>mlist("foo")</literal> type,
+        by defining a <literal>%foo_clear()</literal> macro. It will be called either when
+        <literal>clear</literal> is explicitly applied to any mlist of this type, or implicitly
+        when any mlist of this type is deleted when leaving the environment where it has been
+        defined.
+      </note>
     </refsection>
     <refsection>
         <title>Examples</title>
@@ -82,7 +88,15 @@ b = 3;
 c = 4;
 clear(['a' 'b' 'c'])
 isdef("a") | isdef("b") | isdef("c") // F
-        ]]></programlisting>
+     ]]></programlisting>
+        <programlisting role="example"><![CDATA[
+function %foo_clear(o)
+    disp("deleted");
+endfunction
+
+value = mlist("foo");
+clear value // will print "deleted"
+]]></programlisting>
     </refsection>
     <refsection role="see also">
         <title>See also</title>
@@ -91,11 +105,17 @@ isdef("a") | isdef("b") | isdef("c") // F
                 <link linkend="predef">predef</link>
             </member>
             <member>
+                <link linkend="clearglobal">clearglobal</link>
+            </member>
+            <member>
                 <link linkend="funcprot">funcprot</link>
             </member>
             <member>
                 <link linkend="who">who</link>
             </member>
+            <member>
+                <link linkend="xmlDelete">xmlDelete</link>
+            </member>
         </simplelist>
     </refsection>
     <refsection>
@@ -112,6 +132,13 @@ isdef("a") | isdef("b") | isdef("c") // F
                   Assignments like <literal>clear=1</literal> are no longer possible.
                 </revdescription>
             </revision>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    <literal>clear</literal> becomes overloadable for any
+                    <literal>mlist("foo")</literal>, with <literal>%foo_clear()</literal>.
+                </revdescription>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
index c99587d..b9e62c8 100644 (file)
             Habituellement, les variables protégées sont les bibliothèques standard et les variables dont le nom commence par le caractère "%".
         </para>
         <para>
-            Notez la syntaxe particulière :  <literal>clear a</literal> et non <literal>clear(a)</literal>. Notez aussi que <literal>a=[]</literal> ne supprime pas <literal>a</literal> mais affecte à <literal>a</literal> une matrice vide.
+            Notez la syntaxe particulière :  <literal>clear a</literal> et non <literal>clear(a)</literal>.
+            Notez aussi que <literal>a=[]</literal> ne supprime pas <literal>a</literal>
+            mais affecte à <literal>a</literal> une matrice vide.
         </para>
+        <para>
+            Si un nom <emphasis>Var</emphasis> ne correspond à aucune variable,
+            <literal>clear Var</literal> sera simplement ignoré.
+        </para>
+    <note>
+       <literal>clear</literal> peut être surchargée pour toute <literal>mlist("foo")</literal>,
+       en définissant la fonction <literal>%foo_clear()</literal>. Celle-ci sera appelée autant
+       lors des appels explicites à <literal>clear</literal>, qu'en quittant l'environnement
+       où la mlist a été définie.
+    </note>
     </refsection>
     <refsection>
         <title>Exemples</title>
@@ -71,6 +83,14 @@ c = 4;
 clear(['a' 'b' 'c'])
 isdef("a") | isdef("b") | isdef("c") // F
         ]]></programlisting>
+        <programlisting role="example"><![CDATA[
+function %foo_clear(o)
+    disp("deleted");
+endfunction
+
+value = mlist("foo");
+clear value // will print "deleted"
+]]></programlisting>
     </refsection>
     <refsection role="see also">
         <title>Voir aussi</title>
@@ -79,11 +99,17 @@ isdef("a") | isdef("b") | isdef("c") // F
                 <link linkend="predef">predef</link>
             </member>
             <member>
+                <link linkend="clearglobal">clearglobal</link>
+            </member>
+            <member>
                 <link linkend="funcprot">funcprot</link>
             </member>
             <member>
                 <link linkend="who">who</link>
             </member>
+            <member>
+                <link linkend="xmlDelete">xmlDelete</link>
+            </member>
         </simplelist>
     </refsection>
     <refsection>
@@ -100,6 +126,13 @@ isdef("a") | isdef("b") | isdef("c") // F
                   <literal>clear=1</literal> ne sont plus possibles.
                 </revdescription>
             </revision>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    <literal>clear</literal> devient surchargeable pour toute
+                    <literal>mlist("foo")</literal>, avec <literal>%foo_clear</literal>.
+                </revdescription>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
index 0750d52..bbdd524 100644 (file)
             </note>
         </para>
         <para>
-            コマンド <code>clear</code> は存在しない変数も消去します,
-            すなわち,
-            <code>clear</code> は存在しない変数を存在するものとして
-            消去します.
+            If a name <emphasis>Var</emphasis> matches no variable, <literal>clear Var</literal>
+            does nothing silently.
         </para>
+      <note>
+        <literal>clear()</literal> can be overloaded for any <literal>mlist("foo")</literal> type,
+        by defining a <literal>%foo_clear()</literal> macro. It will be called either when
+        <literal>clear</literal> is explicitly applied to any mlist of this type, or implicitly
+        when any mlist of this type is deleted when leaving the environment where it has been
+        defined.
+      </note>
     </refsection>
     <refsection>
         <title>例</title>
@@ -85,6 +90,14 @@ c = 4;
 clear(['a' 'b' 'c'])
 isdef("a") | isdef("b") | isdef("c") // F
         ]]></programlisting>
+        <programlisting role="example"><![CDATA[
+function %foo_clear(o)
+    disp("deleted");
+endfunction
+
+value = mlist("foo");
+clear value // will print "deleted"
+]]></programlisting>
     </refsection>
     <refsection role="see also">
         <title>参照</title>
@@ -93,11 +106,17 @@ isdef("a") | isdef("b") | isdef("c") // F
                 <link linkend="predef">predef</link>
             </member>
             <member>
+                <link linkend="clearglobal">clearglobal</link>
+            </member>
+            <member>
                 <link linkend="funcprot">funcprot</link>
             </member>
             <member>
                 <link linkend="who">who</link>
             </member>
+            <member>
+                <link linkend="xmlDelete">xmlDelete</link>
+            </member>
         </simplelist>
     </refsection>
     <refsection>
@@ -114,6 +133,13 @@ isdef("a") | isdef("b") | isdef("c") // F
                   Assignments like <literal>clear=1</literal> are no longer possible.
                 </revdescription>
             </revision>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    <literal>clear</literal> becomes overloadable for any
+                    <literal>mlist("foo")</literal>, with <literal>%foo_clear()</literal>.
+                </revdescription>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
index 223590e..7f8bff5 100644 (file)
     </refnamediv>
     <refsynopsisdiv>
         <title>Seqüência de Chamamento</title>
-        <synopsis>clear a</synopsis>
+        <synopsis>
+            clear a b c
+            clear('a', 'b', 'c')
+            clear(['a' 'b' 'c'])
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
+        <title>Parâmetros</title>
+        <variablelist>
+            <varlistentry>
+                <term>a, b, c...</term>
+                <listitem>
+                    <para>variables of any type and size, but not protected</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
         <title>Descrição</title>
         <para>Este comando cancela variáveis que não estão protegidas. Ele remove
             as variáveis nomeadas do ambiente. Por si só, <literal>clear</literal>
             cancela <literal>a</literal> , mas define <literal>a</literal> como uma
             matriz vazia.
         </para>
+        <para>
+            If a name <emphasis>Var</emphasis> matches no variable, <literal>clear Var</literal>
+            does nothing silently.
+        </para>
+      <note>
+        <literal>clear()</literal> can be overloaded for any <literal>mlist("foo")</literal> type,
+        by defining a <literal>%foo_clear()</literal> macro. It will be called either when
+        <literal>clear</literal> is explicitly applied to any mlist of this type, or implicitly
+        when any mlist of this type is deleted when leaving the environment where it has been
+        defined.
+      </note>
+    </refsection>
+    <refsection>
+        <title>Exemplos</title>
+        <programlisting role="example"><![CDATA[
+a = 2;
+b = 3;
+c = 4;
+clear a
+isdef("a") // F
+isdef("b") // T
+clear("b");
+isdef("b") // F
+
+a = 2;
+b = 3;
+c = 4;
+clear(['a' 'b' 'c'])
+isdef("a") | isdef("b") | isdef("c") // F
+     ]]></programlisting>
+        <programlisting role="example"><![CDATA[
+function %foo_clear(o)
+    disp("deleted");
+endfunction
+
+value = mlist("foo");
+clear value // will print "deleted"
+]]></programlisting>
     </refsection>
     <refsection>
         <title> Ver Também </title>
                 <link linkend="predef">predef</link>
             </member>
             <member>
+                <link linkend="clearglobal">clearglobal</link>
+            </member>
+            <member>
                 <link linkend="funcprot">funcprot</link>
             </member>
             <member>
                 <link linkend="who">who</link>
             </member>
+            <member>
+                <link linkend="xmlDelete">xmlDelete</link>
+            </member>
         </simplelist>
     </refsection>
     <refsection role="history">
                   Assignments like <literal>clear=1</literal> are no longer possible.
                 </revdescription>
             </revision>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    <literal>clear</literal> becomes overloadable for any
+                    <literal>mlist("foo")</literal>, with <literal>%foo_clear()</literal>.
+                </revdescription>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
index ba568dc..675db0d 100644 (file)
         <synopsis>
             clear a b c
             clear('a','b','c')
+            clear(['a' 'b' 'c'])
         </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Аргументы</title>
         <variablelist>
             <varlistentry>
-                <term>a,b,c...</term>
+                <term>a, b, c...</term>
                 <listitem>
-                    <para>переменные любого типа и размера, но не защищённые</para>
+                    <para>переменные любого типа и размера, но не защищённые.</para>
                 </listitem>
             </varlistentry>
         </variablelist>
             </note>
         </para>
         <para>
-            Команда <code>clear</code> может работать с несуществующими переменными, т. е.
-            <code>clear</code> уничтожает несуществующие переменные как если бы они существовали.
+            Если имя <emphasis>Var</emphasis> не совпадает ни с одной из переменных, то
+             <literal>clear Var</literal> тихо ничего не делает.
         </para>
+      <note>
+        <literal>clear()</literal> может быть перегружена для любого типа <literal>mlist("foo")</literal>,
+        с помощью определения макроса <literal>%foo_clear()</literal>. Он вызывается либо когда
+        <literal>clear</literal> напрямую применяется к любому mlist-списку этого типа, либо неявно,
+        когда любой mlist-список этого типа удалён при выходе из окружения, в котором он был определён.
+      </note>
     </refsection>
     <refsection>
         <title>Примеры</title>
         <programlisting role="example"><![CDATA[
-a=2;
-b=3;
-c=4;
+a = 2;
+b = 3;
+c = 4;
 clear a
 isdef("a") // F
 isdef("b") // T
 clear("b");
 isdef("b") // F
-        ]]></programlisting>
+
+a = 2;
+b = 3;
+c = 4;
+clear(['a' 'b' 'c'])
+isdef("a") | isdef("b") | isdef("c") // F
+     ]]></programlisting>
+        <programlisting role="example"><![CDATA[
+function %foo_clear(o)
+    disp("deleted");
+endfunction
+
+value = mlist("foo");
+clear value // будет напечатано "deleted"
+]]></programlisting>
     </refsection>
     <refsection role="see also">
         <title>Смотрите также</title>
@@ -84,11 +105,17 @@ isdef("b") // F
                 <link linkend="predef">predef</link>
             </member>
             <member>
+                <link linkend="clearglobal">clearglobal</link>
+            </member>
+            <member>
                 <link linkend="funcprot">funcprot</link>
             </member>
             <member>
                 <link linkend="who">who</link>
             </member>
+            <member>
+                <link linkend="xmlDelete">xmlDelete</link>
+            </member>
         </simplelist>
     </refsection>
     <refsection role="history">
@@ -96,13 +123,20 @@ isdef("b") // F
         <revhistory>
             <revision>
                 <revnumber>5.5.0</revnumber>
-                <revdescription>Argument can now be a matrix of strings</revdescription>
+                <revdescription>Теперь аргумент может быть матрицей строк</revdescription>
             </revision>
             <revision>
                 <revnumber>6.0.0</revnumber>
                 <revdescription>
-                  <literal>clear</literal> is now protected:
-                  Assignments like <literal>clear=1</literal> are no longer possible.
+                  Теперь <literal>clear</literal> защищена:
+                  такие присвоения, как <literal>clear=1</literal>, более невозможны.
+                </revdescription>
+            </revision>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    <literal>clear</literal> становится перегружаемой для любого
+                    <literal>mlist("foo")</literal> с помощью <literal>%foo_clear()</literal>.
                 </revdescription>
             </revision>
         </revhistory>
index 8ad6d04..2ea1b56 100644 (file)
@@ -48,6 +48,7 @@ EXTERNAL_OBJECTS_CPP_SOURCES = \
     src/cpp/convMatrixMethod.cpp \
     src/cpp/deff.cpp \
     src/cpp/display.cpp \
+    src/cpp/clear.cpp \
     src/cpp/doubleExclam_invoke.cpp \
     src/cpp/classExtract.cpp \
     src/cpp/objectExtract.cpp \
@@ -114,7 +115,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_percent_EObj_t.cpp \
        sci_gateway/cpp/sci_doubleExclam_invoke_.cpp \
        sci_gateway/cpp/sci_invoke_lu.cpp \
-       sci_gateway/cpp/sci_percent_EObj_disp.cpp
+       sci_gateway/cpp/sci_percent_EObj_disp.cpp \
+       sci_gateway/cpp/sci_percent_EObj_clear.cpp
 
 libsciexternal_objects_la_CFLAGS= \
     -I$(srcdir)/includes/ \
index f849616..78beee4 100644 (file)
@@ -204,6 +204,7 @@ am__objects_2 =  \
        src/cpp/libsciexternal_objects_algo_la-convMatrixMethod.lo \
        src/cpp/libsciexternal_objects_algo_la-deff.lo \
        src/cpp/libsciexternal_objects_algo_la-display.lo \
+       src/cpp/libsciexternal_objects_algo_la-clear.lo \
        src/cpp/libsciexternal_objects_algo_la-doubleExclam_invoke.lo \
        src/cpp/libsciexternal_objects_algo_la-classExtract.lo \
        src/cpp/libsciexternal_objects_algo_la-objectExtract.lo \
@@ -280,7 +281,8 @@ am__objects_3 = sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_e.lo
        sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_t.lo \
        sci_gateway/cpp/libsciexternal_objects_la-sci_doubleExclam_invoke_.lo \
        sci_gateway/cpp/libsciexternal_objects_la-sci_invoke_lu.lo \
-       sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_disp.lo
+       sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_disp.lo \
+       sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_clear.lo
 am_libsciexternal_objects_la_OBJECTS = $(am__objects_3)
 libsciexternal_objects_la_OBJECTS =  \
        $(am_libsciexternal_objects_la_OBJECTS)
@@ -313,6 +315,7 @@ am__depfiles_remade = sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_do
        sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_4_foo.Plo \
        sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_5.Plo \
        sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_a_foo.Plo \
+       sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_clear.Plo \
        sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_d_foo.Plo \
        sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_disp.Plo \
        sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_e.Plo \
@@ -346,6 +349,7 @@ am__depfiles_remade = sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_do
        src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-array.Plo \
        src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-cast.Plo \
        src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-classExtract.Plo \
+       src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-clear.Plo \
        src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-compile.Plo \
        src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-convMatrixMethod.Plo \
        src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-deff.Plo \
@@ -833,6 +837,7 @@ EXTERNAL_OBJECTS_CPP_SOURCES = \
     src/cpp/convMatrixMethod.cpp \
     src/cpp/deff.cpp \
     src/cpp/display.cpp \
+    src/cpp/clear.cpp \
     src/cpp/doubleExclam_invoke.cpp \
     src/cpp/classExtract.cpp \
     src/cpp/objectExtract.cpp \
@@ -899,7 +904,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_percent_EObj_t.cpp \
        sci_gateway/cpp/sci_doubleExclam_invoke_.cpp \
        sci_gateway/cpp/sci_invoke_lu.cpp \
-       sci_gateway/cpp/sci_percent_EObj_disp.cpp
+       sci_gateway/cpp/sci_percent_EObj_disp.cpp \
+       sci_gateway/cpp/sci_percent_EObj_clear.cpp
 
 libsciexternal_objects_la_CFLAGS = \
     -I$(srcdir)/includes/ \
@@ -1080,6 +1086,8 @@ src/cpp/libsciexternal_objects_algo_la-deff.lo:  \
        src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libsciexternal_objects_algo_la-display.lo:  \
        src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
+src/cpp/libsciexternal_objects_algo_la-clear.lo:  \
+       src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libsciexternal_objects_algo_la-doubleExclam_invoke.lo:  \
        src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libsciexternal_objects_algo_la-classExtract.lo:  \
@@ -1250,6 +1258,9 @@ sci_gateway/cpp/libsciexternal_objects_la-sci_invoke_lu.lo:  \
 sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_disp.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_clear.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 
 libsciexternal_objects.la: $(libsciexternal_objects_la_OBJECTS) $(libsciexternal_objects_la_DEPENDENCIES) $(EXTRA_libsciexternal_objects_la_DEPENDENCIES) 
        $(AM_V_CXXLD)$(libsciexternal_objects_la_LINK) -rpath $(pkglibdir) $(libsciexternal_objects_la_OBJECTS) $(libsciexternal_objects_la_LIBADD) $(LIBS)
@@ -1274,6 +1285,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_4_foo.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_5.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_a_foo.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_clear.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_d_foo.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_disp.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_e.Plo@am__quote@ # am--include-marker
@@ -1307,6 +1319,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-array.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-cast.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-classExtract.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-clear.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-compile.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-convMatrixMethod.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-deff.Plo@am__quote@ # am--include-marker
@@ -1472,6 +1485,13 @@ src/cpp/libsciexternal_objects_algo_la-display.lo: src/cpp/display.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciexternal_objects_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libsciexternal_objects_algo_la-display.lo `test -f 'src/cpp/display.cpp' || echo '$(srcdir)/'`src/cpp/display.cpp
 
+src/cpp/libsciexternal_objects_algo_la-clear.lo: src/cpp/clear.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciexternal_objects_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libsciexternal_objects_algo_la-clear.lo -MD -MP -MF src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-clear.Tpo -c -o src/cpp/libsciexternal_objects_algo_la-clear.lo `test -f 'src/cpp/clear.cpp' || echo '$(srcdir)/'`src/cpp/clear.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-clear.Tpo src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-clear.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/clear.cpp' object='src/cpp/libsciexternal_objects_algo_la-clear.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciexternal_objects_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libsciexternal_objects_algo_la-clear.lo `test -f 'src/cpp/clear.cpp' || echo '$(srcdir)/'`src/cpp/clear.cpp
+
 src/cpp/libsciexternal_objects_algo_la-doubleExclam_invoke.lo: src/cpp/doubleExclam_invoke.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciexternal_objects_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libsciexternal_objects_algo_la-doubleExclam_invoke.lo -MD -MP -MF src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-doubleExclam_invoke.Tpo -c -o src/cpp/libsciexternal_objects_algo_la-doubleExclam_invoke.lo `test -f 'src/cpp/doubleExclam_invoke.cpp' || echo '$(srcdir)/'`src/cpp/doubleExclam_invoke.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-doubleExclam_invoke.Tpo src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-doubleExclam_invoke.Plo
@@ -1927,6 +1947,13 @@ sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_disp.lo: sci_gateway/
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciexternal_objects_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_disp.lo `test -f 'sci_gateway/cpp/sci_percent_EObj_disp.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_percent_EObj_disp.cpp
 
+sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_clear.lo: sci_gateway/cpp/sci_percent_EObj_clear.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciexternal_objects_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_clear.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_clear.Tpo -c -o sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_clear.lo `test -f 'sci_gateway/cpp/sci_percent_EObj_clear.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_percent_EObj_clear.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_clear.Tpo sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_clear.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_percent_EObj_clear.cpp' object='sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_clear.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciexternal_objects_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciexternal_objects_la-sci_percent_EObj_clear.lo `test -f 'sci_gateway/cpp/sci_percent_EObj_clear.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_percent_EObj_clear.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
@@ -2162,6 +2189,7 @@ distclean: distclean-am
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_4_foo.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_5.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_a_foo.Plo
+       -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_clear.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_d_foo.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_disp.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_e.Plo
@@ -2195,6 +2223,7 @@ distclean: distclean-am
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-array.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-cast.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-classExtract.Plo
+       -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-clear.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-compile.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-convMatrixMethod.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-deff.Plo
@@ -2290,6 +2319,7 @@ maintainer-clean: maintainer-clean-am
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_4_foo.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_5.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_a_foo.Plo
+       -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_clear.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_d_foo.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_disp.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libsciexternal_objects_la-sci_percent_EObj_e.Plo
@@ -2323,6 +2353,7 @@ maintainer-clean: maintainer-clean-am
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-array.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-cast.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-classExtract.Plo
+       -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-clear.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-compile.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-convMatrixMethod.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciexternal_objects_algo_la-deff.Plo
index 4e895a0..bce7346 100644 (file)
     <ClCompile Include="sci_gateway\cpp\sci_percent_EObj_4_foo.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_percent_EObj_5.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_percent_EObj_a_foo.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_percent_EObj_clear.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_percent_EObj_disp.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_percent_EObj_d_foo.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_percent_EObj_e.cpp" />
     <ClCompile Include="src\cpp\array.cpp" />
     <ClCompile Include="src\cpp\cast.cpp" />
     <ClCompile Include="src\cpp\classExtract.cpp" />
+    <ClCompile Include="src\cpp\clear.cpp" />
     <ClCompile Include="src\cpp\compile.cpp" />
     <ClCompile Include="src\cpp\convMatrixMethod.cpp" />
     <ClCompile Include="src\cpp\deff.cpp" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
index d5369b9..4138e37 100644 (file)
     <ClCompile Include="sci_gateway\cpp\sci_percent_EObj_a_foo.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_percent_EObj_clear.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="sci_gateway\cpp\sci_percent_EObj_d_foo.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="src\cpp\convMatrixMethod.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="src\cpp\clear.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="src\cpp\deff.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
   <ItemGroup>
     <Xml Include="sci_gateway\external_objects_gateway.xml" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
index 5e4d61f..f2c29ea 100644 (file)
@@ -39,6 +39,8 @@ public:
 
     static int getEnvId(char * fname, const int envId, void * pvApiCtx);
 
+    static int clear(char* fname, const int envId, void* pvApiCtx);
+
     static int getsetOptions(char * fname, const int envId, ScilabAbstractOptionsSetter & setter, void * pvApiCtx);
 
     static int addToClasspath(char * fname, const int envId, void * pvApiCtx);
@@ -77,7 +79,7 @@ public:
 
     static int getClassName(char * fname, const int envId, void * pvApiCtx);
 
-    static int getEnvironmentName(char * fname, const int envId, void * pvApiCtx);
+    static int getEnvironmentName(char* fname, const int envId, void* pvApiCtx);
 
     static int getEnvironmentInfos(char * fname, const int envId, void * pvApiCtx);
 
index c880d36..c5f271d 100644 (file)
@@ -53,6 +53,7 @@ EXTERNAL_OBJECTS_SCILAB_IMPEXP int sci_percent_EObj_t(char * fname, void* pvApiC
 EXTERNAL_OBJECTS_SCILAB_IMPEXP int sci_invoke_lu(char * fname, void* pvApiCtx);
 EXTERNAL_OBJECTS_SCILAB_IMPEXP int sci_doubleExclam_invoke_(char * fname, void* pvApiCtx);
 EXTERNAL_OBJECTS_SCILAB_IMPEXP int sci_percent_EObj_disp(char * fname, void* pvApiCtx);
+EXTERNAL_OBJECTS_SCILAB_IMPEXP int sci_percent_EObj_clear(char* fname, void* pvApiCtx);
 /*--------------------------------------------------------------------------*/
 #endif /* __GW_EXTERNAL_OBJECTS_H__ */
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/external_objects/sci_gateway/cpp/sci_percent_EObj_clear.cpp b/scilab/modules/external_objects/sci_gateway/cpp/sci_percent_EObj_clear.cpp
new file mode 100644 (file)
index 0000000..0d13ec2
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2018 - ESI Group - Clement DAVID
+ *
+ * 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.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
+ *
+ */
+
+#include "ScilabGateway.hxx"
+
+extern "C" {
+#include "Scierror.h"
+#include "gw_external_objects.h"
+}
+
+using namespace org_modules_external_objects;
+
+int sci_percent_EObj_clear(char * fname, void* pvApiCtx)
+{
+    try
+    {
+        return ScilabGateway::clear(fname, 0, pvApiCtx);
+    }
+    catch (std::exception & e)
+    {
+        Scierror(999, _("%s: An error occurred: %s"), fname, e.what());
+        return 0;
+    }
+}
index d57a3e1..3598bb3 100644 (file)
@@ -225,4 +225,5 @@ Don't touch if you do not know what you are doing
     <gateway name="sci_invoke_lu"            function="invoke_lu" type="0"/>
     <gateway name="sci_doubleExclam_invoke_" function="!!_invoke_" type="0"/>
     <gateway name="sci_percent_EObj_disp"    function="%_EObj_disp" type="0"/>
+    <gateway name="sci_percent_EObj_clear"   function="%_EObj_clear" type="0"/>
 </module>
diff --git a/scilab/modules/external_objects/src/cpp/clear.cpp b/scilab/modules/external_objects/src/cpp/clear.cpp
new file mode 100644 (file)
index 0000000..1df35db
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2018 - ESI Group - Clement DAVID
+ *
+ * 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.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
+ *
+ */
+
+#include "ScilabGateway.hxx"
+
+namespace org_modules_external_objects
+{
+
+int ScilabGateway::clear(char * fname, const int envId, void * pvApiCtx)
+{
+    SciErr err;
+    int * addr = 0;
+    int row = 0, col = 0;
+    int * id = 0;
+    int eId;
+
+    CheckInputArgument(pvApiCtx, 1, 1);
+
+    ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
+    ScilabGatewayOptions & options = env.getGatewayOptions();
+    OptionsHelper::setCopyOccurred(false);
+    ScilabObjects::initialization(env, pvApiCtx);
+    options.setIsNew(false);
+
+    err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
+    if (err.iErr)
+    {
+        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
+    }
+
+    if (!ScilabObjects::isExternalObj(addr, pvApiCtx) && !ScilabObjects::isExternalClass(addr, pvApiCtx))
+    {
+        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: External Object expected."), 1);
+    }
+
+    eId = ScilabObjects::getEnvironmentId(addr, pvApiCtx);
+    if (eId != envId)
+    {
+        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Incompatible External Object"));
+    }
+
+    err = getMatrixOfInteger32InList(pvApiCtx, addr, EXTERNAL_OBJ_ID_POSITION, &row, &col, &id);
+    if (err.iErr)
+    {
+        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
+    }
+
+    env.removeobject(*id);
+
+    PutLhsVar();
+
+    return 0;
+}
+}
index f6af9cb..9f3842a 100644 (file)
@@ -24,9 +24,9 @@
         <title>Syntax</title>
         <synopsis>
             jremove()
-            jremove(varName_1 [, varName_2, ...])
-            jremove varName_1 [varName_2 ...]
-            jremove(object_1 [, object_2 ...])
+            jremove(varName_1, varName_2, ...)
+            jremove varName_1  varName_2 ...
+            jremove(object_1 , object_2, ...)
         </synopsis>
     </refsynopsisdiv>
     <refsection>
                s = String.new("Hello world");
                jremove s;
       ]]></programlisting>
+        <para/>
+        <programlisting role="example"><![CDATA[
+               jimport java.lang.String;
+
+               s = String.new("Hello world");
+               clear s;
+      ]]></programlisting>
     </refsection>
     <refsection role="see also">
         <title>See also</title>
                     Function introduced. Based on the 'JIMS' module. The main difference in the behavior compared to the JIMS module is that <link linkend="jautoUnwrap">jautoUnwrap</link> is enabled by default.
                 </revremark>
             </revision>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revremark>
+                    This function is optional, as <link linkend="clear">clear</link> or scope
+                    closing will now release the associated Java object.
+                </revremark>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
index 4e746bc..64b34a4 100644 (file)
         <title>呼び出し手順</title>
 
         <synopsis>
-
             jremove()
-
-            jremove(varName_1 [, varName_2, ...])
-
-            jremove varName_1 [varName_2 ...]
-
-            jremove(object_1 [, object_2 ...])
-
+            jremove(varName_1, varName_2, ...)
+            jremove varName_1  varName_2 ...
+            jremove(object_1 , object_2, ...)
         </synopsis>
 
     </refsynopsisdiv>
                s = String.new("Hello world");
                jremove s;
       ]]></programlisting>
+        <para/>
+        <programlisting role="example"><![CDATA[
+               jimport java.lang.String;
 
+               s = String.new("Hello world");
+               clear s;
+      ]]></programlisting>
     </refsection>
 
     <refsection role="see also">
                 </revremark>
 
             </revision>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revremark>
+                    This function is optional, as <link linkend="clear">clear</link> or scope
+                    closing will now release the associated Java object.
+                </revremark>
+            </revision>
 
         </revhistory>
 
diff --git a/scilab/modules/external_objects_java/tests/unit_tests/clear.tst b/scilab/modules/external_objects_java/tests/unit_tests/clear.tst
new file mode 100644 (file)
index 0000000..59e71a1
--- /dev/null
@@ -0,0 +1,83 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2018 - ESI Group - Clement DAVID
+//
+// <-- NO CHECK REF -->
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+
+
+
+
+
+jimport java.lang.System
+
+klass = jcompile("Test", ["public class Test {"
+"static int counter = 0;"
+""
+"public Test() {"
+"    counter++;"
+"}"
+""
+"protected void finalize() throws Throwable {"
+"    counter--;"
+"}"
+""
+"public static double getClassCounter() {";
+"    return counter;";
+"}"
+""
+"public double getCounter() {";
+"    return counter;";
+"}"
+""
+"}"]);
+
+//
+// Allocate an object and manipulate it
+//
+
+a = klass.new();
+b = a;
+
+assert_checktrue(a.equals(b));
+assert_checkequal(a.counter, b.counter);
+
+counter = b.counter
+
+clear b
+System.gc();
+sleep(1,"s"); // to let the GC do the job
+
+assert_checkequal(a.counter, counter);
+clear a
+
+//
+// allocate some objects and clear all of them through Scilab mechanism
+//
+
+l = list();
+for i=1:100
+    l($+1) = klass.new();
+end
+
+System.gc();
+sleep(1,"s"); // to let the GC do the job
+
+allocated = klass.new();
+assert_checkequal(allocated.counter, 100+1);
+
+clear l
+System.gc();
+sleep(1,"s"); // to let the GC do the job
+
+assert_checkequal(allocated.counter, 1);
+
+clear allocated
+System.gc();
+sleep(1,"s"); // to let the GC do the job
+
+assert_checkequal(klass.getClassCounter(), 0);
+
diff --git a/scilab/modules/external_objects_java/tests/unit_tests/jremove.tst b/scilab/modules/external_objects_java/tests/unit_tests/jremove.tst
new file mode 100644 (file)
index 0000000..c8a5e77
--- /dev/null
@@ -0,0 +1,73 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2019 - ESI Group - Clement DAVID
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- NO CHECK REF -->
+//
+// =============================================================================
+
+jimport java.lang.Runtime
+jimport java.lang.String
+runtime = Runtime.getRuntime()
+
+// construct a big java.lang.String object
+LENGTH =  2**18;
+SIZEOF_STR = 36 + LENGTH*2; // per string on the Java side
+function str = alloc()
+    str = jnewInstance(String, int8(grand(1,LENGTH, "unf", 32, 124)));
+endfunction
+
+function F()
+    jimport java.lang.String
+    str = alloc()
+
+    jremove(str)
+    jremove(String)
+endfunction
+
+function G()
+    jimport java.lang.String
+    str = alloc()
+
+    //  let the scope cleanup do the job
+    //    jremove(str)
+    //    jremove(String)
+endfunction
+
+color=1;
+N=100;
+for i=1:N
+    F();
+    times(color,i) = (runtime.totalMemory() - runtime.freeMemory());
+end
+color = color+1;
+for i=1:N
+    G();
+    times(color,i) = (runtime.totalMemory() - runtime.freeMemory());
+end
+color = color+1;
+for i=1:N
+    execstr("str"+string(i)+" = alloc();");
+    clear("str"+string(i));
+    times(color,i) = (runtime.totalMemory() - runtime.freeMemory());
+end
+color = color+1;
+for i=1:N
+    execstr("str"+string(i)+" = alloc();");
+    jremove("str"+string(i));
+    clear("str"+string(i));
+    times(color,i) = (runtime.totalMemory() - runtime.freeMemory());
+end
+color = color+1;
+for i=1:N
+    l = list(alloc());
+    clear("l");
+    times(color,i) = (runtime.totalMemory() - runtime.freeMemory());
+end
+
+// plot(times'); // to debug; this should look like GC-cycles
+M = double(max(times, "c"));
+assert_checktrue(M < (2 * N * SIZEOF_STR));
diff --git a/scilab/modules/overloading/tests/unit_tests/clear.tst b/scilab/modules/overloading/tests/unit_tests/clear.tst
new file mode 100644 (file)
index 0000000..fd5b241
--- /dev/null
@@ -0,0 +1,57 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2018 - ESI Group - Clement DAVID
+//
+// <-- NO CHECK REF -->
+// <-- CLI SHELL MODE -->
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+global cleared_b_called
+
+a = mlist(["my_type" "name"], "a");
+b = mlist(["my_type" "name"], "b");
+
+// %my_type_clear() will be called with "b"
+function %my_type_clear(v)
+    global cleared_b_called
+    assert_checkequal(cleared_b_called, [])
+    cleared_b_called = 1
+    assert_checkequal(v.name, "b")
+endfunction
+clear b
+assert_checkequal(cleared_b_called, 1)
+
+function foo1()
+    c = mlist(["my_type" "name"], "c");
+    // %my_type_clear() will be called with "c"
+endfunction
+function %my_type_clear(v)
+    assert_checkequal(v.name, "c")
+endfunction
+foo1()
+
+function foo2()
+    ac = a;
+    // %my_type_clear() will not be called
+endfunction
+function %my_type_clear(v)
+    pause
+endfunction
+foo2()
+
+// aa is a reference to a containing the same data
+aa = a;
+
+// %my_type_clear() will be called with "a" only once
+function %my_type_clear(v)
+    global cleared_a_called
+    assert_checkequal(cleared_a_called, [])
+    cleared_a_called = 1
+    assert_checkequal(v.name, "a")
+endfunction
+clear aa
+clear a
+
+