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

View file

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