Make alloc policy realloc() easier to implement (bug 664353, r=luke).

This commit is contained in:
David Anderson 2011-06-15 18:11:59 -07:00
Родитель 029df9a3ef
Коммит 012fd6ce4c
3 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -52,6 +52,9 @@ namespace js {
* Responsible for OOM reporting on NULL return value.
* - void *realloc_(size_t)
* Responsible for OOM reporting on NULL return value.
* The *used* bytes of the previous buffer is passed in
* (rather than the old allocation size), in addition to
* the *new* allocation size requested.
* - void free_(void *)
* - reportAllocOverflow()
* Called on overflow before the container returns NULL.
@ -62,7 +65,7 @@ class SystemAllocPolicy
{
public:
void *malloc_(size_t bytes) { return js_malloc(bytes); }
void *realloc_(void *p, size_t bytes) { return js_realloc(p, bytes); }
void *realloc_(void *p, size_t oldBytes, size_t bytes) { return js_realloc(p, bytes); }
void free_(void *p) { js_free(p); }
void reportAllocOverflow() const {}
};
@ -100,7 +103,7 @@ class ContextAllocPolicy
return p;
}
void *realloc_(void *p, size_t bytes) {
void *realloc_(void *p, size_t oldBytes, size_t bytes) {
void *p2 = js_realloc(p, bytes);
if (JS_UNLIKELY(!p2))
p2 = onOutOfMemory(p2, bytes);

Просмотреть файл

@ -158,7 +158,8 @@ struct VectorImpl<T, N, AP, true>
static inline bool growTo(Vector<T,N,AP> &v, size_t newcap) {
JS_ASSERT(!v.usingInlineStorage());
size_t bytes = sizeof(T) * newcap;
T *newbuf = reinterpret_cast<T *>(v.realloc_(v.mBegin, bytes));
size_t oldBytes = sizeof(T) * v.mLength;
T *newbuf = reinterpret_cast<T *>(v.realloc_(v.mBegin, oldBytes, bytes));
if (!newbuf)
return false;
v.mBegin = newbuf;

Просмотреть файл

@ -286,8 +286,8 @@ class CompilerAllocPolicy : public ContextAllocPolicy
CompilerAllocPolicy(JSContext *cx, Compiler &compiler);
void *malloc_(size_t bytes) { return checkAlloc(ContextAllocPolicy::malloc_(bytes)); }
void *realloc_(void *p, size_t bytes) {
return checkAlloc(ContextAllocPolicy::realloc_(p, bytes));
void *realloc_(void *p, size_t oldBytes, size_t bytes) {
return checkAlloc(ContextAllocPolicy::realloc_(p, oldBytes, bytes));
}
};