Permalink
Browse files

allocf should take ud; https://twitter.com/junjis0203/status/23694997…

  • Loading branch information...
1 parent 9206dcb commit b8fc484d2ea97e8eb6bc25744d3e192580e1504d @matz matz committed Aug 18, 2012
Showing with 9 additions and 9 deletions.
  1. +2 −2 include/mruby.h
  2. +3 −3 src/gc.c
  3. +4 −4 src/state.c
View
@@ -41,7 +41,7 @@ typedef int32_t mrb_code;
struct mrb_state;
-typedef void* (*mrb_allocf) (struct mrb_state *mrb, void*, size_t);
+typedef void* (*mrb_allocf) (struct mrb_state *mrb, void*, size_t, void *ud);
#ifndef MRB_ARENA_SIZE
#define MRB_ARENA_SIZE 1024
@@ -205,7 +205,7 @@ mrb_value mrb_str_new_cstr(mrb_state*, const char*);
mrb_value mrb_str_new2(mrb_state *mrb, const char *p);
mrb_state* mrb_open(void);
-mrb_state* mrb_open_allocf(mrb_allocf);
+mrb_state* mrb_open_allocf(mrb_allocf, void *ud);
void mrb_close(mrb_state*);
int mrb_checkstack(mrb_state*,int);
View
@@ -153,11 +153,11 @@ mrb_realloc(mrb_state *mrb, void *p, size_t len)
{
void *p2;
- p2 = (mrb->allocf)(mrb, p, len);
+ p2 = (mrb->allocf)(mrb, p, len, mrb->ud);
if (!p2 && len > 0 && mrb->heaps) {
mrb_garbage_collect(mrb);
- p2 = (mrb->allocf)(mrb, p, len);
+ p2 = (mrb->allocf)(mrb, p, len, mrb->ud);
}
return p2;
}
@@ -188,7 +188,7 @@ mrb_calloc(mrb_state *mrb, size_t nelem, size_t len)
void*
mrb_free(mrb_state *mrb, void *p)
{
- return (mrb->allocf)(mrb, p, 0);
+ return (mrb->allocf)(mrb, p, 0, mrb->ud);
}
#ifndef MRB_HEAP_PAGE_SIZE
View
@@ -14,9 +14,9 @@ void mrb_init_core(mrb_state*);
void mrb_init_ext(mrb_state*);
mrb_state*
-mrb_open_allocf(mrb_allocf f)
+mrb_open_allocf(mrb_allocf f, void *ud)
{
- mrb_state *mrb = (mrb_state *)(f)(NULL, NULL, sizeof(mrb_state));
+ mrb_state *mrb = (mrb_state *)(f)(NULL, NULL, sizeof(mrb_state), ud);
if (mrb == NULL) return NULL;
memset(mrb, 0, sizeof(mrb_state));
@@ -30,7 +30,7 @@ mrb_open_allocf(mrb_allocf f)
}
static void*
-allocf(mrb_state *mrb, void *p, size_t size)
+allocf(mrb_state *mrb, void *p, size_t size, void *ud)
{
if (size == 0) {
free(p);
@@ -44,7 +44,7 @@ allocf(mrb_state *mrb, void *p, size_t size)
mrb_state*
mrb_open()
{
- mrb_state *mrb = mrb_open_allocf(allocf);
+ mrb_state *mrb = mrb_open_allocf(allocf, NULL);
return mrb;
}

4 comments on commit b8fc484

Contributor

junjis0203 commented on b8fc484 Aug 19, 2012

mrb_state.ud is a pointer for any purpose.
So, I think another pointer must be added for mrb_allocf.

Owner

matz replied Aug 19, 2012

In Lua, ud is used only for allocf. Do we really need other ud?

Contributor

junjis0203 replied Aug 25, 2012

ud is added by masuidrive. I think he uses ud for other purpose.

Owner

matz replied Aug 25, 2012

If someone needs to use application ud and malloc ud at the same time, he/she will submit an issue.

Please sign in to comment.