drop deprecated function calls for Ruby 2.7

This commit is contained in:
Roza 2020-02-26 11:53:12 -05:00
parent 1bb8ef48f4
commit 41e604b992
2 changed files with 183 additions and 192 deletions

View file

@ -22,7 +22,6 @@
#include "audio.h"
#include "binding-util.h"
#include "binding.h"
#include "src/config.h"
#include "debugwriter.h"
#include "eventthread.h"
#include "filesystem.h"
@ -30,6 +29,7 @@
#include "lang-fun.h"
#include "sdl-util.h"
#include "sharedstate.h"
#include "src/config.h"
#include "src/util.h"
#include "boost-hash.h"
@ -369,10 +369,14 @@ RB_METHOD(mriRgssMain) {
while (true) {
VALUE exc = Qnil;
#if RUBYCOMPAT < 270
rb_rescue2((VALUE(*)(ANYARGS))rgssMainCb, rb_block_proc(),
(VALUE(*)(ANYARGS))rgssMainRescue, (VALUE)&exc, rb_eException,
(VALUE)0);
#else
rb_rescue2(rgssMainCb, rb_block_proc(), rgssMainRescue, (VALUE)&exc,
rb_eException, (VALUE)0);
#endif
if (NIL_P(exc))
break;

View file

@ -21,8 +21,8 @@
#include "binding-util.h"
#include "sharedstate.h"
#include "filesystem.h"
#include "sharedstate.h"
#include "src/config.h"
#include "src/util.h"
@ -33,10 +33,8 @@
#include "intern.h"
#endif
static void
fileIntFreeInstance(void *inst)
{
SDL_RWops *ops = static_cast<SDL_RWops*>(inst);
static void fileIntFreeInstance(void *inst) {
SDL_RWops *ops = static_cast<SDL_RWops *>(inst);
SDL_RWclose(ops);
SDL_FreeRW(ops);
@ -48,17 +46,12 @@ DEF_TYPE_CUSTOMFREE(FileInt, fileIntFreeInstance);
DEF_ALLOCFUNC_CUSTOMFREE(FileInt, fileIntFreeInstance);
#endif
static VALUE
fileIntForPath(const char *path, bool rubyExc)
{
static VALUE fileIntForPath(const char *path, bool rubyExc) {
SDL_RWops *ops = SDL_AllocRW();
try
{
try {
shState->fileSystem().openReadRaw(*ops, path);
}
catch (const Exception &e)
{
} catch (const Exception &e) {
SDL_FreeRW(ops);
if (rubyExc)
@ -76,23 +69,22 @@ fileIntForPath(const char *path, bool rubyExc)
return obj;
}
RB_METHOD(fileIntRead)
{
RB_METHOD(fileIntRead) {
int length = -1;
rb_get_args(argc, argv, "|i", &length RB_ARG_END);
SDL_RWops *ops = getPrivateData<SDL_RWops>(self);
if (length == -1)
{
if (length == -1) {
Sint64 cur = SDL_RWtell(ops);
Sint64 end = SDL_RWseek(ops, 0, SEEK_END);
// Sometimes SDL_RWseek will fail for no reason
// with encrypted archives, so let's just ask
// for the size up front
if (end < 0) end = ops->size(ops);
if (end < 0)
end = ops->size(ops);
length = end - cur;
SDL_RWseek(ops, cur, SEEK_SET);
@ -108,8 +100,7 @@ RB_METHOD(fileIntRead)
return data;
}
RB_METHOD(fileIntClose)
{
RB_METHOD(fileIntClose) {
RB_UNUSED_PARAM;
SDL_RWops *ops = getPrivateData<SDL_RWops>(self);
@ -118,8 +109,7 @@ RB_METHOD(fileIntClose)
return Qnil;
}
RB_METHOD(fileIntGetByte)
{
RB_METHOD(fileIntGetByte) {
RB_UNUSED_PARAM;
SDL_RWops *ops = getPrivateData<SDL_RWops>(self);
@ -130,15 +120,13 @@ RB_METHOD(fileIntGetByte)
return (result == 1) ? rb_fix_new(byte) : Qnil;
}
RB_METHOD(fileIntBinmode)
{
RB_METHOD(fileIntBinmode) {
RB_UNUSED_PARAM;
return Qnil;
}
RB_METHOD(fileIntPos)
{
RB_METHOD(fileIntPos) {
SDL_RWops *ops = getPrivateData<SDL_RWops>(self);
long long pos = SDL_RWtell(ops); // Will return -1 if it doesn't work
@ -146,22 +134,18 @@ RB_METHOD(fileIntPos)
}
VALUE
kernelLoadDataInt(const char *filename, bool rubyExc, bool raw)
{
kernelLoadDataInt(const char *filename, bool rubyExc, bool raw) {
rb_gc_start();
VALUE port = fileIntForPath(filename, rubyExc);
VALUE result;
if (!raw)
{
if (!raw) {
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
// FIXME need to catch exceptions here with begin rescue
VALUE data = fileIntRead(0, 0, port);
result = rb_funcall2(marsh, rb_intern("load"), 1, &data);
}
else
{
} else {
result = fileIntRead(0, 0, port);
}
@ -170,8 +154,7 @@ kernelLoadDataInt(const char *filename, bool rubyExc, bool raw)
return result;
}
RB_METHOD(kernelLoadData)
{
RB_METHOD(kernelLoadData) {
RB_UNUSED_PARAM;
VALUE filename;
@ -180,20 +163,15 @@ RB_METHOD(kernelLoadData)
SafeStringValue(filename);
// There's gotta be an easier way to do this
if (raw != Qnil && raw != Qtrue && raw != Qfalse)
{
if (raw != Qnil && raw != Qtrue && raw != Qfalse) {
rb_raise(rb_eTypeError, "load_data: second argument must be Boolean");
}
if (!shState->config().encryptedGraphics)
{
VALUE isGraphicsFile = rb_funcall(filename,
rb_intern("start_with?"),
1,
if (!shState->config().encryptedGraphics) {
VALUE isGraphicsFile = rb_funcall(filename, rb_intern("start_with?"), 1,
rb_str_new2("Graphics"));
if (isGraphicsFile == Qtrue)
{
if (isGraphicsFile == Qtrue) {
VALUE f = rb_file_open_str(filename, "rb");
VALUE ret = rb_funcall(f, rb_intern("read"), 0);
rb_funcall(f, rb_intern("close"), 0);
@ -203,8 +181,7 @@ RB_METHOD(kernelLoadData)
return kernelLoadDataInt(RSTRING_PTR(filename), true, RTEST(raw));
}
RB_METHOD(kernelSaveData)
{
RB_METHOD(kernelSaveData) {
RB_UNUSED_PARAM;
VALUE obj;
@ -216,7 +193,7 @@ RB_METHOD(kernelSaveData)
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
VALUE v[] = { obj, file };
VALUE v[] = {obj, file};
rb_funcall2(marsh, rb_intern("dump"), ARRAY_SIZE(v), v);
rb_io_close(file);
@ -224,7 +201,11 @@ RB_METHOD(kernelSaveData)
return Qnil;
}
#ifndef OLD_RUBY
#if RUBYCOMPAT < 270
static VALUE stringForceUTF8(VALUE arg)
#else
static VALUE stringForceUTF8(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, arg))
#endif
{
if (RB_TYPE_P(arg, RUBY_T_STRING) && ENCODING_IS_ASCII8BIT(arg))
rb_enc_associate_index(arg, rb_utf8_encindex());
@ -232,38 +213,44 @@ static VALUE stringForceUTF8(VALUE arg)
return arg;
}
static VALUE customProc(VALUE arg, VALUE proc)
{
#if RUBYCOMPAT < 270
static VALUE customProc(VALUE arg, VALUE proc) {
VALUE obj = stringForceUTF8(arg);
obj = rb_funcall2(proc, rb_intern("call"), 1, &obj);
return obj;
}
#endif
RB_METHOD(_marshalLoad)
{
RB_METHOD(_marshalLoad) {
RB_UNUSED_PARAM;
#if RUBYCOMPAT < 270
VALUE port, proc = Qnil;
rb_get_args(argc, argv, "o|o", &port, &proc RB_ARG_END);
#else
VALUE port;
rb_get_args(argc, argv, "o", &port RB_ARG_END);
#endif
VALUE utf8Proc;
#if RUBYCOMPAT < 270
if (NIL_P(proc))
utf8Proc = rb_proc_new(RUBY_METHOD_FUNC(stringForceUTF8), Qnil);
else
utf8Proc = rb_proc_new(RUBY_METHOD_FUNC(customProc), proc);
#else
utf8Proc = rb_proc_new(stringForceUTF8, Qnil);
#endif
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
VALUE v[] = { port, utf8Proc };
VALUE v[] = {port, utf8Proc};
return rb_funcall2(marsh, rb_intern("_mkxp_load_alias"), ARRAY_SIZE(v), v);
}
#endif
void
fileIntBindingInit()
{
void fileIntBindingInit() {
VALUE klass = rb_define_class("FileInt", rb_cIO);
#ifndef OLD_RUBY
rb_define_alloc_func(klass, classAllocate<&FileIntType>);
@ -294,4 +281,4 @@ fileIntBindingInit()
rb_define_alias(rb_singleton_class(marsh), "_mkxp_load_alias", "load");
_rb_define_module_function(marsh, "load", _marshalLoad);
#endif
}
}