Make alloc policy realloc() easier to implement

RESOLVED FIXED

Status

()

Core
JavaScript Engine
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: dvander, Assigned: dvander)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

Created attachment 539397 [details] [diff] [review]
fix

realloc() is annoying to implement in a bump allocator like IonAllocPolicy, so this changes jsvector to pass in the old size.
Attachment #539397 - Flags: review?(luke)

Comment 1

6 years ago
Comment on attachment 539397 [details] [diff] [review]
fix

Review of attachment 539397 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/ion/IonAllocPolicy.h
@@ +62,5 @@
> +    void *realloc_(void *p, size_t oldBytes, size_t bytes) {
> +        void *n = malloc_(bytes);
> +        if (!n)
> +            return n;
> +        memcpy(n, p, oldBytes);

In theory, bytes can be less than oldBytes in which case you need a Min() here.

::: js/src/jsvector.h
@@ +157,5 @@
>  
>      static inline bool growTo(Vector<T,N,AP> &v, size_t newcap) {
>          JS_ASSERT(!v.usingInlineStorage());
>          size_t bytes = sizeof(T) * newcap;
> +        size_t oldBytes = sizeof(T) * v.mLength;

Could you comment in jsalloc.h (first big comment) that realloc is passed the *used* bytes of the previous buffer, and not the total bytes allocated.
Attachment #539397 - Flags: review?(luke) → review+
http://hg.mozilla.org/tracemonkey/rev/21e26c404883
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.