mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-14 12:13:22 +00:00
Make alloc policy realloc() easier to implement (bug 664353, r=luke).
This commit is contained in:
parent
029df9a3ef
commit
012fd6ce4c
@ -52,6 +52,9 @@ namespace js {
|
|||||||
* Responsible for OOM reporting on NULL return value.
|
* Responsible for OOM reporting on NULL return value.
|
||||||
* - void *realloc_(size_t)
|
* - void *realloc_(size_t)
|
||||||
* Responsible for OOM reporting on NULL return value.
|
* 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 *)
|
* - void free_(void *)
|
||||||
* - reportAllocOverflow()
|
* - reportAllocOverflow()
|
||||||
* Called on overflow before the container returns NULL.
|
* Called on overflow before the container returns NULL.
|
||||||
@ -62,7 +65,7 @@ class SystemAllocPolicy
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void *malloc_(size_t bytes) { return js_malloc(bytes); }
|
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 free_(void *p) { js_free(p); }
|
||||||
void reportAllocOverflow() const {}
|
void reportAllocOverflow() const {}
|
||||||
};
|
};
|
||||||
@ -100,7 +103,7 @@ class ContextAllocPolicy
|
|||||||
return p;
|
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);
|
void *p2 = js_realloc(p, bytes);
|
||||||
if (JS_UNLIKELY(!p2))
|
if (JS_UNLIKELY(!p2))
|
||||||
p2 = onOutOfMemory(p2, bytes);
|
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) {
|
static inline bool growTo(Vector<T,N,AP> &v, size_t newcap) {
|
||||||
JS_ASSERT(!v.usingInlineStorage());
|
JS_ASSERT(!v.usingInlineStorage());
|
||||||
size_t bytes = sizeof(T) * newcap;
|
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)
|
if (!newbuf)
|
||||||
return false;
|
return false;
|
||||||
v.mBegin = newbuf;
|
v.mBegin = newbuf;
|
||||||
|
@ -286,8 +286,8 @@ class CompilerAllocPolicy : public ContextAllocPolicy
|
|||||||
CompilerAllocPolicy(JSContext *cx, Compiler &compiler);
|
CompilerAllocPolicy(JSContext *cx, Compiler &compiler);
|
||||||
|
|
||||||
void *malloc_(size_t bytes) { return checkAlloc(ContextAllocPolicy::malloc_(bytes)); }
|
void *malloc_(size_t bytes) { return checkAlloc(ContextAllocPolicy::malloc_(bytes)); }
|
||||||
void *realloc_(void *p, size_t bytes) {
|
void *realloc_(void *p, size_t oldBytes, size_t bytes) {
|
||||||
return checkAlloc(ContextAllocPolicy::realloc_(p, bytes));
|
return checkAlloc(ContextAllocPolicy::realloc_(p, oldBytes, bytes));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user