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/vm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/vm.c') diff --git a/src/vm.c b/src/vm.c index 944116d14..aa9fde0fe 100644 --- a/src/vm.c +++ b/src/vm.c @@ -279,7 +279,7 @@ localjump_error(mrb_state *mrb, const char *kind) snprintf(buf, 256, "unexpected %s", kind); exc = mrb_exc_new(mrb, E_LOCALJUMP_ERROR, buf, strlen(buf)); - mrb->exc = mrb_object(exc); + mrb->exc = (struct RObject *) mrb_object(exc); } static void @@ -298,7 +298,7 @@ argnum_error(mrb_state *mrb, int num) mrb->ci->argc, num); } exc = mrb_exc_new(mrb, E_ARGUMENT_ERROR, buf, strlen(buf)); - mrb->exc = mrb_object(exc); + mrb->exc = (struct RObject *) mrb_object(exc); } #define SET_TRUE_VALUE(r) {\ @@ -625,7 +625,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) CASE(OP_RAISE) { /* A raise(R(A)) */ - mrb->exc = mrb_object(regs[GETARG_A(i)]); + mrb->exc = (struct RObject *) mrb_object(regs[GETARG_A(i)]); goto L_RAISE; } @@ -1573,7 +1573,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) mrb_value msg = pool[GETARG_Bx(i)]; mrb_value exc = mrb_exc_new3(mrb, mrb->eRuntimeError_class, msg); - mrb->exc = mrb_object(exc); + mrb->exc = (struct RObject *) mrb_object(exc); goto L_RAISE; } } -- cgit v1.2.3