From 9e336b00e5934dbe583edfd1db6370fa4e78745d Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sun, 20 May 2012 09:43:14 -0700 Subject: More C++ compilability work: mrb_obj_alloc void* conversions One of the biggest set of changes needed to make C++ compile, is that you can't autoconvert "void*" to a different pointer type without a cast (you can of course, convert pointers *to* "void*"!) For the first part, convert the users of "mrb_obj_alloc". Since it has to return something, make it RBasic* (that's what mrb_obj_alloc() is operating on anyway). This way, even in C you'll get a warning if you don't cast it. For places where there are a lot of similar calls to mrb_obj_alloc(), this can be easily hidden through a macro. I did this in string.c: #define mrb_obj_alloc_string(mrb) ((struct RString *) mrb_obj_alloc((mrb), MRB_TT_STRING, (mrb)->string_class)) I also updated the mrb_object() macro to also return a RBasic* -- my previous commit changed that from "void*" -> "RObject*", but I figure it should be consistent with mrb_obj_alloc() --- src/proc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/proc.c') diff --git a/src/proc.c b/src/proc.c index c579d8d17..ab77e43fa 100644 --- a/src/proc.c +++ b/src/proc.c @@ -15,7 +15,7 @@ mrb_proc_new(mrb_state *mrb, mrb_irep *irep) { struct RProc *p; - p = mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class); + p = (struct RProc *) mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class); p->body.irep = irep; p->target_class = (mrb->ci) ? mrb->ci->target_class : 0; p->env = 0; @@ -30,7 +30,7 @@ mrb_closure_new(mrb_state *mrb, mrb_irep *irep) struct REnv *e; if (!mrb->ci->env) { - e = mrb_obj_alloc(mrb, MRB_TT_ENV, (struct RClass *) mrb->ci->proc->env); + e = (struct REnv *) mrb_obj_alloc(mrb, MRB_TT_ENV, (struct RClass *) mrb->ci->proc->env); e->flags= (unsigned int)mrb->ci->proc->body.irep->nlocals; e->mid = mrb->ci->mid; e->cioff = mrb->ci - mrb->cibase; @@ -49,7 +49,7 @@ mrb_proc_new_cfunc(mrb_state *mrb, mrb_func_t func) { struct RProc *p; - p = mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class); + p = (struct RProc *) mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class); p->body.func = func; p->flags |= MRB_PROC_CFUNC; -- cgit v1.2.3