fix malloc issues on Linux

This commit is contained in:
David Rose
2005-09-30 19:49:25 +00:00
parent b75f4cbf59
commit 237d193cac
7 changed files with 49 additions and 9 deletions
+4 -2
View File
@@ -333,8 +333,10 @@
// ptmalloc2 anyway). We always define this by default on Windows; on
// 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
// 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
// Runtime library, downloadable as part of the Mozilla package from
+9
View File
@@ -102,7 +102,16 @@ InputFile() {
CPPPreprocessor::InputFile::
~InputFile() {
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;
#endif
}
}
+2 -1
View File
@@ -10,7 +10,8 @@
nearly_zero.h \
stl_compares.I stl_compares.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 \
cmath.I cmath.h \
+8
View File
@@ -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
Doug Lea and released to the public domain, as explained at
@@ -5059,3 +5065,5 @@ History:
structure of old version, but most details differ.)
*/
#endif // USE_MEMORY_DLMALLOC
+7 -4
View File
@@ -36,7 +36,6 @@
#define USE_DL_PREFIX 1
#define NO_MALLINFO 1
#include "dlmalloc.h"
#include "dlmalloc.c"
void *default_operator_new(size_t 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
#include "ptmalloc2_smp.c"
#define NO_MALLINFO 1
#include "dlmalloc.h"
void *default_operator_new(size_t 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 *ptr = malloc(size);
+2
View File
@@ -100,6 +100,7 @@
#include <sys/types.h>
#endif
/*
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
@@ -107,6 +108,7 @@
#ifdef HAVE_SYS_MALLOC_H
#include <sys/malloc.h>
#endif
*/
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
+17 -2
View File
@@ -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.
Copyright (C) 1996,1997,1998,1999,2000,01,02 Free Software Foundation, Inc.
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:
@@ -2859,7 +2868,7 @@ struct malloc_par {
char* sbrk_base;
};
typedef struct malloc_state *mstate;
/*typedef struct malloc_state *mstate;*/
/* There are several instances of this struct ("arenas") in this
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(). */
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,
MREMAP_MAYMOVE);
@@ -8207,3 +8219,6 @@ History:
structure of old version, but most details differ.)
*/
#endif // USE_MEMORY_PTMALLOC2