Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MRI 1.8 Support #163

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add MRI 1.8 Support #163

wants to merge 3 commits into from

Conversation

Ghabry
Copy link

@Ghabry Ghabry commented May 12, 2017

This allows compiling of mkxp against Ruby 1.8.7 (tested with p374).

To test that it works simply start a RPG Maker XP game. If you get "Win32Api not found" instead of "Syntax error" it works ;).

This is mostly implemented by providing wrapper functions and macros (mostly copy-pasted from ruby 2.4) in binding-util.h.

Known issues:

  • Everything encoding related is no-op by now. Includes the UTF8-Marhsaller. Guess I need to use the iconv-module here. I know that ruby reworked the whole encoding code in Ruby 2 but my Ruby knowledge is almost zero so I'm a bit lost here :(
  • ruby_option (like ruby_sysinit) segfaults when called. call removed for now
  • rb_check_typeddata not implemented
  • rb_typeddata_is_kind_of not implemented
  • rb_hash_lookup2 not implemented but this is only in a RGSS3 codepath, so not relevant
  • rb_str_catf not implemented (so no stacktrace printed in error case)
  • raiseDisposedAccess will never raise

That typed data stuff was a bit tricky to fake because Ruby 1.8 does not have this typed data struct. But is good enough to launch games. Though some sanity checks are missing (see issues above)

To The Moon (Windows version) with 2.4 MRI:
screenshot_20170512_023350

With 1.8 MRI:
screenshot_20170512_023314

With 1.8 MRI and some WinApi emulation (Mouse cursor is stuck):
screenshot_20170512_023212

@Ghabry
Copy link
Author

Ghabry commented May 12, 2017

Also fixed compile for MRI 1.9, but this crashes with
"[BUG] object allocation during garbage collection phase"
on startup >.>

Copy link
Owner

@Ancurio Ancurio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the minor formatting, I can't comment too much on the 1.8 since I'm not familiar with the differences to 2.x, but I'd really like to get this merged to start the effort even if not everything is working yet.

Thanks for your work!


#if RUBY_API_VERSION_MAJOR == 1
ruby_init();
//ruby_options(argc, argv);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this somehow segfaults Ruby and I have no idea why. Will remove it.

@@ -90,13 +90,17 @@ void raiseRbExc(const Exception &exc)
void
raiseDisposedAccess(VALUE self)
{
#if RUBY_API_VERSION_MAJOR == 1
// FIXME: raiseDisposedAccess not implemented
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue with implementing this in 1.8? Does 1.8 not allow raising exceptions from C?

Edit: Oh it probably has to do with getting the class name from the typed data object, I see.

@@ -319,3 +323,73 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)

return argI;
}

#if RUBY_API_VERSION_MAJOR == 1
// Functions providing Ruby 1.8 compatibililty
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use /* */ for documentative comments


#if RUBY_API_VERSION_MAJOR == 1
// Functions providing Ruby 1.8 compatibililty
VALUE rb_sprintf(const char* fmt, ...) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the code base puts opening braces on a new line

@@ -130,7 +132,6 @@ kernelLoadDataInt(const char *filename, bool rubyExc)
VALUE port = fileIntForPath(filename, rubyExc);

VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random whitespace change?

}

