Index: sal/rtl/source/alloc.c
===================================================================
RCS file: /cvs/porting/sal/rtl/source/alloc.c,v
retrieving revision 1.14
diff -u -3 -p -r1.14 alloc.c
--- sal/rtl/source/alloc.c	17 Dec 2003 17:10:01 -0000	1.14
+++ sal/rtl/source/alloc.c	29 Feb 2004 17:50:41 -0000
@@ -227,6 +227,39 @@ static sal_uInt32 __rtl_memory_vmpagesiz
 
 /*===========================================================================
  *
+ * Determine allocation mode (debug/release) by examining environment
+ * variable "OOO_FORCE_SYSALLOC".
+ *
+ *=========================================================================*/
+
+#include <stdlib.h>   /* getenv */
+#include <stdio.h>    /* stderr */
+
+typedef 
+   enum { AMode_CUSTOM, AMode_SYSTEM, AMode_UNSET } 
+   AllocMode;
+
+static AllocMode alloc_mode = AMode_UNSET;
+
+static void determine_alloc_mode ( void )
+{
+   /* This shouldn't happen, but still ... */
+   if (alloc_mode != AMode_UNSET)
+      return;
+
+   if (getenv("OOO_FORCE_SYSALLOC") != NULL) {
+      alloc_mode = AMode_SYSTEM;
+      fprintf(stderr, "OOo: Using system memory allocator.\n");
+      fprintf(stderr, "OOo: This is for debugging only.  To disable,\n");
+      fprintf(stderr, "OOo: unset the environment variable"
+                      " OOO_FORCE_SYSALLOC.\n");
+   } else {
+      alloc_mode = AMode_CUSTOM;
+   }
+}
+
+/*===========================================================================
+ *
  * rtl_memory (global) internals.
  *
  *=========================================================================*/
@@ -1165,8 +1165,8 @@ static void __rtl_memory_enqueue (memory
 /*
  * rtl_reallocateMemory.
  */
-#ifndef FORCE_SYSALLOC
-void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
+static
+void* SAL_CALL rtl_reallocateMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
 {
 	memory_type * memory;
 	if (!(!p || !n))
@@ -1322,18 +1322,33 @@ void* SAL_CALL rtl_reallocateMemory (voi
 	}
 	return (p);
 }
-#else  /* FORCE_SYSALLOC */
-void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
+
+static
+void* SAL_CALL rtl_reallocateMemory_SYSTEM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
 {
 	return realloc(p, (sal_Size)(n));
 }
-#endif /* FORCE_SYSALLOC */
+
+void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
+{
+   while (1) {
+      if (alloc_mode == AMode_CUSTOM) {
+         return rtl_reallocateMemory_CUSTOM(p,n);
+      }
+      if (alloc_mode == AMode_SYSTEM) {
+         return rtl_reallocateMemory_SYSTEM(p,n);
+      }
+      determine_alloc_mode();
+   }
+}
+
+
 
 /*
  * rtl_allocateMemory.
  */
-#ifndef FORCE_SYSALLOC
-void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C()
+static
+void* SAL_CALL rtl_allocateMemory_CUSTOM (sal_Size n) SAL_THROW_EXTERN_C()
 {
 	void * p = 0;
 	if (n > 0)
@@ -1355,18 +1355,33 @@ void* SAL_CALL rtl_allocateMemory (sal_u
 	}
 	return (p);
 }
-#else  /* FORCE_SYSALLOC */
-void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C()
+
+static
+void* SAL_CALL rtl_allocateMemory_SYSTEM (sal_Size n) SAL_THROW_EXTERN_C()
 {
 	return malloc((sal_Size)(n));
 }
-#endif /* FORCE_SYSALLOC */
+
+void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C()
+{
+   while (1) {
+      if (alloc_mode == AMode_CUSTOM) {
+         return rtl_allocateMemory_CUSTOM(n);
+      }
+      if (alloc_mode == AMode_SYSTEM) {
+         return rtl_allocateMemory_SYSTEM(n);
+      }
+      determine_alloc_mode();
+   }
+}
+
+
 
 /*
  * rtl_freeMemory.
  */
-#ifndef FORCE_SYSALLOC
-void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C()
+static
+void SAL_CALL rtl_freeMemory_CUSTOM (void * p) SAL_THROW_EXTERN_C()
 {
 	if (p)
 	{
@@ -1387,18 +1387,34 @@ void SAL_CALL rtl_freeMemory (void * p) 
 		RTL_MEMORY_LEAVE();
 	}
 }
-#else  /* FORCE_SYSALLOC */
-void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C()
+
+static
+void SAL_CALL rtl_freeMemory_SYSTEM (void * p) SAL_THROW_EXTERN_C()
 {
 	free(p);
 }
-#endif /* FORCE_SYSALLOC */
+
+void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C()
+{
+   while (1) {
+      if (alloc_mode == AMode_CUSTOM) {
+         rtl_freeMemory_CUSTOM(p);
+	 return;
+      }
+      if (alloc_mode == AMode_SYSTEM) {
+         rtl_freeMemory_SYSTEM(p);
+	 return;
+      }
+      determine_alloc_mode();
+   }
+}
+
 
 /*
  * rtl_allocateZeroMemory.
  */
-#ifndef FORCE_SYSALLOC
-void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C()
+static
+void* SAL_CALL rtl_allocateZeroMemory_CUSTOM (sal_Size n) SAL_THROW_EXTERN_C()
 {
 	void * p = 0;
 	if (n > 0)
@@ -1421,18 +1421,32 @@ void* SAL_CALL rtl_allocateZeroMemory (s
 	}
 	return (p);
 }
-#else  /* FORCE_SYSALLOC */
-void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C()
+
+static
+void* SAL_CALL rtl_allocateZeroMemory_SYSTEM (sal_Size n) SAL_THROW_EXTERN_C()
 {
 	return calloc((sal_Size)(n), 1);
 }
-#endif /* FORCE_SYSALLOC */
+
+void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C()
+{
+   while (1) {
+      if (alloc_mode == AMode_CUSTOM) {
+         return rtl_allocateZeroMemory_CUSTOM(n);
+      }
+      if (alloc_mode == AMode_SYSTEM) {
+         return rtl_allocateZeroMemory_SYSTEM(n);
+      }
+      determine_alloc_mode();
+   }
+}
+
 
 /*
  * rtl_freeZeroMemory.
  */
-#ifndef FORCE_SYSALLOC
-void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
+static
+void SAL_CALL rtl_freeZeroMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
 {
 	if (p)
 	{
@@ -1454,8 +1454,9 @@ void SAL_CALL rtl_freeZeroMemory (void *
 		RTL_MEMORY_LEAVE();
 	}
 }
-#else  /* FORCE_SYSALLOC */
-void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
+
+static
+void SAL_CALL rtl_freeZeroMemory_SYSTEM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
 {
 	if (p)
 	{
@@ -1463,7 +1463,21 @@ void SAL_CALL rtl_freeZeroMemory (void *
 		free(p);
 	}
 }
-#endif /* FORCE_SYSALLOC */
+
+void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
+{
+   while (1) {
+      if (alloc_mode == AMode_CUSTOM) {
+         rtl_freeZeroMemory_CUSTOM(p,n);
+	 return;
+      }
+      if (alloc_mode == AMode_SYSTEM) {
+         rtl_freeZeroMemory_SYSTEM(p,n);
+	 return;
+      }
+      determine_alloc_mode();
+   }
+}
 
 /*===========================================================================
  *

