mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-22 06:02:04 +02:00
drop deprecated function calls for Ruby 2.7
This commit is contained in:
parent
1bb8ef48f4
commit
41e604b992
2 changed files with 183 additions and 192 deletions
|
@ -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;
|
||||
|
|
|
@ -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,9 +33,7 @@
|
|||
#include "intern.h"
|
||||
#endif
|
||||
|
||||
static void
|
||||
fileIntFreeInstance(void *inst)
|
||||
{
|
||||
static void fileIntFreeInstance(void *inst) {
|
||||
SDL_RWops *ops = static_cast<SDL_RWops *>(inst);
|
||||
|
||||
SDL_RWclose(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;
|
||||
|
@ -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,27 +213,35 @@ 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"));
|
||||
|
||||
|
@ -261,9 +250,7 @@ RB_METHOD(_marshalLoad)
|
|||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
fileIntBindingInit()
|
||||
{
|
||||
void fileIntBindingInit() {
|
||||
VALUE klass = rb_define_class("FileInt", rb_cIO);
|
||||
#ifndef OLD_RUBY
|
||||
rb_define_alloc_func(klass, classAllocate<&FileIntType>);
|
||||
|
|
Loading…
Add table
Reference in a new issue