VALUE rb_hash_lookup2(VALUE, VALUE, VALUE) {
return Qnil;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the equivalent 1.8 function for this?

@@ -392,4 +392,5 @@ int rb_utf8_encindex(void) {
VALUE rb_hash_lookup2(VALUE, VALUE, VALUE) {
return Qnil;
}
#endif
#endif // RUBY_API_VERSION_MINOR == 8
#endif // RUBY_API_VERSION_MAJOR == 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline at end

@@ -32,7 +32,7 @@
#include "boost-hash.h"

#include <ruby.h>
#if RUBY_API_VERSION_MAJOR > 1
#ifndef RUBY_LEGACY_VERSION
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this defined by a ruby header, or do we define it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I define it. Problem is that checking for 1.8 vs. 1.9 is ugly to write so I introduced a new macro for 1.8 only. You can suggest a better macro name :D

@Ghabry
Copy link
Author

Ghabry commented May 22, 2017

I can't comment too much on the 1.8 since I'm not familiar with the differences to 2.x

I'm also coding blind because the documentation for MRI 1.8 is basicly non-existent :D

Added raiseDisposedAccess (though the reported classname will be quite useless, just some internal class(#12345678). Though the bookkeeping for storing the "emulated typed data classname" somewhere is not worth the afford imho. So the sanity checks will also not work (they always return true) but I guess they bomb a bit later then. Or do you have any ideas to solve this with not too much work?

rb_str_catf and rb_hash_lookup2 are implemented. hash_lookup is quite useless, only used in VX Ace codepath.

The stacktrace somehow only always contains one element in my tests and I have no idea why o.O

@Ghabry
Copy link
Author

Ghabry commented Sep 16, 2017

Rebased my changes but I can't test if I failed with my rebase because I can't get mkxp to compile because PhysFS changed the API >.>. I also applied @carstene1ns PR, but I still get

rgssad.cpp:507:1: error: conversión no válida de ‘int (*)(void*, const char*, PHYSFS_EnumerateCallback, const char*, void*) {aka int (*)(void*, const char*, PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*), const char*, void*)}’ a ‘PHYSFS_EnumerateCallbackResult (*)(void*, const char*, PHYSFS_EnumerateCallback, const char*, void*) {aka PHYSFS_EnumerateCallbackResult (*)(void*, const char*, PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*), const char*, void*)}’ [-fpermissive]
 };
 ^
rgssad.cpp:528:1: error: conversión no válida de ‘int (*)(void*, const char*, PHYSFS_EnumerateCallback, const char*, void*) {aka int (*)(void*, const char*, PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*), const char*, void*)}’ a ‘PHYSFS_EnumerateCallbackResult (*)(void*, const char*, PHYSFS_EnumerateCallback, const char*, void*) {aka PHYSFS_EnumerateCallbackResult (*)(void*, const char*, PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*), const char*, void*)}’ [-fpermissive]
 };
 ^
src/rgssad.cpp:638:1: error: conversión no válida de ‘int (*)(void*, const char*, PHYSFS_EnumerateCallback, const char*, void*) {aka int (*)(void*, const char*, PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*), const char*, void*)}’ a ‘PHYSFS_EnumerateCallbackResult (*)(void*, const char*, PHYSFS_EnumerateCallback, const char*, void*) {aka PHYSFS_EnumerateCallbackResult (*)(void*, const char*, PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*), const char*, void*)}’ [-fpermissive]
 };
 ^
make[2]: *** [CMakeFiles/mkxp.dir/build.make:983: CMakeFiles/mkxp.dir/src/rgssad.cpp.o] Error 1
make[2]: *** Se espera a que terminen otras tareas....
filesystem.cpp: En la función ‘int cacheEnumCB(void*, const char*, const char*)’:
filesystem.cpp:429:44: error: conversión no válida de ‘int (*)(void*, const char*, const char*)’ a ‘PHYSFS_EnumerateCallback {aka PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*)}’ [-fpermissive]
   PHYSFS_enumerate(fullPath, cacheEnumCB, d);
                                            ^
In file included from src/rgssad.h:25:0,
                 from src/filesystem.cpp:24:
/usr/include/physfs.h:2746:17: nota:   argumento de inicialización 2 de ‘int PHYSFS_enumerate(const char*, PHYSFS_EnumerateCallback, void*)’
 PHYSFS_DECL int PHYSFS_enumerate(const char *dir, PHYSFS_EnumerateCallback c,
                 ^~~~~~~~~~~~~~~~
src/filesystem.cpp: En la función miembro ‘void FileSystem::createPathCache()’:
src/filesystem.cpp:452:41: error: conversión no válida de ‘int (*)(void*, const char*, const char*)’ a ‘PHYSFS_EnumerateCallback {aka PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*)}’ [-fpermissive]
  PHYSFS_enumerate("", cacheEnumCB, &data);
                                         ^
In file included from src/rgssad.h:25:0,
                 from src/filesystem.cpp:24:
/usr/include/physfs.h:2746:17: nota:   argumento de inicialización 2 de ‘int PHYSFS_enumerate(const char*, PHYSFS_EnumerateCallback, void*)’
 PHYSFS_DECL int PHYSFS_enumerate(const char *dir, PHYSFS_EnumerateCallback c,
                 ^~~~~~~~~~~~~~~~
src/filesystem.cpp: En la función ‘int findFontsFolderCB(void*, const char*, const char*)’:
src/filesystem.cpp:517:46: error: conversión no válida de ‘int (*)(void*, const char*, const char*)’ a ‘PHYSFS_EnumerateCallback {aka PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*)}’ [-fpermissive]
   PHYSFS_enumerate(fname, fontSetEnumCB, data);
                                              ^
In file included from src/rgssad.h:25:0,
                 from src/filesystem.cpp:24:
