summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-12-04 16:40:59 +0900
committerKOBAYASHI Shuji <[email protected]>2019-12-04 22:21:00 +0900
commita030446a94fc18bd2b6881f697417df3f0ddb179 (patch)
treed5298c35e448a615d6c7bd293647bdff5825ecba /src
parentbc22991ac3ec08fa9e48fc46e49e69115a386ed9 (diff)
downloadmruby-a030446a94fc18bd2b6881f697417df3f0ddb179.tar.gz
mruby-a030446a94fc18bd2b6881f697417df3f0ddb179.zip
Refine `mrb_alloca()`
* The allocated memory is guaranteed to be aligned for any data type (it was not guaranteed when string type is embed). * Make allocation size exactly specified size (does not allocate space for a null byte).
Diffstat (limited to 'src')
-rw-r--r--src/gc.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/gc.c b/src/gc.c
index 2fe1d59c9..40c85a373 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -280,8 +280,9 @@ mrb_free(mrb_state *mrb, void *p)
MRB_API void*
mrb_alloca(mrb_state *mrb, size_t size)
{
- mrb_value str = mrb_str_new(mrb, NULL, size);
- return RSTRING_PTR(str);
+ struct RString *s;
+ s = (struct RString*)mrb_obj_alloc(mrb, MRB_TT_STRING, mrb->string_class);
+ return s->as.heap.ptr = (char*)mrb_malloc(mrb, size);
}
static mrb_bool