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()
C++ is pickier about when a 'goto' can cross a variable being delcared.
The fix is to just add a set of braces to restrict the variable's scope.
Without this, g++ will fail with:
regcomp.c:3057: error: jump to label 'set_call_attr'
regcomp.c:3087: error: from here
regcomp.c:3041: error: skips initialization of 'int gnum'
C++ is picker than C about when you can "goto" across a variable being
defined. The fix is to just minimize the variable's scope inside an
extra set of brackets.
Without this change, g++ has the following errors:
transcode.c:590: error: jump to label 'resume_label3'
transcode.c:514: error: from here
transcode.c:582: error: crosses initialization of 'const unsigned char* p'
transcode.c:2124: error: jump to label 'set_encs'
transcode.c:2184: error: from here
transcode.c:2088: error: skips initialization of 'const char* err'
transcode.c:2089: error: skips initialization of 'size_t error_len'
transcode.c:2090: error: skips initialization of 'mrb_value bytes'
transcode.c:2091: error: skips initialization of 'mrb_value dumped'
transcode.c:2092: error: skips initialization of 'size_t readagain_len'
transcode.c:2093: error: skips initialization of 'mrb_value bytes2'
mrb_gc_mark_ht_size() and mrb_gc_free_ht() were declared in gc.h as
taking a "RHash *" argument, but then they were defined in hash.c
as taking a "RClass *" Get these in sync.
The following is legal code in both C and C++:
struct foo {
struct bar { int a } x;
int y;
};
...however in C++ it defines a type called "foo::bar" instead of "bar".
Just avoid this construct altogether