/usr/include/physfs.h:2746:17: nota:   argumento de inicialización 2 de ‘int PHYSFS_enumerate(const char*, PHYSFS_EnumerateCallback, void*)’
 PHYSFS_DECL int PHYSFS_enumerate(const char *dir, PHYSFS_EnumerateCallback c,
                 ^~~~~~~~~~~~~~~~
src/filesystem.cpp: En la función miembro ‘void FileSystem::initFontSets(SharedFontState&)’:
src/filesystem.cpp:526:45: error: conversión no válida de ‘int (*)(void*, const char*, const char*)’ a ‘PHYSFS_EnumerateCallback {aka PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*)}’ [-fpermissive]
  PHYSFS_enumerate(".", findFontsFolderCB, &d);
                                             ^
In file included from src/rgssad.h:25:0,
                 from src/filesystem.cpp:24:
/usr/include/physfs.h:2746:17: nota:   argumento de inicialización 2 de ‘int PHYSFS_enumerate(const char*, PHYSFS_EnumerateCallback, void*)’
 PHYSFS_DECL int PHYSFS_enumerate(const char *dir, PHYSFS_EnumerateCallback c,
                 ^~~~~~~~~~~~~~~~
src/filesystem.cpp: En la función miembro ‘void FileSystem::openRead(FileSystem::OpenHandler&, const char*)’:
src/filesystem.cpp:663:46: error: conversión no válida de ‘int (*)(void*, const char*, const char*)’ a ‘PHYSFS_EnumerateCallback {aka PHYSFS_EnumerateCallbackResult (*)(void*, const char*, const char*)}’ [-fpermissive]
   PHYSFS_enumerate(dir, openReadEnumCB, &data);
                                              ^
In file included from src/rgssad.h:25:0,
                 from src/filesystem.cpp:24:
/usr/include/physfs.h:2746:17: nota:   argumento de inicialización 2 de ‘int PHYSFS_enumerate(const char*, PHYSFS_EnumerateCallback, void*)’
 PHYSFS_DECL int PHYSFS_enumerate(const char *dir, PHYSFS_EnumerateCallback c,
                 ^~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/mkxp.dir/build.make:263: CMakeFiles/mkxp.dir/src/filesystem.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/mkxp.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Any idea?

@carstene1ns
Copy link
Contributor

@Ghabry
Copy link
Author

Ghabry commented Sep 16, 2017

Thanks. https://gist.github.com/Ghabry/001c7e920b4a62089220866e7ce68a09 compiles for me now and can confirm that the rebase was successful 👍

@carstene1ns
Copy link
Contributor

Thank you for fixing my PR! =)

Unfortunately crashes on startup with "[BUG] object allocation during garbage collection phase"
@LiEnby
Copy link

LiEnby commented Dec 22, 2021

do you know if this works with ruby 1.8.1 specifically? iirc, the mkxp-z bindings dont

@Ghabry
Copy link
Author

Ghabry commented Dec 22, 2021

Not tested. Because it is a minor update I assumed it does not have any breaking changes. Is there any game that does not work with 1.8.7?

@LiEnby
Copy link

LiEnby commented Dec 22, 2021

Not tested. Because it is a minor update I assumed it does not have any breaking changes. Is there any game that does not work with 1.8.7?

yeah ive found one thats throwing some subclass error or some shit,

anyway tried on ruby 1.8.1,
got

root@Silica-Ubuntu:/home/silica/mkxp-ruby18/build# make
[  1%] Linking CXX executable mkxp.bin.x86_64
/usr/bin/ld: CMakeFiles/mkxp.dir/binding-mri/binding-util.cpp.o: in function `rb_hash_lookup2(unsigned long, unsigned long, unsigned long)':
binding-util.cpp:(.text+0x11ef): undefined reference to `rb_hash_lookup'

@Ghabry
Copy link
Author

Ghabry commented Dec 22, 2021

Is this the only error?

Replace the content of my rb_hash_lookup2 function with return def

Should be fine because it is only used by rgss3 code

@LiEnby
Copy link

LiEnby commented Dec 22, 2021

maybe add like ifdef RUBY_API_VERSION_TEENY == 1

anyway it built, but does not seem to work, even with a basic RTP project :D
Screenshot from 2021-12-22 15-10-49

@Ghabry
Copy link
Author

Ghabry commented Dec 22, 2021

Well no idea then.
Needs more work to find the underlying issue first

Splendide-Imaginarius added a commit to Splendide-Imaginarius/mkxp that referenced this pull request Apr 30, 2024
Don't hang if the user closes the game while it's still initializing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants