mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
fix malloc issues on windows
This commit is contained in:
parent
9e3fb7bb6c
commit
f0df11bc39
@ -5,6 +5,10 @@
|
|||||||
#define USE_DL_PREFIX 1
|
#define USE_DL_PREFIX 1
|
||||||
#define NO_MALLINFO 1
|
#define NO_MALLINFO 1
|
||||||
|
|
||||||
|
/* Define this to enable spammy "memmatch" debug output, which can be
|
||||||
|
processed by direct/src/directscripts/memmatch.py. */
|
||||||
|
/*#define MEMMATCH 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
|
||||||
@ -2028,6 +2032,10 @@ static struct malloc_state _gm_;
|
|||||||
#define is_global(M) ((M) == &_gm_)
|
#define is_global(M) ((M) == &_gm_)
|
||||||
#define is_initialized(M) ((M)->top != 0)
|
#define is_initialized(M) ((M)->top != 0)
|
||||||
|
|
||||||
|
#ifdef MEMMATCH
|
||||||
|
static int output_counter = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* -------------------------- system alloc setup ------------------------- */
|
/* -------------------------- system alloc setup ------------------------- */
|
||||||
|
|
||||||
/* Operations on mflags */
|
/* Operations on mflags */
|
||||||
@ -4153,9 +4161,17 @@ void* dlmalloc(size_t bytes) {
|
|||||||
|
|
||||||
postaction:
|
postaction:
|
||||||
POSTACTION(gm);
|
POSTACTION(gm);
|
||||||
|
#ifdef MEMMATCH
|
||||||
|
fprintf(stderr, "memmatch %p %08d malloc(%d)\n",
|
||||||
|
mem, ++output_counter, bytes);
|
||||||
|
#endif
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MEMMATCH
|
||||||
|
fprintf(stderr, "memmatch %p %08d malloc(%d)\n",
|
||||||
|
0, ++output_counter, bytes);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4166,6 +4182,11 @@ void dlfree(void* mem) {
|
|||||||
with special cases for top, dv, mmapped chunks, and usage errors.
|
with special cases for top, dv, mmapped chunks, and usage errors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef MEMMATCH
|
||||||
|
fprintf(stderr, "memmatch %p %08d free\n",
|
||||||
|
mem, ++output_counter);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (mem != 0) {
|
if (mem != 0) {
|
||||||
mchunkptr p = mem2chunk(mem);
|
mchunkptr p = mem2chunk(mem);
|
||||||
#if FOOTERS
|
#if FOOTERS
|
||||||
|
@ -33,26 +33,24 @@
|
|||||||
inline void *operator new(size_t size) { \
|
inline void *operator new(size_t size) { \
|
||||||
return (*global_operator_new)(size); \
|
return (*global_operator_new)(size); \
|
||||||
} \
|
} \
|
||||||
inline void *operator new(size_t size, void *) { \
|
inline void *operator new(size_t size, void *ptr) { \
|
||||||
return (*global_operator_new)(size); \
|
return ptr; \
|
||||||
} \
|
} \
|
||||||
inline void operator delete(void *ptr) { \
|
inline void operator delete(void *ptr) { \
|
||||||
(*global_operator_delete)(ptr); \
|
(*global_operator_delete)(ptr); \
|
||||||
} \
|
} \
|
||||||
inline void operator delete(void *ptr, void *) { \
|
inline void operator delete(void *ptr, void *) { \
|
||||||
(*global_operator_delete)(ptr); \
|
|
||||||
} \
|
} \
|
||||||
inline void *operator new[](size_t size) { \
|
inline void *operator new[](size_t size) { \
|
||||||
return (*global_operator_new)(size); \
|
return (*global_operator_new)(size); \
|
||||||
} \
|
} \
|
||||||
inline void *operator new[](size_t size, void *) { \
|
inline void *operator new[](size_t size, void *ptr) { \
|
||||||
return (*global_operator_new)(size); \
|
return ptr; \
|
||||||
} \
|
} \
|
||||||
inline void operator delete[](void *ptr) { \
|
inline void operator delete[](void *ptr) { \
|
||||||
(*global_operator_delete)(ptr); \
|
(*global_operator_delete)(ptr); \
|
||||||
} \
|
} \
|
||||||
inline void operator delete[](void *ptr, void *) { \
|
inline void operator delete[](void *, void *) { \
|
||||||
(*global_operator_delete)(ptr); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // USE_MEMORY_NOWRAPPERS
|
#else // USE_MEMORY_NOWRAPPERS
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "config_express.h"
|
#include "config_express.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
//#include <windows.h> // for IsBadWritePtr()
|
#include <windows.h> // for IsBadWritePtr()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,15 +33,15 @@
|
|||||||
#include "config_express.h"
|
#include "config_express.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
MemoryUsage *MemoryUsage::_global_ptr = (MemoryUsage *)NULL;
|
||||||
|
|
||||||
// This flag is set true in is_counting() mode to indicate that the
|
// This flag is set true in is_counting() mode to indicate that the
|
||||||
// malloc operation is coming from C++ operator new or delete.
|
// malloc operation is coming from C++ operator new or delete.
|
||||||
static bool _is_cpp_operator = false;
|
bool MemoryUsage::_is_cpp_operator = false;
|
||||||
|
|
||||||
// This flag is used to protect the operator new/delete handlers
|
// This flag is used to protect the operator new/delete handlers
|
||||||
// against recursive entry.
|
// against recursive entry.
|
||||||
static bool _recursion_protect = false;
|
bool MemoryUsage::_recursion_protect = false;
|
||||||
|
|
||||||
MemoryUsage *MemoryUsage::_global_ptr = (MemoryUsage *)NULL;
|
|
||||||
|
|
||||||
// The cutoff ages, in seconds, for the various buckets in the AgeHistogram.
|
// The cutoff ages, in seconds, for the various buckets in the AgeHistogram.
|
||||||
double MemoryUsage::AgeHistogram::_cutoff[MemoryUsage::AgeHistogram::num_buckets] = {
|
double MemoryUsage::AgeHistogram::_cutoff[MemoryUsage::AgeHistogram::num_buckets] = {
|
||||||
@ -224,18 +224,6 @@ operator_new_handler(size_t size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
cerr << "new(" << size << ") = " << ptr << "\n";
|
|
||||||
static int counter = 0;
|
|
||||||
static int target = 0;
|
|
||||||
|
|
||||||
++counter;
|
|
||||||
if (target == 0 && counter == 1000) {
|
|
||||||
target = ConfigVariableInt("target", 10000);
|
|
||||||
}
|
|
||||||
nassertr(counter != target, ptr);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +238,6 @@ operator_new_handler(size_t size) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void MemoryUsage::
|
void MemoryUsage::
|
||||||
operator_delete_handler(void *ptr) {
|
operator_delete_handler(void *ptr) {
|
||||||
// cerr << "delete(" << ptr << ")\n";
|
|
||||||
if (_recursion_protect) {
|
if (_recursion_protect) {
|
||||||
if (express_cat.is_spam()) {
|
if (express_cat.is_spam()) {
|
||||||
express_cat.spam()
|
express_cat.spam()
|
||||||
|
@ -167,6 +167,9 @@ private:
|
|||||||
|
|
||||||
bool _track_memory_usage;
|
bool _track_memory_usage;
|
||||||
bool _count_memory_usage;
|
bool _count_memory_usage;
|
||||||
|
|
||||||
|
static bool _is_cpp_operator;
|
||||||
|
static bool _recursion_protect;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "memoryUsage.I"
|
#include "memoryUsage.I"
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "nodeReferenceCount.h"
|
#include "nodeReferenceCount.h"
|
||||||
#include "pointerTo.h"
|
#include "pointerTo.h"
|
||||||
#include "pvector.h"
|
#include "pvector.h"
|
||||||
|
#include "memoryBase.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Class : PointerToArrayElement
|
// Class : PointerToArrayElement
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "pandabase.h"
|
#include "pandabase.h"
|
||||||
#include "pnotify.h"
|
#include "pnotify.h"
|
||||||
|
#include "memoryBase.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Class : PointerToVoid
|
// Class : PointerToVoid
|
||||||
@ -33,7 +34,7 @@
|
|||||||
//
|
//
|
||||||
// This is the base class for PointerToBase<T>.
|
// This is the base class for PointerToBase<T>.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class EXPCL_PANDAEXPRESS PointerToVoid {
|
class EXPCL_PANDAEXPRESS PointerToVoid : public MemoryBase {
|
||||||
protected:
|
protected:
|
||||||
INLINE PointerToVoid();
|
INLINE PointerToVoid();
|
||||||
INLINE ~PointerToVoid();
|
INLINE ~PointerToVoid();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user