mpi module plugged.
[scilab.git] / scilab / modules / mpi / src / c / serialization.c
index 2925f57..ce1cfbc 100644 (file)
@@ -6,15 +6,16 @@
  * 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
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
  *
  */
 #include <string.h>
 #include <stdio.h>
 #include "api_scilab.h"
 #include "BOOL.h"
-#include "MALLOC.h"
+#include "sci_malloc.h"
 #include "serialization.h"
+#include "elem_common.h"
 
 static int serialize_double(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBufferSize)
 {
@@ -157,6 +158,8 @@ static int serialize_string(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_p
 
     *_piBuffer = piOut;
     *_piBufferSize = iOutLen;
+
+    freeAllocatedMatrixOfString(iRows, iCols, pstData);
     return 0;
 }
 
@@ -312,11 +315,13 @@ static int serialize_int(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBu
                 break;
                 }
         */ default:
+            FREE(piOut);
             return 1;
     }
 
     if (sciErr.iErr)
     {
+        FREE(piOut);
         printError(&sciErr, 0);
         return 1;
     }
@@ -404,33 +409,58 @@ static int serialize_sparse(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_p
 
     *_piBuffer = piOut;
     *_piBufferSize = iOutLen;
+
+    if (_bData)
+    {
+        if (iComplex)
+        {
+            freeAllocatedSparseMatrix(piRowCount, piColPos, pdblR);
+        }
+        else
+        {
+            freeAllocatedComplexSparseMatrix(piRowCount, piColPos, pdblR, pdblI);
+        }
+    }
+    else
+    {
+        freeAllocatedBooleanSparse(piRowCount, piColPos);
+    }
+
     return 0;
 }
 
 int serialize_to_mpi(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBufferSize)
 {
-    switch (*_piAddr)
+    int iType = 0;
+    SciErr sciErr = getVarType(_pvCtx, _piAddr, &iType);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    switch (iType)
     {
         case sci_matrix:
-            return serialize_double(pvApiCtx, _piAddr, _piBuffer, _piBufferSize);
+            return serialize_double(_pvCtx, _piAddr, _piBuffer, _piBufferSize);
             break;
         case sci_strings:
-            return serialize_string(pvApiCtx, _piAddr, _piBuffer, _piBufferSize);
+            return serialize_string(_pvCtx, _piAddr, _piBuffer, _piBufferSize);
             break;
         case sci_boolean:
-            return serialize_boolean(pvApiCtx, _piAddr, _piBuffer, _piBufferSize);
+            return serialize_boolean(_pvCtx, _piAddr, _piBuffer, _piBufferSize);
             break;
         case sci_sparse:
-            return serialize_sparse(pvApiCtx, _piAddr, _piBuffer, _piBufferSize, TRUE);
+            return serialize_sparse(_pvCtx, _piAddr, _piBuffer, _piBufferSize, TRUE);
             break;
         case sci_boolean_sparse:
-            return serialize_sparse(pvApiCtx, _piAddr, _piBuffer, _piBufferSize, FALSE);
+            return serialize_sparse(_pvCtx, _piAddr, _piBuffer, _piBufferSize, FALSE);
             break;
         case sci_ints:
-            return serialize_int(pvApiCtx, _piAddr, _piBuffer, _piBufferSize);
+            return serialize_int(_pvCtx, _piAddr, _piBuffer, _piBufferSize);
             break;
         default:
             return -1;
             break;
     }
-}
\ No newline at end of file
+}