fix elementary_functions memory leak in tests 66/16366/3
Antoine ELIAS [Tue, 14 Apr 2015 09:33:12 +0000 (11:33 +0200)]
Change-Id: Icb8ca033e4c4b05eabae7b94bba827f2c88c62ca

20 files changed:
scilab/modules/elementary_functions/includes/elem_func_gw.hxx
scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_abs.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_acosh.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_asinh.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_atanh.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_conj.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_cosh.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_cumprod.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_cumsum.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_max.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_prod.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_sinh.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_sum.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_tanh.cpp
scilab/modules/elementary_functions/src/c/DllmainElementary_functions.c
scilab/modules/elementary_functions/src/cpp/prod.cpp
scilab/modules/elementary_functions/src/cpp/sum.cpp
scilab/modules/linear_algebra/sci_gateway/cpp/sci_spec.cpp
scilab/modules/polynomials/sci_gateway/cpp/sci_roots.cpp

index 8e68eee..616ba89 100644 (file)
@@ -93,7 +93,7 @@ types::Double* getAsDouble(T* _val)
 {
     types::Double* dbl = new types::Double(_val->getDims(), _val->getDimsArray());
     double* pOut = dbl->get();
-    auto* pIn = _val->get();
+    typename T::type* pIn = _val->get();
     int size = dbl->getSize();
     for (int i = 0; i < size; i++)
     {
@@ -103,16 +103,16 @@ types::Double* getAsDouble(T* _val)
     return dbl;
 }
 
-template <class T, typename U>
+template <class T>
 T* toInt(types::Double* _dbl)
 {
     T* pI = new T(_dbl->getDims(), _dbl->getDimsArray());
-    U* p = pI->get();
+    typename T::type* p = pI->get();
     double* pdbl = _dbl->get();
     int size = _dbl->getSize();
     for (int i = 0; i < size; i++)
     {
-        p[i] = static_cast<U>(pdbl[i]);
+        p[i] = static_cast<typename T::type>(pdbl[i]);
     }
 
     return pI;
index a426939..319554a 100644 (file)
 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 *
 */
+//for Visual Leak Detector
+#ifdef DEBUG_VLD
+#include <vld.h>
+#endif
 
 #include "elem_func_gw.hxx"
 #include "context.hxx"
index 0a9b158..dbb2987 100644 (file)
@@ -104,6 +104,8 @@ types::Function::ReturnValue sci_abs(types::typed_list &in, int _iRetCount, type
             }
 
             out.push_back(api_scilab::getReturnVariable(pDblOut));
+            delete pDblOut;
+            delete pDblIn;
             break;
         }
         case InternalType::ScilabPolynom:
index 3d99596..52a135c 100644 (file)
@@ -112,8 +112,9 @@ types::Function::ReturnValue sci_acosh(types::typed_list &in, int _iRetCount, ty
     }
     else
     {
+        ast::ExecVisitor exec;
         std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_acosh";
-        return Overload::call(wstFuncName, in, _iRetCount, out, new ast::ExecVisitor());
+        return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
     }
 
     return types::Function::OK;
index eb560b4..815e33b 100644 (file)
@@ -79,8 +79,9 @@ types::Function::ReturnValue sci_asinh(types::typed_list &in, int _iRetCount, ty
     }
     else
     {
+        ast::ExecVisitor exec;
         std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_asinh";
-        return Overload::call(wstFuncName, in, _iRetCount, out, new ast::ExecVisitor());
+        return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
     }
 
     return types::Function::OK;
index c332d17..ab6e171 100644 (file)
@@ -79,8 +79,9 @@ types::Function::ReturnValue sci_atanh(types::typed_list &in, int _iRetCount, ty
     }
     else
     {
+        ast::ExecVisitor exec;
         std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_atanh";
-        return Overload::call(wstFuncName, in, _iRetCount, out, new ast::ExecVisitor());
+        return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
     }
 
     return types::Function::OK;
index 8288b3a..f36acd2 100644 (file)
@@ -76,6 +76,7 @@ types::Function::ReturnValue sci_conj(types::typed_list &in, int _iRetCount, typ
     {
         pPolyOut->setCoef(pDblOut);
         out.push_back(pPolyOut);
+        pDblOut->killMe();
     }
 
     return types::Function::OK;
index a34ea1a..85bebc8 100644 (file)
@@ -79,8 +79,9 @@ types::Function::ReturnValue sci_cosh(types::typed_list &in, int _iRetCount, typ
     }
     else
     {
+        ast::ExecVisitor exec;
         std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_cosh";
-        return Overload::call(wstFuncName, in, _iRetCount, out, new ast::ExecVisitor());
+        return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
     }
 
     return types::Function::OK;
index 6d13f1e..8d1a510 100644 (file)
@@ -53,11 +53,13 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
         return types::Function::Error;
     }
 
+    bool isCloned = true;
     /***** get data *****/
     switch (in[0]->getType())
     {
         case InternalType::ScilabDouble :
             pDblIn = in[0]->getAs<types::Double>();
+            isCloned = false;
             break;
         case InternalType::ScilabBool:
             pDblIn = getAsDouble(in[0]->getAs<types::Bool>());
@@ -65,6 +67,7 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
             break;
         case InternalType::ScilabPolynom :
             pPolyIn = in[0]->getAs<types::Polynom>();
+            isCloned = false;
             break;
         case InternalType::ScilabInt8:
             pDblIn = getAsDouble(in[0]->getAs<types::Int8>());
@@ -104,6 +107,11 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
 
             if (pDbl->isScalar() == false)
             {
+                if (isCloned)
+                {
+                    pDblIn->killMe();
+                }
+
                 Scierror(999, _("%s: Wrong value for input argument #%d: A positive scalar expected.\n"), "cumprod", 2);
                 return types::Function::Error;
             }
@@ -112,6 +120,11 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
 
             if (iOrientation <= 0)
             {
+                if (isCloned)
+                {
+                    pDblIn->killMe();
+                }
+
                 Scierror(999, _("%s: Wrong value for input argument #%d: A positive scalar expected.\n"), "cumprod", 2);
                 return types::Function::Error;
             }
@@ -122,6 +135,11 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
 
             if (pStr->isScalar() == false)
             {
+                if (isCloned)
+                {
+                    pDblIn->killMe();
+                }
+
                 Scierror(999, _("%s: Wrong size for input argument #%d: A scalar string expected.\n"), "cumprod", 2);
                 return types::Function::Error;
             }
@@ -186,12 +204,22 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
                     pstrExpected = "\"*\",\"r\",\"c\",\"m\"";
                 }
 
+                if (isCloned)
+                {
+                    pDblIn->killMe();
+                }
+
                 Scierror(999, _("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), "cumprod", 2, pstrExpected);
                 return types::Function::Error;
             }
         }
         else
         {
+            if (isCloned)
+            {
+                pDblIn->killMe();
+            }
+
             Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix or a string expected.\n"), "cumprod", 2);
             return types::Function::Error;
         }
@@ -201,6 +229,11 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
     {
         if (in[2]->isString() == false)
         {
+            if (isCloned)
+            {
+                pDblIn->killMe();
+            }
+
             Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), "cumprod", 3);
             return types::Function::Error;
         }
