Bug 549532 - Allow custom memory allocator use in spidermonkey. Part 1. r=dvander.

This commit is contained in:
Mike Moening 2010-04-16 15:03:53 -04:00
parent c2478655ef
commit 16d0ed8f28
5 changed files with 15 additions and 7 deletions

View File

@ -200,7 +200,7 @@ struct JSArenaPool {
if ((pool)->current == (a)) (pool)->current = &(pool)->first; \
*(pnext) = (a)->next; \
JS_CLEAR_ARENA(a); \
free(a); \
js_free(a); \
(a) = NULL; \
JS_END_MACRO

View File

@ -67,7 +67,7 @@
static void *
DefaultAllocTable(void *pool, size_t size)
{
return malloc(size);
return js_malloc(size);
}
static void
@ -79,7 +79,7 @@ DefaultFreeTable(void *pool, void *item, size_t size)
static JSHashEntry *
DefaultAllocEntry(void *pool, const void *key)
{
return (JSHashEntry*) malloc(sizeof(JSHashEntry));
return (JSHashEntry*) js_malloc(sizeof(JSHashEntry));
}
static void

View File

@ -836,7 +836,7 @@ js_SetSlotThreadSafe(JSContext *cx, JSObject *obj, uint32 slot, jsval v)
static JSFatLock *
NewFatlock()
{
JSFatLock *fl = (JSFatLock *)malloc(sizeof(JSFatLock)); /* for now */
JSFatLock *fl = (JSFatLock *)js_malloc(sizeof(JSFatLock)); /* for now */
if (!fl) return NULL;
fl->susp = 0;
fl->next = NULL;

View File

@ -241,9 +241,9 @@ PointerRangeSize(T *begin, T *end)
class SystemAllocPolicy
{
public:
void *malloc(size_t bytes) { return ::malloc(bytes); }
void *realloc(void *p, size_t bytes) { return ::realloc(p, bytes); }
void free(void *p) { ::free(p); }
void *malloc(size_t bytes) { return js_malloc(bytes); }
void *realloc(void *p, size_t bytes) { return js_realloc(p, bytes); }
void free(void *p) { js_free(p); }
void reportAllocOverflow() const {}
};

View File

@ -44,6 +44,7 @@
#ifndef jsutil_h___
#define jsutil_h___
#include "jstypes.h"
#include <stdlib.h>
JS_BEGIN_EXTERN_C
@ -182,6 +183,12 @@ extern JS_FRIEND_API(void)
JS_DumpBacktrace(JSCallsite *trace);
#endif
#if defined JS_USE_CUSTOM_ALLOCATOR
#include "jscustomallocator.h"
#else
static JS_INLINE void* js_malloc(size_t bytes) {
if (bytes < sizeof(void*)) /* for asyncFree */
bytes = sizeof(void*);
@ -203,6 +210,7 @@ static JS_INLINE void* js_realloc(void* p, size_t bytes) {
static JS_INLINE void js_free(void* p) {
free(p);
}
#endif/* JS_USE_CUSTOM_ALLOCATOR */
JS_END_EXTERN_C