[opengtl-commits] [583] malloc/free shouldn't be used when the MemoryManager is unabled ( fix crashe in use of generated/changed/whatever function of shiva's kernel)

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 583
Author:   cyrille
Date:     2009-03-05 18:53:47 +0100 (Thu, 05 Mar 2009)

Log Message:
-----------
malloc/free shouldn't be used when the MemoryManager is unabled (fix crashe in use of generated/changed/whatever function of shiva's kernel)

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.h
    trunk/OpenGTL/OpenGTL/tools/mmbenchmark/MMBenchmark.cpp

Added Paths:
-----------
    trunk/OpenGTL/OpenGTL/GTLCore/MemoryModelConfig_p.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2009-03-02 12:25:00 UTC (rev 582)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2009-03-05 17:53:47 UTC (rev 583)
@@ -40,11 +40,8 @@
 
 #include "AST/AccessorExpression.h"
 #include "wrappers/ArrayWrap.h"
+#include "MemoryModelConfig_p.h"
 
-// Define _USE_GTL_MM_ if you want to enable the use of GTLCore::MemoryManager
-// instead of plain call to malloc.
-#define _USE_GTL_MM_
-
 #define UNIFORMIZE_TYPES( _v1_, _v2_) \
   GTL_ASSERT( _v1_.value() ); \
   GTL_ASSERT( _v2_.value() ); \
@@ -776,6 +773,9 @@
   CallFunc->setTailCall(false);
   return convertPointerTo( _bb, CallFunc, _type );
 #else
+#ifndef _USE_OS_MM_
+#error _USE_OS_MM_ or _USE_GTL_MM_ should be defined
+#endif
   return new llvm::MallocInst( _type, _size, "", _bb);
 #endif
 }
@@ -790,6 +790,9 @@
   llvm::CallInst *CallFunc = llvm::CallInst::Create(func, params.begin(), params.end(), "", _bb);
   CallFunc->setTailCall(false);
 #else
+#ifndef _USE_OS_MM_
+#error _USE_OS_MM_ or _USE_GTL_MM_ should be defined
+#endif
   new llvm::FreeInst( _ptr, _bb );
 #endif
 }

Added: trunk/OpenGTL/OpenGTL/GTLCore/MemoryModelConfig_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/MemoryModelConfig_p.h	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/MemoryModelConfig_p.h	2009-03-05 17:53:47 UTC (rev 583)
@@ -0,0 +1,29 @@
+/*
+ *  Copyright (c) 2009 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _MEMORY_MODEL_CONFIG_P_H_
+#define _MEMORY_MODEL_CONFIG_P_H_
+
+// Define _USE_GTL_MM_ if you want to enable the use of GTLCore::MemoryManager
+// instead of plain call to malloc.
+#define _USE_GTL_MM_
+// Define _USE_OS_MM_ if you want to use the OS malloc/free
+// #define _USE_OS_MM_
+
+#endif


Property changes on: trunk/OpenGTL/OpenGTL/GTLCore/MemoryModelConfig_p.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.cpp	2009-03-02 12:25:00 UTC (rev 582)
+++ trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.cpp	2009-03-05 17:53:47 UTC (rev 583)
@@ -21,16 +21,32 @@
 
 #include "../MemoryManager_p.h"
 
+#include "../MemoryModelConfig_p.h"
+
 extern "C" {
 
 void* gtl_malloc( int _size )
 {
+#ifdef _USE_GTL_MM_
   return GTLCore::MemoryManager::allocate(_size);
+#else
+#ifndef _USE_OS_MM_
+#error _USE_OS_MM_ or _USE_GTL_MM_ should be defined
+#endif
+  return malloc(_size);
+#endif
 }
 
 void gtl_free( void* _ptr )
 {
+#ifdef _USE_GTL_MM_
   GTLCore::MemoryManager::desallocate(_ptr);
+#else
+#ifndef _USE_OS_MM_
+#error _USE_OS_MM_ or _USE_GTL_MM_ should be defined
+#endif
+  free(_ptr);
+#endif
 }
 
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.h	2009-03-02 12:25:00 UTC (rev 582)
+++ trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.h	2009-03-05 17:53:47 UTC (rev 583)
@@ -32,7 +32,7 @@
 template<class T>
 T* gtlAllocate(int elt = 1)
 {
-  T* t = (T*)malloc( elt * sizeof(T) );
+  T* t = (T*)gtl_malloc( elt * sizeof(T) );
   // t.count = 1;
   return t;
 }
@@ -40,7 +40,7 @@
 template<class T>
 void gtlFree( T* t)
 {
-  free(t);
+  gtl_free(t);
 }
 
 

Modified: trunk/OpenGTL/OpenGTL/tools/mmbenchmark/MMBenchmark.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/tools/mmbenchmark/MMBenchmark.cpp	2009-03-02 12:25:00 UTC (rev 582)
+++ trunk/OpenGTL/OpenGTL/tools/mmbenchmark/MMBenchmark.cpp	2009-03-05 17:53:47 UTC (rev 583)
@@ -32,7 +32,7 @@
   std::cout << "memorymanager: gtlmm osmm" << std::endl;
 }
 
-#define _COUNT_LOOP_ 1000000
+#define _COUNT_LOOP_ 100000000
 #define _OBJECT_SIZE_ 10
 
 int main(int argc, char** argv)


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/