Kaynağa Gözat

fix malloc issues on Linux

David Rose 20 yıl önce
ebeveyn
işleme
237d193cac

+ 4 - 2
dtool/Config.pp

@@ -333,8 +333,10 @@
 // ptmalloc2 anyway).  We always define this by default on Windows; on
 // ptmalloc2 anyway).  We always define this by default on Windows; on
 // Linux, we define it by default only when DO_MEMORY_USAGE is enabled
 // Linux, we define it by default only when DO_MEMORY_USAGE is enabled
 // (since in that case, we'll be paying the overhead for the extra
 // (since in that case, we'll be paying the overhead for the extra
-// call anyway).
-#defer ALTERNATIVE_MALLOC $[or $[WINDOWS_PLATFORM],$[DO_MEMORY_USAGE]]
+// call anyway) or when HAVE_THREADS is not defined (since the
+// non-thread-safe dlmalloc is a tiny bit faster than the system
+// library).
+#defer ALTERNATIVE_MALLOC $[or $[WINDOWS_PLATFORM],$[DO_MEMORY_USAGE],$[not $[HAVE_THREADS]]]
 
 
 // Is NSPR installed, and where?  This is the Netscape Portable
 // Is NSPR installed, and where?  This is the Netscape Portable
 // Runtime library, downloadable as part of the Mozilla package from
 // Runtime library, downloadable as part of the Mozilla package from

+ 9 - 0
dtool/src/cppparser/cppPreprocessor.cxx

