bug 12189: fix segfault when overwrite for increment 05/10105/3
Antoine ELIAS [Wed, 2 Jan 2013 10:25:12 +0000 (11:25 +0100)]
Change-Id: I47c55d84c03d2124960ec2722f37b571585bf8dd

scilab/etc/modules.xml.in
scilab/etc/modules.xml.vc
scilab/modules/ast/etc/ast.quit [new file with mode: 0644]
scilab/modules/ast/etc/ast.start [new file with mode: 0644]
scilab/modules/ast/includes/runvisitor.hxx
scilab/modules/ast/macros/buildmacros.bat [new file with mode: 0644]
scilab/modules/ast/macros/buildmacros.sce [new file with mode: 0644]
scilab/modules/ast/macros/cleanmacros.bat [new file with mode: 0644]
scilab/modules/ast/tests/nonreg_tests/bug_12189.dia.ref [new file with mode: 0644]
scilab/modules/ast/tests/nonreg_tests/bug_12189.tst [new file with mode: 0644]

index a9da152..4e82c41 100644 (file)
@@ -58,4 +58,5 @@
     <module name="graphic_export" activate="yes"/>
     <module name="operations" activate="yes"/>
     <module name="api_scilab" activate="yes"/>
+    <module name="ast" activate="yes"/>
 </modules>
index 4767aa1..8a1e673 100644 (file)
@@ -59,4 +59,5 @@
     <module name="graphic_export" activate="yes"/>
     <module name="operations" activate="yes"/>
     <module name="api_scilab" activate="yes"/>
+    <module name="ast" activate="yes"/>
 </modules>
diff --git a/scilab/modules/ast/etc/ast.quit b/scilab/modules/ast/etc/ast.quit
new file mode 100644 (file)
index 0000000..6bfa34b
--- /dev/null
@@ -0,0 +1,9 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
diff --git a/scilab/modules/ast/etc/ast.start b/scilab/modules/ast/etc/ast.start
new file mode 100644 (file)
index 0000000..6bfa34b
--- /dev/null
@@ -0,0 +1,9 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
index b79f620..e02ff5c 100644 (file)
@@ -765,98 +765,18 @@ public :
         if (result_get()->isImplicitList())
         {
             bool bNeedUpdate = false;
-            ImplicitList* pVar = ((InternalType*)result_get())->getAs<ImplicitList>();
+            InternalType* pIL = result_get();
+            ImplicitList* pVar = pIL->getAs<ImplicitList>();
 
             InternalType *pIT = NULL;
             pIT = pVar->extractValue(0);
             symbol::Symbol varName = e.vardec_get().name_get();
 
-            //keep pIt as Double to optimize Double case
-            if (pIT->isDouble())
-            {
-                symbol::Context::getInstance()->put(varName, *pIT);
-            }
-
-            Double *pDouble = pIT->getAs<Double>();
             for (int i = 0 ; i < pVar->getSize() ; i++)
             {
-                //QueryPerformanceCounter(&liStart);
-                if (pIT->isRef(1))
-                {
-                    pIT = pIT->clone();
-                    //update pDouble after clone
-                    pDouble = pIT->getAs<Double>();
-                    bNeedUpdate = true;
-                }
 
-                if (pIT->isDouble())
-                {
-                    pDouble->set(0, pVar->extractValueInDouble(i));
-                }
-                else if (pIT->isInt())
-                {
-                    switch (pIT->getType())
-                    {
-                        case InternalType::RealInt8 :
-                        {
-                            Int8* pI = pIT->getAs<Int8>();
-                            pI->set(0, (char)pVar->extractValueInInteger(i));
-                            break;
-                        }
-                        case InternalType::RealUInt8 :
-                        {
-                            UInt8* pI = pIT->getAs<UInt8>();
-                            pI->set(0, (unsigned char)pVar->extractValueInInteger(i));
-                            break;
-                        }
-                        case InternalType::RealInt16 :
-                        {
-                            Int16* pI = pIT->getAs<Int16>();
-                            pI->set(0, (short)pVar->extractValueInInteger(i));
-                            break;
-                        }
-                        case InternalType::RealUInt16 :
-                        {
-                            UInt16* pI = pIT->getAs<UInt16>();
-                            pI->set(0, (unsigned short)pVar->extractValueInInteger(i));
-                            break;
-                        }
-                        case InternalType::RealInt32 :
-                        {
-                            Int32* pI = pIT->getAs<Int32>();
-                            pI->set(0, (int)pVar->extractValueInInteger(i));
-                            break;
-                        }
-                        case InternalType::RealUInt32 :
-                        {
-                            UInt32* pI = pIT->getAs<UInt32>();
-                            pI->set(0, (unsigned int)pVar->extractValueInInteger(i));
-                            break;
-                        }
-                        case InternalType::RealInt64 :
-                        {
-                            Int64* pI = pIT->getAs<Int64>();
-                            pI->set(0, (long long)pVar->extractValueInInteger(i));
-                            break;
-                        }
-                        case InternalType::RealUInt64 :
-                        {
-                            UInt64* pI = pIT->getAs<UInt64>();
-                            pI->set(0, (unsigned long long)pVar->extractValueInInteger(i));
-                            break;
-                        }
-                    }
-                }
-                else
-                {
-                    pIT = pVar->extractValue(i);
-                }
-
-                if (pDouble == NULL || bNeedUpdate)
-                {
-                    symbol::Context::getInstance()->put(varName, *pIT);
-                    bNeedUpdate = false;
-                }
+                pIT = pVar->extractValue(i);
+                symbol::Context::getInstance()->put(varName, *pIT);
 
                 e.body_get().accept(*this);
                 if (e.body_get().is_break())
@@ -876,21 +796,9 @@ public :
                     const_cast<ForExp*>(&e)->return_set();
                     break;
                 }
-
-                //QueryPerformanceCounter(&liStop);
-                //llTotal += (liStop.QuadPart - liStart.QuadPart - llOverHead);
             }
