From d7d460d6b03451e4b881fadbf936b6e723be0a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Sun, 19 Jan 2025 11:30:55 -0500 Subject: [PATCH] Small fixes to the sandbox bindings --- binding-sandbox/binding-sandbox.h | 14 +++++++++++--- retro/sandbox-bindgen.rb | 7 +++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/binding-sandbox/binding-sandbox.h b/binding-sandbox/binding-sandbox.h index de5173d9..dae24ff5 100644 --- a/binding-sandbox/binding-sandbox.h +++ b/binding-sandbox/binding-sandbox.h @@ -52,6 +52,7 @@ namespace mkxp_sandbox { ID id; VALUE backtrace; + VALUE separator; wasm_ptr_t backtrace_str; void operator()(VALUE exception) { @@ -60,8 +61,8 @@ namespace mkxp_sandbox { SANDBOX_AWAIT_AND_SET(id, mkxp_sandbox::rb_intern, "backtrace"); SANDBOX_AWAIT_AND_SET(backtrace, mkxp_sandbox::rb_funcall, exception, id, 0); SANDBOX_AWAIT_AND_SET(id, mkxp_sandbox::rb_intern, "join"); - SANDBOX_AWAIT_AND_SET(backtrace_str, mkxp_sandbox::rb_str_new_cstr, "\n\t"); - SANDBOX_AWAIT_AND_SET(backtrace, mkxp_sandbox::rb_funcall, backtrace, id, 1, backtrace_str); + SANDBOX_AWAIT_AND_SET(separator, mkxp_sandbox::rb_str_new_cstr, "\n\t"); + SANDBOX_AWAIT_AND_SET(backtrace, mkxp_sandbox::rb_funcall, backtrace, id, 1, separator); SANDBOX_AWAIT_AND_SET(backtrace_str, mkxp_sandbox::rb_string_value_cstr, &backtrace); mkxp_retro::log_printf(RETRO_LOG_ERROR, "%s\n", *mkxp_sandbox::sandbox->bindings + backtrace_str); } @@ -205,7 +206,7 @@ namespace mkxp_sandbox { } if (zlib_result != Z_OK) { - mkxp_retro::log_printf(RETRO_LOG_ERROR, "Error decoding script %zu: '%s'\n", i, (const char *)(*mkxp_sandbox::sandbox->bindings + script_name)); + mkxp_retro::log_printf(RETRO_LOG_ERROR, "Error decoding script %zu: '%s'\n", i, *mkxp_sandbox::sandbox->bindings + script_name); break; } } @@ -221,6 +222,13 @@ namespace mkxp_sandbox { while (true) { for (i = 0; i < script_count; ++i) { + // Skip this script object if it's not an array + SANDBOX_AWAIT_AND_SET(script, mkxp_sandbox::rb_ary_entry, scripts, i); + SANDBOX_AWAIT_AND_SET(value, mkxp_sandbox::rb_obj_is_kind_of, script, mkxp_sandbox::sandbox->bindings.rb_cArray()); + if (value != SANDBOX_TRUE) { + continue; + } + SANDBOX_AWAIT_AND_SET(script_filename_value, mkxp_sandbox::rb_ary_entry, script, 1); SANDBOX_AWAIT_AND_SET(script_string_value, mkxp_sandbox::rb_ary_entry, script, 3); SANDBOX_AWAIT_AND_SET(value, mkxp_sandbox::eval_script, script_string_value, script_filename_value); diff --git a/retro/sandbox-bindgen.rb b/retro/sandbox-bindgen.rb index 381d56b2..968e4563 100644 --- a/retro/sandbox-bindgen.rb +++ b/retro/sandbox-bindgen.rb @@ -82,6 +82,13 @@ ARG_HANDLERS = { formatter: lambda { |name| "VALUE (*#{name})(void *, ANYARGS)" }, declaration: 'VALUE (*)(void *, ANYARGS)', }, + 'rb_alloc_func_t' => { + keep: true, + func_ptr_args: [:size], + func_ptr_rets: [:size], + formatter: lambda { |name| "VALUE (*#{name})(void *, VALUE)" }, + declaration: 'VALUE (*)(void *, VALUE)', + }, 'VALUE (*)(VALUE)' => { keep: true, func_ptr_args: [:size],