@@ -102,7 +102,16 @@ InputFile() {
 CPPPreprocessor::InputFile::
 CPPPreprocessor::InputFile::
 ~InputFile() {
 ~InputFile() {
   if (_in != NULL) {
   if (_in != NULL) {
+    // For some reason--compiler bug in gcc 3.2?--explicitly deleting
+    // the stream pointer does not call the appropriate global delete
+    // function; instead apparently calling the system delete
+    // function.  So we call the delete function by hand instead.
+#ifndef USE_MEMORY_NOWRAPPERS
+    _in->~istream();
+    (*global_operator_delete)(_in);
+#else
     delete _in;
     delete _in;
+#endif
   }
   }
 }
 }
 
 

+ 2 - 1
dtool/src/dtoolbase/Sources.pp

@@ -10,7 +10,8 @@
     nearly_zero.h \
     nearly_zero.h \
     stl_compares.I stl_compares.h \
     stl_compares.I stl_compares.h \
     pallocator.T pallocator.h \
     pallocator.T pallocator.h \
-    pdeque.h plist.h pmap.h pset.h pvector.h
+    pdeque.h plist.h pmap.h pset.h pvector.h \
+    dlmalloc.c ptmalloc2_smp.c
 
 
   #define INSTALL_HEADERS \
   #define INSTALL_HEADERS \
     cmath.I cmath.h \
     cmath.I cmath.h \

+ 8 - 0
dtool/src/dtoolbase/dlmalloc.c

@@ -1,3 +1,9 @@
+
+#include "dtoolbase.h"
+
+#ifdef USE_MEMORY_DLMALLOC
+#define USE_DL_PREFIX 1
+
 /*
 /*
   This is a version (aka dlmalloc) of malloc/free/realloc written by
   This is a version (aka dlmalloc) of malloc/free/realloc written by
   Doug Lea and released to the public domain, as explained at
   Doug Lea and released to the public domain, as explained at
@@ -5059,3 +5065,5 @@ History:
          structure of old version,  but most details differ.)
          structure of old version,  but most details differ.)
  
  
 */
 */
+
+#endif  // USE_MEMORY_DLMALLOC

+ 7 - 4
dtool/src/dtoolbase/dtoolbase.cxx

@@ -36,7 +36,6 @@
 #define USE_DL_PREFIX 1
 #define USE_DL_PREFIX 1
 #define NO_MALLINFO 1
 #define NO_MALLINFO 1
 #include "dlmalloc.h"
 #include "dlmalloc.h"
-#include "dlmalloc.c"
 
 
 void *default_operator_new(size_t size) {
 void *default_operator_new(size_t size) {
   void *ptr = dlmalloc(size);
   void *ptr = dlmalloc(size);
@@ -66,10 +65,14 @@ void (*global_operator_delete)(void *ptr) = &default_operator_delete;
 //
 //
 /////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////
 
 
-#elif defined(USE_MEMORY_PTMALLOC2)
+#elif defined(USE_MEMORY_PTMALLOC2) && !defined(linux)
+// This doesn't appear to work in Linux; perhaps it is clashing with
+// the system library.  On Linux, fall through to the next case
+// instead.
 
 
 #define USE_DL_PREFIX 1
 #define USE_DL_PREFIX 1
-#include "ptmalloc2_smp.c"
+#define NO_MALLINFO 1
+#include "dlmalloc.h"
 
 
 void *default_operator_new(size_t size) {
 void *default_operator_new(size_t size) {
   void *ptr = dlmalloc(size);
   void *ptr = dlmalloc(size);
@@ -96,7 +99,7 @@ void (*global_operator_delete)(void *ptr) = &default_operator_delete;
 //
 //
 /////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////
 
 
-#elif defined(USE_MEMORY_MALLOC)
+#elif defined(USE_MEMORY_MALLOC) || defined(USE_MEMORY_PTMALLOC2)
 
 
 void *default_operator_new(size_t size) {
 void *default_operator_new(size_t size) {
   void *ptr = malloc(size);
   void *ptr = malloc(size);

+ 2 - 0
dtool/src/dtoolbase/dtoolbase.h

@@ -100,6 +100,7 @@
 #include <sys/types.h>
 #include <sys/types.h>
 #endif
 #endif
 
 
+/*
 #ifdef HAVE_MALLOC_H
 #ifdef HAVE_MALLOC_H
 #include <malloc.h>
 #include <malloc.h>
 #endif
 #endif
@@ -107,6 +108,7 @@
 #ifdef HAVE_SYS_MALLOC_H
 #ifdef HAVE_SYS_MALLOC_H
 #include <sys/malloc.h>
 #include <sys/malloc.h>
 #endif
 #endif
+*/
 
 
 #ifdef HAVE_ALLOCA_H
 #ifdef HAVE_ALLOCA_H
 #include <alloca.h>
 #include <alloca.h>

+ 17 - 2
dtool/src/dtoolbase/ptmalloc2_smp.c

@@ -1,3 +1,12 @@
+/* drose: Note that this file is released under an unrestricted
+   license as well as the LGPL, in spite of the comments below.  See
+   http://www.malloc.de . */
+
+#include "dtoolbase.h"
+
+#if defined(USE_MEMORY_PTMALLOC2) && !defined(linux)
+#define USE_DL_PREFIX 1
+
 /* Malloc implementation for multiple threads without lock contention.
 /* Malloc implementation for multiple threads without lock contention.
    Copyright (C) 1996,1997,1998,1999,2000,01,02 Free Software Foundation, Inc.
    Copyright (C) 1996,1997,1998,1999,2000,01,02 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    This file is part of the GNU C Library.
@@ -2239,7 +2248,7 @@ struct malloc_chunk {
 };
 };
 
 
 
 
-typedef struct malloc_chunk* mchunkptr;
+/*typedef struct malloc_chunk* mchunkptr;*/
 
 
 /*
 /*
    malloc_chunk details:
    malloc_chunk details:
@@ -2859,7 +2868,7 @@ struct malloc_par {
   char*            sbrk_base;
   char*            sbrk_base;
 };
 };
 
 
-typedef struct malloc_state *mstate;
+/*typedef struct malloc_state *mstate;*/
 
 
 /* There are several instances of this struct ("arenas") in this
 /* There are several instances of this struct ("arenas") in this
    malloc.  If you are adapting this malloc in a way that does NOT use
    malloc.  If you are adapting this malloc in a way that does NOT use
@@ -5311,6 +5320,9 @@ mremap_chunk(p, new_size) mchunkptr p; size_t new_size;
   /* Note the extra SIZE_SZ overhead as in mmap_chunk(). */
   /* Note the extra SIZE_SZ overhead as in mmap_chunk(). */
   new_size = (new_size + offset + SIZE_SZ + page_mask) & ~page_mask;
   new_size = (new_size + offset + SIZE_SZ + page_mask) & ~page_mask;
 
 
+#ifndef MREMAP_MAYMOVE
+#define MREMAP_MAYMOVE 1  /* terrible hack--drose */
+#endif
   cp = (char *)mremap((char *)p - offset, size + offset, new_size,
   cp = (char *)mremap((char *)p - offset, size + offset, new_size,
                       MREMAP_MAYMOVE);
                       MREMAP_MAYMOVE);
 
 
@@ -8207,3 +8219,6 @@ History:
          structure of old version,  but most details differ.)
          structure of old version,  but most details differ.)
 
 
 */
 */
+
+#endif  // USE_MEMORY_PTMALLOC2
+