summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-05-28 10:44:18 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2019-05-29 11:47:12 +0900
commit2b81ea7ec1c7645b13b097e5b249cbc99f374da7 (patch)
tree94ed8b8da63e535477da932ddc05da67f137408a /src
parenta1e1af44d205c2c29608f508cce84d6b6ebd2bbf (diff)
downloadmruby-2b81ea7ec1c7645b13b097e5b249cbc99f374da7.tar.gz
mruby-2b81ea7ec1c7645b13b097e5b249cbc99f374da7.zip
Add `mrb_alloca` again; ref #4470
This time, the allocated memory comes from the string object, which is referenced from GC arena. The memory region will be reclaimed when the C function called from VM is terminated, or the GC arena is restored.
Diffstat (limited to 'src')
-rw-r--r--src/gc.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/gc.c b/src/gc.c
index 6dc8e373b..94068c0f9 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -277,6 +277,13 @@ mrb_free(mrb_state *mrb, void *p)
(mrb->allocf)(mrb, p, 0, mrb->allocf_ud);
}
+MRB_API void*
+mrb_alloca(mrb_state *mrb, size_t size)
+{
+ mrb_value str = mrb_str_new(mrb, NULL, size);
+ return RSTRING_PTR(str);
+}
+
static mrb_bool
heap_p(mrb_gc *gc, struct RBasic *object)
{