Skip to content

Commit

Permalink
Add field allocf_ud to replace current ud.
Browse files Browse the repository at this point in the history
Since some use it as `mrb_state` associated user data.
  • Loading branch information
take-cheeze committed Jul 17, 2014
1 parent d17506c commit fc9a91c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/mruby.h
Expand Up @@ -112,6 +112,7 @@ typedef struct mrb_state {
struct mrb_jmpbuf *jmp;

mrb_allocf allocf; /* memory allocation function */
void *allocf_ud; /* auxiliary data of allocf */

struct mrb_context *c;
struct mrb_context *root_c;
Expand Down
6 changes: 3 additions & 3 deletions src/gc.c
Expand Up @@ -171,10 +171,10 @@ mrb_realloc_simple(mrb_state *mrb, void *p, size_t len)
{
void *p2;

p2 = (mrb->allocf)(mrb, p, len, mrb->ud);
p2 = (mrb->allocf)(mrb, p, len, mrb->allocf_ud);
if (!p2 && len > 0 && mrb->heaps) {
mrb_full_gc(mrb);
p2 = (mrb->allocf)(mrb, p, len, mrb->ud);
p2 = (mrb->allocf)(mrb, p, len, mrb->allocf_ud);
}

return p2;
Expand Down Expand Up @@ -240,7 +240,7 @@ mrb_calloc(mrb_state *mrb, size_t nelem, size_t len)
void
mrb_free(mrb_state *mrb, void *p)
{
(mrb->allocf)(mrb, p, 0, mrb->ud);
(mrb->allocf)(mrb, p, 0, mrb->allocf_ud);
}

#ifndef MRB_HEAP_PAGE_SIZE
Expand Down
2 changes: 1 addition & 1 deletion src/state.c
Expand Up @@ -37,7 +37,7 @@ mrb_open_core(mrb_allocf f, void *ud)
if (mrb == NULL) return NULL;

*mrb = mrb_state_zero;
mrb->ud = ud;
mrb->allocf_ud = ud;
mrb->allocf = f;
mrb->current_white_part = MRB_GC_WHITE_A;
mrb->atexit_stack_len = 0;
Expand Down

0 comments on commit fc9a91c

Please sign in to comment.