Add MRI 1.8 Support #163

Open
Ghabry wants to merge 3 commits from Ghabry/mri-1.8 into master
3 changed files with 78 additions and 30 deletions
Showing only changes of commit 7ef1213b37 - Show all commits

View File

@ -585,7 +585,6 @@ static void mriBindingExecute()
#if RUBY_API_VERSION_MAJOR == 1
ruby_init();
//ruby_options(argc, argv);
#else
ruby_sysinit(&argc, &argv);
ruby_setup();

View File

@ -91,16 +91,16 @@ void
raiseDisposedAccess(VALUE self)
{
#ifdef RUBY_LEGACY_VERSION
// FIXME: raiseDisposedAccess not implemented
const char *klassName = rb_class2name(self);
#else
const char *klassName = RTYPEDDATA_TYPE(self)->wrap_struct_name;
#endif
char buf[32];
strncpy(buf, klassName, sizeof(buf));
buf[0] = tolower(buf[0]);
rb_raise(getRbData()->exc[RGSS], "disposed %s", buf);
#endif
}
int
@ -325,72 +325,120 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
}
#if RUBY_API_VERSION_MAJOR == 1
NORETURN(void rb_error_arity(int, int, int)) {
NORETURN(void rb_error_arity(int, int, int))
{
assert(false);
}
#if RUBY_API_VERSION_MINOR == 8
// Functions providing Ruby 1.8 compatibililty
VALUE rb_sprintf(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
/*
Functions providing Ruby 1.8 compatibililty.
All encoding related functions return dummy values because mkxp only uses them
to retrieve the UTF-8 encoding.
*/
VALUE rb_sprintf_vararg(const char* fmt, va_list args) {
char buf[4096];
int const result = vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
int result = vsnprintf(buf, sizeof(buf), fmt, args);
if (result < 0) {
buf[0] = '\0';
}
return rb_str_new2(buf);
}
VALUE rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t * rbType) {
VALUE rb_sprintf(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
VALUE val = rb_sprintf_vararg(fmt, args);
va_end(args);
return val;
}
VALUE rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *rbType)
{
return rb_data_object_alloc(klass, 0, rbType->function.dmark, rbType->function.dfree);
}
void *rb_check_typeddata(VALUE v, const rb_data_type_t *) {
// FIXME: rb_check_typeddata not implemented
return RTYPEDDATA_DATA(v);
void *rb_check_typeddata(VALUE value, const rb_data_type_t* typed)
{
// FIXME: Won't work because rb_typeddata_is_kind_of is not implemented
if (!rb_typeddata_is_kind_of(value, typed)) {
rb_raise(getRbData()->exc[RGSS],
"wrong data type %s (expected %s)", rb_class2name(value), typed->wrap_struct_name
);
}
return RTYPEDDATA_DATA(value);
}
VALUE rb_enc_str_new(const char* ch, long len, rb_encoding*) {
VALUE rb_enc_str_new(const char* ch, long len, rb_encoding*)
{
// Encoding is ignored
return rb_str_new(ch, len);
}
rb_encoding *rb_utf8_encoding(void) {
rb_encoding *rb_utf8_encoding(void)
{
// not relevant
return NULL;
}
void rb_enc_set_default_external(VALUE encoding) {
// no-op, assuming UTF-8
void rb_enc_set_default_external(VALUE)
{
// not relevant
Ancurio commented 2017-05-19 18:14:34 +00:00 (Migrated from github.com)
Review

missing newline at end

missing newline at end
}
VALUE rb_enc_from_encoding(rb_encoding *enc) {
VALUE rb_enc_from_encoding(rb_encoding*)
{
// not relevant
return Qnil;
}
VALUE rb_str_catf(VALUE, const char*, ...) {
return Qnil;
VALUE rb_str_catf(VALUE value, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
VALUE second = rb_sprintf_vararg(fmt, args);
va_end(args);
return rb_str_concat(value, second);
}
VALUE rb_errinfo(void) {
VALUE rb_errinfo(void)
{
return ruby_errinfo;
}
int rb_typeddata_is_kind_of(VALUE, const rb_data_type_t *) {
int rb_typeddata_is_kind_of(VALUE value, const rb_data_type_t* typed)
{
// FIXME: rb_typeddata_is_kind_of not implemented
return 1;
}
VALUE rb_file_open_str(VALUE filename, const char* mode) {
VALUE rb_file_open_str(VALUE filename, const char* mode)
{
return rb_file_open(RB_OBJ_STRING(filename), mode);
}
VALUE rb_enc_associate_index(VALUE, int) {
VALUE rb_enc_associate_index(VALUE, int)
{
// not relevant
return Qnil;
}
int rb_utf8_encindex(void) {
int rb_utf8_encindex(void)
{
// not relevant
return 0;
}
VALUE rb_hash_lookup2(VALUE, VALUE, VALUE) {
return Qnil;
VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE def)
{
VALUE v = rb_hash_lookup(hash, key);
return (v == Qnil) ? def : v;
}
#endif // RUBY_API_VERSION_MINOR == 8
#endif // RUBY_API_VERSION_MAJOR == 1

View File

@ -132,6 +132,7 @@ kernelLoadDataInt(const char *filename, bool rubyExc)
VALUE port = fileIntForPath(filename, rubyExc);
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
// FIXME need to catch exceptions here with begin rescue
VALUE result = rb_funcall2(marsh, rb_intern("load"), 1, &port);