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()
This commit is contained in:
Mitchell Blank Jr
2012-05-20 09:43:14 -07:00
parent ec8f97d2a6
commit 9e336b00e5
14 changed files with 42 additions and 40 deletions
+2 -2
View File
@@ -367,7 +367,7 @@ mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj)
//struct clone_method_data data;
/* copy singleton(unnamed) class */
//VALUE clone = class_alloc(RBASIC(klass)->flags, 0);
struct RClass *clone = mrb_obj_alloc(mrb, klass->tt, mrb->class_class);
struct RClass *clone = (struct RClass *) mrb_obj_alloc(mrb, klass->tt, mrb->class_class);
//clone->super = objklass->super;
if ((mrb_type(obj) == MRB_TT_CLASS) ||
@@ -452,7 +452,7 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self)
if (mrb_special_const_p(self)) {
mrb_raise(mrb, E_TYPE_ERROR, "can't clone %s", mrb_obj_classname(mrb, self));
}
clone = mrb_obj_alloc(mrb, self.tt, mrb_obj_class(mrb, self));
clone = (struct RObject *) mrb_obj_alloc(mrb, self.tt, mrb_obj_class(mrb, self));
clone->c = mrb_singleton_class_clone(mrb, self);
init_copy(mrb, mrb_obj_value(clone), self);
//1-9-2 no bug mrb_funcall(mrb, clone, "initialize_clone", 1, self);