@@ -209,6 +242,11 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
 
         if (pStr->isScalar() == false)
         {
+            if (isCloned)
+            {
+                pDblIn->killMe();
+            }
+
             Scierror(999, _("%s: Wrong size for input argument #%d: A scalar string expected.\n"), "cumprod", 3);
             return types::Function::Error;
         }
@@ -225,6 +263,11 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
         }
         else
         {
+            if (isCloned)
+            {
+                pDblIn->killMe();
+            }
+
             Scierror(999, _("%s: Wrong value for input argument #%d: %s or %s expected.\n"), "cumprod", 3, "\"native\"", "\"double\"");
             return types::Function::Error;
         }
@@ -253,7 +296,7 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
         {
             pDblOut = new types::Double(pDblIn->getDims(), pDblIn->getDimsArray(), pDblIn->isComplex());
             cumprod(pDblIn, iOrientation, pDblOut);
-            if (in[0]->isDouble() == false)
+            if (isCloned)
             {
                 delete pDblIn;
                 pDblIn = NULL;
@@ -300,42 +343,42 @@ types::Function::ReturnValue sci_cumprod(types::typed_list &in, int _iRetCount,
             }
             case InternalType::ScilabInt8:
             {
-                out.push_back(toInt<types::Int8, char>(pDblOut));
+                out.push_back(toInt<types::Int8>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt16:
             {
-                out.push_back(toInt<types::Int16, short>(pDblOut));
+                out.push_back(toInt<types::Int16>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt32:
             {
-                out.push_back(toInt<types::Int32, int>(pDblOut));
+                out.push_back(toInt<types::Int32>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt64:
             {
-                out.push_back(toInt<types::Int64, long long>(pDblOut));
+                out.push_back(toInt<types::Int64>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt8:
             {
-                out.push_back(toInt<types::UInt8, unsigned char>(pDblOut));
+                out.push_back(toInt<types::UInt8>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt16:
             {
-                out.push_back(toInt<types::UInt16, unsigned short>(pDblOut));
+                out.push_back(toInt<types::UInt16>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt32:
             {
-                out.push_back(toInt<types::UInt32, unsigned int>(pDblOut));
+                out.push_back(toInt<types::UInt32>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt64:
             {
-                out.push_back(toInt<types::UInt64, unsigned long long>(pDblOut));
+                out.push_back(toInt<types::UInt64>(pDblOut));
                 break;
             }
         }
index 61facb9..4e8df6d 100644 (file)
@@ -52,11 +52,13 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
         return types::Function::Error;
     }
 
+    bool isCloned = true;
     /***** get data *****/
     switch (in[0]->getType())
     {
         case InternalType::ScilabDouble:
             pDblIn = in[0]->getAs<types::Double>();
+            isCloned = false;
             break;
         case InternalType::ScilabBool:
             pDblIn = getAsDouble(in[0]->getAs<types::Bool>());
@@ -64,6 +66,7 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
             break;
         case InternalType::ScilabPolynom:
             pPolyIn = in[0]->getAs<types::Polynom>();
+            isCloned = false;
             break;
         case InternalType::ScilabInt8:
             pDblIn = getAsDouble(in[0]->getAs<types::Int8>());
@@ -104,6 +107,11 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
 
             if (pDbl->isScalar() == false)
             {
+                if (isCloned)
+                {
+                    pDblIn->killMe();
+                }
+
                 Scierror(999, _("%s: Wrong value for input argument #%d: A positive scalar expected.\n"), "cumsum", 2);
                 return types::Function::Error;
             }
@@ -112,6 +120,11 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
 
             if (iOrientation <= 0)
             {
+                if (isCloned)
+                {
+                    pDblIn->killMe();
+                }
+
                 Scierror(999, _("%s: Wrong value for input argument #%d: A positive scalar expected.\n"), "cumsum", 2);
                 return types::Function::Error;
             }
@@ -122,6 +135,11 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
 
             if (pStr->isScalar() == false)
             {
+                if (isCloned)
+                {
+                    pDblIn->killMe();
+                }
+
                 Scierror(999, _("%s: Wrong size for input argument #%d: A scalar string expected.\n"), "cumsum", 2);
                 return types::Function::Error;
             }
@@ -186,12 +204,22 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
                     pstrExpected = "\"*\",\"r\",\"c\",\"m\"";
                 }
 
+                if (isCloned)
+                {
+                    pDblIn->killMe();
+                }
+
                 Scierror(999, _("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), "cumsum", 2, pstrExpected);
                 return types::Function::Error;
             }
         }
         else
         {
+            if (isCloned)
+            {
+                pDblIn->killMe();
+            }
+
             Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix or a string expected.\n"), "cumsum", 2);
             return types::Function::Error;
         }
@@ -201,6 +229,11 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
     {
         if (in[2]->isString() == false)
         {
+            if (isCloned)
+            {
+                pDblIn->killMe();
+            }
+
             Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), "cumsum", 3);
             return types::Function::Error;
         }
@@ -209,6 +242,11 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
 
         if (pStr->isScalar() == false)
         {
+            if (isCloned)
+            {
+                pDblIn->killMe();
+            }
+
             Scierror(999, _("%s: Wrong size for input argument #%d: A scalar string expected.\n"), "cumsum", 3);
             return types::Function::Error;
         }
@@ -225,6 +263,11 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
         }
         else
         {
+            if (isCloned)
+            {
+                pDblIn->killMe();
+            }
+
             Scierror(999, _("%s: Wrong value for input argument #%d: %s or %s expected.\n"), "cumsum", 3, "\"native\"", "\"double\"");
             return types::Function::Error;
         }
@@ -253,7 +296,7 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
         {
             pDblOut = new types::Double(pDblIn->getDims(), pDblIn->getDimsArray(), pDblIn->isComplex());
             cumsum(pDblIn, iOrientation, pDblOut);
-            if (in[0]->isDouble() == false)
+            if (isCloned)
             {
                 delete pDblIn;
                 pDblIn = NULL;
@@ -303,42 +346,42 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
             }
             case InternalType::ScilabInt8:
             {
-                out.push_back(toInt<types::Int8, char>(pDblOut));
+                out.push_back(toInt<types::Int8>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt16:
             {
-                out.push_back(toInt<types::Int16, short>(pDblOut));
+                out.push_back(toInt<types::Int16>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt32:
             {
-                out.push_back(toInt<types::Int32, int>(pDblOut));
+                out.push_back(toInt<types::Int32>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt64:
             {
-                out.push_back(toInt<types::Int64, long long>(pDblOut));
+                out.push_back(toInt<types::Int64>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt8:
             {
-                out.push_back(toInt<types::UInt8, unsigned char>(pDblOut));
+                out.push_back(toInt<types::UInt8>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt16:
             {
-                out.push_back(toInt<types::UInt16, unsigned short>(pDblOut));
+                out.push_back(toInt<types::UInt16>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt32:
             {
-                out.push_back(toInt<types::UInt32, unsigned int>(pDblOut));
+                out.push_back(toInt<types::UInt32>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt64:
             {
-                out.push_back(toInt<types::UInt64, unsigned long long>(pDblOut));
+                out.push_back(toInt<types::UInt64>(pDblOut));
                 break;
             }
         }
index 8121bf8..a2c0e1f 100644 (file)
@@ -95,7 +95,7 @@ types::Function::ReturnValue sci_MinMax(types::typed_list &in, int _iRetCount, t
     if (inputs[0]->isDouble() == false && inputs[0]->isInt() == false)
     {
         wchar_t* wcsMinMax = to_wide_string(fname);
-        std::wstring wstFuncName = L"%"  + inputs[0]->getShortTypeStr() + L"_" + wcsMinMax;
+        std::wstring wstFuncName = L"%" + inputs[0]->getShortTypeStr() + L"_" + wcsMinMax;
         FREE(wcsMinMax);
         ast::ExecVisitor exec;
         return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
@@ -346,11 +346,11 @@ types::Function::ReturnValue sci_MinMax(types::typed_list &in, int _iRetCount, t
         {
             if (iSigned)
             {
-                out.push_back(toInt<types::Int8, char>(pDblOut));
+                out.push_back(toInt<types::Int8>(pDblOut));
             }
             else
             {
-                out.push_back(toInt<types::UInt8, unsigned char>(pDblOut));
+                out.push_back(toInt<types::UInt8>(pDblOut));
             }
             break;
         }
@@ -358,11 +358,11 @@ types::Function::ReturnValue sci_MinMax(types::typed_list &in, int _iRetCount, t
         {
             if (iSigned)
             {
-                out.push_back(toInt<types::Int16, short>(pDblOut));
+                out.push_back(toInt<types::Int16>(pDblOut));
             }
             else
             {
-                out.push_back(toInt<types::UInt16, unsigned short>(pDblOut));
+                out.push_back(toInt<types::UInt16>(pDblOut));
             }
             break;
         }
@@ -370,11 +370,11 @@ types::Function::ReturnValue sci_MinMax(types::typed_list &in, int _iRetCount, t
         {
             if (iSigned)
             {
-                out.push_back(toInt<types::Int32, int>(pDblOut));
+                out.push_back(toInt<types::Int32>(pDblOut));
             }
             else
             {
-                out.push_back(toInt<types::UInt32, unsigned int>(pDblOut));
+                out.push_back(toInt<types::UInt32>(pDblOut));
             }
             break;
         }
@@ -382,11 +382,11 @@ types::Function::ReturnValue sci_MinMax(types::typed_list &in, int _iRetCount, t
         {
             if (iSigned)
             {
-                out.push_back(toInt<types::Int64, long long>(pDblOut));
+                out.push_back(toInt<types::Int64>(pDblOut));
             }
             else
             {
-                out.push_back(toInt<types::UInt64, unsigned long long>(pDblOut));
+                out.push_back(toInt<types::UInt64>(pDblOut));
             }
             break;
         }
index 0d4552d..d693099 100644 (file)
@@ -383,42 +383,42 @@ types::Function::ReturnValue sci_prod(types::typed_list &in, int _iRetCount, typ
             }
             case InternalType::ScilabInt8:
             {
-                out.push_back(toInt<types::Int8, char>(pDblOut));
+                out.push_back(toInt<types::Int8>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt16:
             {
-                out.push_back(toInt<types::Int16, short>(pDblOut));
+                out.push_back(toInt<types::Int16>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt32:
             {
-                out.push_back(toInt<types::Int32, int>(pDblOut));
+                out.push_back(toInt<types::Int32>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt64:
             {
-                out.push_back(toInt<types::Int64, long long>(pDblOut));
+                out.push_back(toInt<types::Int64>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt8:
             {
-                out.push_back(toInt<types::UInt8, unsigned char>(pDblOut));
+                out.push_back(toInt<types::UInt8>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt16:
             {
-                out.push_back(toInt<types::UInt16, unsigned short>(pDblOut));
+                out.push_back(toInt<types::UInt16>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt32:
             {
-                out.push_back(toInt<types::UInt32, unsigned int>(pDblOut));
+                out.push_back(toInt<types::UInt32>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt64:
             {
-                out.push_back(toInt<types::UInt64, unsigned long long>(pDblOut));
+                out.push_back(toInt<types::UInt64>(pDblOut));
                 break;
             }
         }
index 7e16caf..9e32cd7 100644 (file)
@@ -79,8 +79,9 @@ types::Function::ReturnValue sci_sinh(types::typed_list &in, int _iRetCount, typ
     }
     else
     {
+        ast::ExecVisitor exec;
         std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_sinh";
-        return Overload::call(wstFuncName, in, _iRetCount, out, new ast::ExecVisitor());
+        return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
     }
 
     return types::Function::OK;
index 1d33547..629a3ec 100644 (file)
@@ -380,42 +380,42 @@ types::Function::ReturnValue sci_sum(types::typed_list &in, int _iRetCount, type
             }
             case InternalType::ScilabInt8:
             {
-                out.push_back(toInt<types::Int8, char>(pDblOut));
+                out.push_back(toInt<types::Int8>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt16:
             {
-                out.push_back(toInt<types::Int16, short>(pDblOut));
+                out.push_back(toInt<types::Int16>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt32:
             {
-                out.push_back(toInt<types::Int32, int>(pDblOut));
+                out.push_back(toInt<types::Int32>(pDblOut));
                 break;
             }
             case InternalType::ScilabInt64:
             {
-                out.push_back(toInt<types::Int64, long long>(pDblOut));
+                out.push_back(toInt<types::Int64>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt8:
             {
-                out.push_back(toInt<types::UInt8, unsigned char>(pDblOut));
+                out.push_back(toInt<types::UInt8>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt16:
             {
-                out.push_back(toInt<types::UInt16, unsigned short>(pDblOut));
+                out.push_back(toInt<types::UInt16>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt32:
             {
-                out.push_back(toInt<types::UInt32, unsigned int>(pDblOut));
+                out.push_back(toInt<types::UInt32>(pDblOut));
                 break;
             }
             case InternalType::ScilabUInt64:
             {
-                out.push_back(toInt<types::UInt64, unsigned long long>(pDblOut));
+                out.push_back(toInt<types::UInt64>(pDblOut));
                 break;
             }
         }
index 30ba2d6..1196459 100644 (file)
@@ -79,8 +79,9 @@ types::Function::ReturnValue sci_tanh(types::typed_list &in, int _iRetCount, typ
     }
     else
     {
+        ast::ExecVisitor exec;
         std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_tanh";
-        return Overload::call(wstFuncName, in, _iRetCount, out, new ast::ExecVisitor());
+        return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
     }
 
     return types::Function::OK;
index d3d8175..b74129d 100644 (file)
  */
 
 #include <windows.h>
+
+//for Visual Leak Detector
+#ifdef DEBUG_VLD
+#include <vld.h>
+#endif
+
 /*--------------------------------------------------------------------------*/
 #pragma comment(lib,"../../../../bin/libintl.lib")
 /*--------------------------------------------------------------------------*/
index bca7873..2a7c4b3 100644 (file)
@@ -214,6 +214,8 @@ types::Polynom* prod(types::Polynom* pIn, int iOrientation)
 
             delete pdblTempReal;
         }
+
+        delete[]piRanks;
     }
     else // sum following a dimension
     {
@@ -325,7 +327,6 @@ types::Polynom* prod(types::Polynom* pIn, int iOrientation)
         {
             // alloc temporary workspace
             double* pdblTempReal = new double[iMaxOutputRank + 1];
-            double* pdblTempImg  = new double[iMaxOutputRank + 1];
 
             // init output to a matrix of 1 + 0s + 0s²...
             for (int i = 0; i < pOut->getSize(); i++)
@@ -359,6 +360,11 @@ types::Polynom* prod(types::Polynom* pIn, int iOrientation)
 
             delete pdblTempReal;
         }
+
+        delete[] piRankMax;
+        delete[] piRanks;
+        delete[] piIndex;
+        delete[] piDims;
     }
 
     pOut->updateRank();
index 9bd1df4..4eed734 100644 (file)
@@ -196,7 +196,7 @@ types::Polynom* sum(types::Polynom* pIn, int iOrientation)
             int iIndex = pDblRanksOut->getIndex(piIndex);
             pdblOut[iIndex] = std::max(pdblOut[iIndex], pdblIn[i]);
         }
-        
+
         pDblRanks->killMe();
 
         // move output ranks from types::Double to int*
@@ -257,6 +257,10 @@ types::Polynom* sum(types::Polynom* pIn, int iOrientation)
                 }
             }
         }
+
+        delete[] piRanks;
+        delete[] piIndex;
+        delete[] piDims;
     }
 
     return pOut;
index 48e8df4..10355a7 100644 (file)
@@ -33,14 +33,12 @@ bool isNoZeroImag(types::Double* _pDbl);
 
 types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
-    types::Double* pDblA    = NULL;
-    types::Double* pDblB    = NULL;
     double* pDataA          = NULL;
     double* pDataB          = NULL;
     bool symmetric          = FALSE;
     int iRet                = 0;
 
-    if ((in.size() != 1) && (in.size() != 2))
+    if (in.size() != 1 && in.size() != 2)
     {
         Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "spec", 1, 2);
         return types::Function::Error;
@@ -52,27 +50,28 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
         return types::Function::Error;
     }
 
-    if ((in[0]->isDouble() == false))
+    if (in[0]->isDouble() == false)
     {
         ast::ExecVisitor exec;
         std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_spec";
         return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
     }
-    pDblA = in[0]->clone()->getAs<types::Double>();
 
-    if (pDblA->getCols() != pDblA->getRows())
+    types::Double* in0 = in[0]->getAs<types::Double>();
+
+    if (in0->getCols() != in0->getRows())
     {
         Scierror(20, _("%s: Wrong type for input argument #%d: Square matrix expected.\n"), "spec", 1);
         return types::Function::Error;
     }
 
-    if ((pDblA->getRows() == -1) || (pDblA->getCols() == -1)) // manage eye case
+    if (in0->getRows() == -1 || in0->getCols() == -1) // manage eye case
     {
         Scierror(271, _("%s: Size varying argument a*eye(), (arg %d) not allowed here.\n"), "spec", 1);
         return types::Function::Error;
     }
 
-    if ((pDblA->getCols() == 0) || (pDblA->getRows() == 0)) // size null
+    if (in0->getCols() == 0 || in0->getRows() == 0) // size null
     {
         out.push_back(types::Double::Empty());
         for (int i = 1; i < _iRetCount; i++)
@@ -82,6 +81,8 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
         return types::Function::OK;
     }
 
+    types::Double* pDblA = in0->clone()->getAs<types::Double>();
+
     if (in.size() == 1)
     {
         types::Double* pDblEigenValues  = NULL;
@@ -92,6 +93,7 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
             pDataA = (double*)oGetDoubleComplexFromPointer(pDblA->getReal(), pDblA->getImg(), pDblA->getSize());
             if (!pDataA)
             {
+                pDblA->killMe();
                 Scierror(999, _("%s: Cannot allocate more memory.\n"), "spec");
                 return types::Function::Error;
             }
@@ -104,6 +106,11 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
         int totalSize = pDblA->getSize();
         if ((pDblA->isComplex() ? C2F(vfiniteComplex)(&totalSize, (doublecomplex*)pDataA) : C2F(vfinite)(&totalSize, pDataA)) == false)
         {
+            if (pDblA->isComplex())
+            {
+                vFreeDoubleComplexFromPointer((doublecomplex*)pDataA);
+            }
+            pDblA->killMe();
             Scierror(264, _("%s: Wrong value for input argument %d: Must not contain NaN or Inf.\n"), "spec", 1);
             return types::Function::Error;
         }
@@ -136,12 +143,16 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
 
                 if (iRet < 0)
                 {
+                    vFreeDoubleComplexFromPointer((doublecomplex*)pDataA);
+                    pDblA->killMe();
                     Scierror(998, _("%s: On entry to ZGEEV parameter number  3 had an illegal value (lapack library problem).\n"), "spec", iRet);
                     return types::Function::Error;
                 }
 
                 if (iRet > 0)
                 {
+                    vFreeDoubleComplexFromPointer((doublecomplex*)pDataA);
+                    pDblA->killMe();
                     Scierror(24, _("%s: Convergence problem, %d off-diagonal elements of an intermediate tridiagonal form did not converge to zero.\n"), "spec", iRet);
                     return types::Function::Error;
                 }
@@ -149,6 +160,7 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
                 if (_iRetCount == 2)
                 {
                     vGetPointerFromDoubleComplex((doublecomplex*)pDataA, pDblA->getSize() , pDblEigenVectors->getReal(), pDblEigenVectors->getImg());
+                    vFreeDoubleComplexFromPointer((doublecomplex*)pDataA);
                     expandToDiagonalOfMatrix(pDblEigenValues->getReal(), pDblA->getCols());
                     out.push_back(pDblEigenVectors);
                 }
@@ -159,14 +171,17 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
                 doublecomplex* pEigenValues = (doublecomplex*)MALLOC(pDblA->getCols() * sizeof(doublecomplex));
                 doublecomplex* pEigenVectors = pDblEigenVectors ? (doublecomplex*)MALLOC(sizeof(doublecomplex) * pDblA->getSize()) : NULL;
                 iRet = iEigen1ComplexM((doublecomplex*)pDataA, pDblA->getCols(), pEigenValues, pEigenVectors);
+                vFreeDoubleComplexFromPointer((doublecomplex*)pDataA);
                 if (iRet < 0)
                 {
+                    pDblA->killMe();
                     Scierror(998, _("%s: On entry to ZHEEV parameter number  3 had an illegal value (lapack library problem).\n"), "spec", iRet);
                     return types::Function::Error;
                 }
 
                 if (iRet > 0)
                 {
+                    pDblA->killMe();
                     Scierror(24, _("%s: The QR algorithm failed to compute all the eigenvalues, and no eigenvectors have been computed. Elements and %d+1:N of W contain eigenvalues which have converged.\n"), "spec", iRet);
                     return types::Function::Error;
                 }
@@ -185,6 +200,7 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
                 }
                 out.push_back(pDblEigenValues);
                 FREE(pEigenValues);
+                pDblA->killMe();
             }
         }
         else // real
@@ -192,15 +208,16 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
             if (symmetric)
             {
                 iRet = iEigen1RealSymmetricM(pDataA, pDblA->getCols(), (_iRetCount == 2), pDblEigenValues->getReal());
-
                 if (iRet < 0)
                 {
+                    pDblA->killMe();
                     Scierror(998, _("%s: On entry to ZGEEV parameter number  3 had an illegal value (lapack library problem).\n"), "spec", iRet);
                     return types::Function::Error;
                 }
 
                 if (iRet > 0)
                 {
+                    pDblA->killMe();
                     Scierror(24, _("%s: Convergence problem, %d off-diagonal elements of an intermediate tridiagonal form did not converge to zero.\n"), "spec", iRet);
                     return types::Function::Error;
                 }
@@ -210,6 +227,11 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
                     expandToDiagonalOfMatrix(pDblEigenValues->getReal(), pDblA->getCols());
                     out.push_back(pDblA);
                 }
+                else
+                {
+                    pDblA->killMe();
+                }
+
                 out.push_back(pDblEigenValues);
             }
             else // not symmetric
@@ -218,12 +240,14 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
 
                 if (iRet < 0)
                 {
+                    pDblA->killMe();
                     Scierror(998, _("%s: On entry to ZHEEV parameter number  3 had an illegal value (lapack library problem).\n"), "spec", iRet);
                     return types::Function::Error;
                 }
 
                 if (iRet > 0)
                 {
+                    pDblA->killMe();
                     Scierror(24, _("%s: The QR algorithm failed to compute all the eigenvalues, and no eigenvectors have been computed. Elements and %d+1:N of WR and WI contain eigenvalues which have converged.\n"), "spec", iRet);
                     return types::Function::Error;
                 }
@@ -234,9 +258,13 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
                     expandToDiagonalOfMatrix(pDblEigenValues->getImg(), pDblA->getCols());
                     out.push_back(pDblEigenVectors);
                 }
+
                 out.push_back(pDblEigenValues);
+                pDblA->killMe();
             }
         }
+
+        return types::Function::OK;
     }
 
     if (in.size() == 2)
@@ -251,37 +279,40 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
         doublecomplex* pAlpha           = NULL;
         bool bIsComplex                 = false;
 
-        if ((in[1]->isDouble() == false))
+        if (in[1]->isDouble() == false)
         {
             ast::ExecVisitor exec;
             std::wstring wstFuncName = L"%" + in[1]->getShortTypeStr() + L"_spec";
             return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
         }
-        pDblB = in[1]->getAs<types::Double>()->clone()->getAs<types::Double>();
 
-        if (pDblB->getCols() != pDblB->getRows())
+        types::Double* in1 = in[1]->getAs<types::Double>();
+
+        if (in1->getCols() != in1->getRows())
         {
             Scierror(20, _("%s: Wrong type for input argument #%d: Square matrix expected.\n"), "spec", 2);
             return types::Function::Error;
         }
 
-        if ((pDblA->getRows() != pDblB->getRows()) && (pDblA->getCols() != pDblB->getCols()))
+        if (pDblA->getRows() != in1->getRows() && pDblA->getCols() != in1->getCols())
         {
+            pDblA->killMe();
             Scierror(999, _("%s: Arguments %d and %d must have equal dimensions.\n"), "spec", 1, 2);
             return types::Function::Error;
         }
 
         //chekc if A and B are real complex or with imag part at 0
-        if (isNoZeroImag(pDblA) == false && isNoZeroImag(pDblB) == false)
+        if (isNoZeroImag(pDblA) == false && isNoZeroImag(in1) == false)
         {
             //view A and B as real matrix
             bIsComplex = false;
         }
         else
         {
-            bIsComplex = pDblA->isComplex() || pDblB->isComplex();
+            bIsComplex = pDblA->isComplex() || in1->isComplex();
         }
 
+        types::Double* pDblB = in1->clone()->getAs<types::Double>();
         if (bIsComplex)
         {
             if (pDblA->isComplex() == false)
@@ -297,8 +328,10 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
             pDataA = (double*)oGetDoubleComplexFromPointer(pDblA->getReal(), pDblA->getImg(), pDblA->getSize());
             pDataB = (double*)oGetDoubleComplexFromPointer(pDblB->getReal(), pDblB->getImg(), pDblB->getSize());
 
-            if (!pDblA || !pDblB)
+            if (!pDataA || !pDataB)
             {
+                delete pDataA;
+                delete pDataB;
                 Scierror(999, _("%s: Cannot allocate more memory.\n"), "spec");
                 return types::Function::Error;
             }
@@ -313,12 +346,16 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
 
         if ((pDblA->isComplex() ? C2F(vfiniteComplex)(&totalSize, (doublecomplex*)pDataA) : C2F(vfinite)(&totalSize, pDataA)) == false)
         {
+            pDblA->killMe();
+            pDblB->killMe();
             Scierror(264, _("%s: Wrong value for input argument %d: Must not contain NaN or Inf.\n"), "spec", 1);
             return types::Function::Error;
         }
 
         if ((pDblB->isComplex() ? C2F(vfiniteComplex)(&totalSize, (doublecomplex*)pDataB) : C2F(vfinite)(&totalSize, pDataB)) == false)
         {
+            pDblA->killMe();
+            pDblB->killMe();
             Scierror(264, _("%s: Wrong value for input argument %d: Must not contain NaN or Inf.\n"), "spec", 2);
             return types::Function::Error;
         }
@@ -383,6 +420,8 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
 
         if (iRet < 0)
         {
+            pDblA->killMe();
+            pDblB->killMe();
             Scierror(998, _("%s: On entry to ZHEEV parameter number  3 had an illegal value (lapack library problem).\n"), "spec", iRet);
             return types::Function::Error;
         }
@@ -397,11 +436,11 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
                 }
                 else
                 {
-                    if (iRet ==  pDblA->getCols() + 1)
+                    if (iRet == pDblA->getCols() + 1)
                     {
                         Scierror(999, _("%s: Other than QZ iteration failed in DHGEQZ.\n"), "spec");
                     }
-                    if (iRet ==  pDblA->getCols() + 2)
+                    if (iRet == pDblA->getCols() + 2)
                     {
                         Scierror(999, _("%s: Error return from DTGEVC.\n"), "spec");
                     }
@@ -411,6 +450,18 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
             {
                 Scierror(24, _("%s: The QR algorithm failed to compute all the eigenvalues, and no eigenvectors have been computed. Elements and %d+1:N of W contain eigenvalues which have converged.\n"), "spec", iRet);
             }
+
+            pDblA->killMe();
+            pDblB->killMe();
+            if (pDataA)
+            {
+                vFreeDoubleComplexFromPointer((doublecomplex*)pDataA);
+            }
+
+            if (pDataB)
+            {
+                vFreeDoubleComplexFromPointer((doublecomplex*)pDataB);
+            }
             return types::Function::Error;
         }
 
@@ -478,6 +529,7 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ
         {
             vFreeDoubleComplexFromPointer((doublecomplex*)pDataB);
         }
+        pDblB->killMe();
 
     } // if(in.size() == 2)
 
index 83d4af5..0c6b0b7 100644 (file)
@@ -247,13 +247,24 @@ types::Function::ReturnValue sci_roots(types::typed_list &in, int _iRetCount, ty
             C2F(dcopy)(&iSize, pdblTempImg, &iOne, pdblOutImg, &iOne);
         }
 
-        ast::ExecVisitor exec;
         //call spec
-        types::typed_list tlInput;
-        types::optional_list tlOpt;
-        tlInput.push_back(pDblOut);
-        types::Function *funcSpec = symbol::Context::getInstance()->get(symbol::Symbol(L"spec"))->getAs<types::Function>();
-        ret = funcSpec->call(tlInput, tlOpt, 1, out, &exec);
+        types::InternalType* pSpec = symbol::Context::getInstance()->get(symbol::Symbol(L"spec"));
+        if (pSpec && pSpec->isFunction())
+        {
+            types::Function *funcSpec = pSpec->getAs<types::Function>();
+            ast::ExecVisitor exec;
+            types::typed_list tlInput;
+            types::optional_list tlOpt;
+            tlInput.push_back(pDblOut);
+
+            ret = funcSpec->call(tlInput, tlOpt, 1, out, &exec);
+            pDblOut->killMe();
+        }
+        else
+        {
+            Scierror(999, _("%s: unable to find spec function\n"), "roots");
+            return types::Function::Error;
+        }
     }
 
     if (pDblIn)