Bläddra i källkod

Added error handler implemetation to rtlMalloc() and rtlRealloc() functions.

Signed-off-by: Attila Vamos <attila.vamos@gmail.com>
Attila Vamos 12 år sedan
förälder
incheckning
61df2f37a8
2 ändrade filer med 22 tillägg och 6 borttagningar
  1. 20 4
      rtl/eclrtl/eclrtl.cpp
  2. 2 2
      rtl/eclrtl/eclrtl.hpp

+ 20 - 4
rtl/eclrtl/eclrtl.cpp

@@ -65,9 +65,17 @@ MODULE_EXIT()
 //=============================================================================
 // Miscellaneous string functions...
 
-ECLRTL_API void * rtlMalloc(size32_t size)
+ECLRTL_API void * rtlMalloc(size32_t size, const char * aFile, unsigned aLine)
 {
-    return malloc(size);
+    void * retVal = malloc(size);
+
+    if( NULL == retVal)
+    {
+        StringBuffer msg;
+        msg.append("Memory allocation error in ").append(aFile).append(" at line ").append(aLine).append(" for size ").append(size).append(" Bytes!");
+        rtlFail(0, msg.str());
+    }
+    return retVal;
 }
 
 void rtlFree(void *ptr)
@@ -75,9 +83,17 @@ void rtlFree(void *ptr)
     free(ptr);
 }
 
-ECLRTL_API void * rtlRealloc(void * _ptr, size32_t size)
+ECLRTL_API void * rtlRealloc(void * _ptr, size32_t size, const char * aFile, unsigned aLine)
 {
-    return realloc(_ptr, size);
+    void * retVal = realloc(_ptr, size);
+
+    if( (0 < size) && (NULL == retVal))
+    {
+        StringBuffer msg;
+        msg.append("Memory reallocation error in ").append(aFile).append(" at line ").append(aLine).append(" for size ").append(size).append(" Bytes!");
+        rtlFail(0, msg.str());
+    }
+    return retVal;
 }
 
 //=============================================================================

+ 2 - 2
rtl/eclrtl/eclrtl.hpp

@@ -92,9 +92,9 @@ interface ICompiledUStrRegExpr
 
 //-----------------------------------------------------------------------------
 
-ECLRTL_API void * rtlMalloc(size32_t size);
+ECLRTL_API void * rtlMalloc(size32_t size, const char * aFile = __FILE__, unsigned aLine = __LINE__);
 ECLRTL_API void rtlFree(void * x);
-ECLRTL_API void * rtlRealloc(void * _ptr, size32_t size);
+ECLRTL_API void * rtlRealloc(void * _ptr, size32_t size, const char * aFile = __FILE__, unsigned aLine = __LINE__);
 ECLRTL_API __int64 rtlRound(double x);
 ECLRTL_API double rtlRoundTo(double x, int places);
 ECLRTL_API __int64 rtlRoundDown(double x);