Skip to content

Commit

Permalink
fix excess allocation in boxing functions. helps #10954
Browse files Browse the repository at this point in the history
the alloc_*w functions were changed to refer to size not including
tag, but these functions were not updated.
  • Loading branch information
JeffBezanson authored and carnaval committed Apr 27, 2015
1 parent ffb6b95 commit 7a0e464
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
36 changes: 18 additions & 18 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,13 @@ jl_value_t *jl_box##nb(jl_datatype_t *t, int##nb##_t x) \
*(int##nb##_t*)jl_data_ptr(v) = x; \
return v; \
}
BOXN_FUNC(8, 2)
BOXN_FUNC(16, 2)
BOXN_FUNC(32, 2)
BOXN_FUNC(8, 1)
BOXN_FUNC(16, 1)
BOXN_FUNC(32, 1)
#ifdef _P64
BOXN_FUNC(64, 2)
BOXN_FUNC(64, 1)
#else
BOXN_FUNC(64, 3)
BOXN_FUNC(64, 2)
#endif

#define UNBOX_FUNC(j_type,c_type) \
Expand Down Expand Up @@ -710,12 +710,12 @@ jl_value_t *pfx##_##typ(c_type x) \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
}
BOX_FUNC(float32, float, jl_box, 2)
BOX_FUNC(voidpointer, void*, jl_box, 2) //2 pointers == two words on all platforms
BOX_FUNC(float32, float, jl_box, 1)
BOX_FUNC(voidpointer, void*, jl_box, 1)
#ifdef _P64
BOX_FUNC(float64, double, jl_box, 2)
BOX_FUNC(float64, double, jl_box, 1)
#else
BOX_FUNC(float64, double, jl_box, 3)
BOX_FUNC(float64, double, jl_box, 2)
#endif

#define NBOX_C 1024
Expand Down Expand Up @@ -743,18 +743,18 @@ jl_value_t *jl_box_##typ(c_type x) \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
}
SIBOX_FUNC(int16, int16_t, 2)
SIBOX_FUNC(int32, int32_t, 2)
UIBOX_FUNC(uint16, uint16_t, 2)
UIBOX_FUNC(uint32, uint32_t, 2)
UIBOX_FUNC(char, uint32_t, 2)
UIBOX_FUNC(gensym, size_t, 2)
SIBOX_FUNC(int16, int16_t, 1)
SIBOX_FUNC(int32, int32_t, 1)
UIBOX_FUNC(uint16, uint16_t, 1)
UIBOX_FUNC(uint32, uint32_t, 1)
UIBOX_FUNC(char, uint32_t, 1)
UIBOX_FUNC(gensym, size_t, 1)
#ifdef _P64
SIBOX_FUNC(int64, int64_t, 1)
UIBOX_FUNC(uint64, uint64_t, 1)
#else
SIBOX_FUNC(int64, int64_t, 2)
UIBOX_FUNC(uint64, uint64_t, 2)
#else
SIBOX_FUNC(int64, int64_t, 3)
UIBOX_FUNC(uint64, uint64_t, 3)
#endif

static jl_value_t *boxed_int8_cache[256];
Expand Down
5 changes: 2 additions & 3 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,15 +636,14 @@ static Value *emit_pointerref(jl_value_t *e, jl_value_t *i, jl_codectx_t *ctx)
uint64_t size = jl_datatype_size(ety);
Value *strct =
builder.CreateCall(prepare_call(jlallocobj_func),
ConstantInt::get(T_size,
sizeof(void*)+size));
ConstantInt::get(T_size, sizeof(void*)+size));
builder.CreateStore(literal_pointer_val((jl_value_t*)ety),
emit_typeptr_addr(strct));
im1 = builder.CreateMul(im1, ConstantInt::get(T_size,
LLT_ALIGN(size, ((jl_datatype_t*)ety)->alignment)));
thePtr = builder.CreateGEP(builder.CreateBitCast(thePtr, T_pint8), im1);
builder.CreateMemCpy(builder.CreateBitCast(strct, T_pint8),
thePtr, size, 1);
thePtr, size, 1);
return mark_julia_type(strct, ety);
}
// TODO: alignment?
Expand Down

0 comments on commit 7a0e464

Please sign in to comment.