-            //BpIT->DecreaseRef();
-            pVar->DecreaseRef();
-            //delete pVar;
 
-            //if(pVar->getSize() > 0 && llTotal > 0)
-            //{
-            //    //compute and display mean of time
-            //    long long llMean =  llTotal / pVar->getSize();
-            //    std::cout << L"Total time (ms): " << (((double)llTotal /  (double)liFresquency.QuadPart) * 1000) << std::endl;
-            //    std::cout << L"Mean time (ms): " << (((double)llMean /  (double)liFresquency.QuadPart) * 1000) << std::endl;
-            //}
+            pVar->DecreaseRef();
         }
         else if (result_get()->isList())
         {
@@ -903,11 +811,13 @@ public :
                 e.body_get().accept(*this);
                 if (e.body_get().is_break())
                 {
+                    const_cast<Exp*>(&(e.body_get()))->break_reset();
                     break;
                 }
 
                 if (e.body_get().is_continue())
                 {
+                    const_cast<Exp*>(&(e.body_get()))->continue_reset();
                     continue;
                 }
 
@@ -935,11 +845,13 @@ public :
                 e.body_get().accept(*this);
                 if (e.body_get().is_break())
                 {
+                    const_cast<Exp*>(&(e.body_get()))->break_reset();
                     break;
                 }
 
                 if (e.body_get().is_continue())
                 {
+                    const_cast<Exp*>(&(e.body_get()))->continue_reset();
                     continue;
                 }
 
@@ -950,6 +862,7 @@ public :
                 }
             }
         }
+
         result_set(NULL);
     }
 
diff --git a/scilab/modules/ast/macros/buildmacros.bat b/scilab/modules/ast/macros/buildmacros.bat
new file mode 100644 (file)
index 0000000..433a603
--- /dev/null
@@ -0,0 +1,11 @@
+rem Scilab ( http://mwww.scilab.org/ ) - This file is part of Scilab
+rem Copyright (C) 2006 - INRIA 
+rem
+rem This file must be used under the terms of the CeCILL.
+rem This source file is licensed as described in the file COPYING, which
+rem you should have received as part of this distribution.  The terms
+rem are also available at
+rem http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+
+@..\..\..\bin\scilex -nwni -ns -e exec('buildmacros.sce');quit;
\ No newline at end of file
diff --git a/scilab/modules/ast/macros/buildmacros.sce b/scilab/modules/ast/macros/buildmacros.sce
new file mode 100644 (file)
index 0000000..926a8fa
--- /dev/null
@@ -0,0 +1,15 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Allan CORNET
+// 
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at    
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+if (isdef('genlib') == %f) then
+  exec(SCI+'/modules/functions/scripts/buildmacros/loadgenlib.sce');
+end
+//------------------------------------
+//genlib('api_scilablib','SCI/modules/api_scilab/macros',%f,%t);
+//------------------------------------
diff --git a/scilab/modules/ast/macros/cleanmacros.bat b/scilab/modules/ast/macros/cleanmacros.bat
new file mode 100644 (file)
index 0000000..0009ddb
--- /dev/null
@@ -0,0 +1,13 @@
+rem Scilab ( http://mwww.scilab.org/ ) - This file is part of Scilab
+rem Copyright (C) 2006 - INRIA
+rem
+rem This file must be used under the terms of the CeCILL.
+rem This source file is licensed as described in the file COPYING, which
+rem you should have received as part of this distribution.  The terms
+rem are also available at
+rem http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+
+@del *.bin 2>NUL
+@del lib 2>NUL
+@del names 2>NUL
\ No newline at end of file
diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_12189.dia.ref b/scilab/modules/ast/tests/nonreg_tests/bug_12189.dia.ref
new file mode 100644 (file)
index 0000000..345d9ca
--- /dev/null
@@ -0,0 +1,19 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 12189 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/12189
+//
+// <-- Short Description -->
+// for expression segfault when overwrite increment
+
+for i = 1 : 10
+    i = 100;
+end
diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_12189.tst b/scilab/modules/ast/tests/nonreg_tests/bug_12189.tst
new file mode 100644 (file)
index 0000000..345d9ca
--- /dev/null
@@ -0,0 +1,19 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 12189 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/12189
+//
+// <-- Short Description -->
+// for expression segfault when overwrite increment
+
+for i = 1 : 10
+    i = 100;
+end