mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-14 04:03:47 +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.
|
||||
* - 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));
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user