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 Ruby 3.4 to linux CI #52

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
xcode: ['16.0']
xcode: ['16.1']
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
Expand Down Expand Up @@ -69,6 +69,7 @@ jobs:
- short: '3.1'
- short: '3.2'
- short: '3.3'
- short: '3.4'
steps:
- uses: actions/checkout@v4
with:
Expand Down
22 changes: 22 additions & 0 deletions Sources/RubyGateway/RbVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@ final class RbVM : @unchecked Sendable {
try RbError.raise(error: .setup("Has already been done (via C API?) for this process."))
}

// What is going on with init_stack
// --------------------------------
// Line added for Ruby 3.4 because of ruby/ruby:9505 that took it out of `ruby_setup()`.
//
// This stack frame we're in now isn't very interesting except for defining the native thread
// that will become the Ruby "main thread". Here is why it's OK to call this macro:
//
// `RUBY_INIT_STACK` declares a ‘stack’ variable and calls `vm.c:ruby_init_stack()` which
// stores that variable address in `native_main_thread_stack_top`, the only place that is set.
//
// `eval.c:ruby_setup()` -> `vm.c:Init_BareVM()` is the only place that refers to the static
// and passes to `thread.c:ruby_thread_init_stack()` for the current thread, which for platforms
// we care about[1] leads to `thread_pthread.c:native_thread_init_stack()`. We only care about the
// “main thread” use-case at this point and go to`thread_pthread.c:native_thread_init_main_thread_stack()`.
// We only care about `MAINSTACKADDR_AVAILABLE` and so do not use the address to figure the
// stack layout for GC. Then there is a sanity check which is the only place the address is
// used - as long as it is within the stack as reported by pthreads then we are good.
//
// [1] Brief eyeball the win32 version looks OK too.
//
rbg_RUBY_INIT_STACK()

let setup_rc = ruby_setup()
guard setup_rc == 0 else {
try RbError.raise(error: .setup("ruby_setup() failed: \(setup_rc)"))
Expand Down
3 changes: 3 additions & 0 deletions Sources/RubyGatewayHelpers/include/rbg_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
typedef unsigned long VALUE;
typedef VALUE ID;

/// Call `RUBY_INIT_STACK`
void rbg_RUBY_INIT_STACK(void);

/// Safely call `rb_load` and report exception status.
void rbg_load_protect(VALUE fname, int wrap, int * _Nonnull status);

Expand Down
5 changes: 5 additions & 0 deletions Sources/RubyGatewayHelpers/rbg_macros.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ long rbg_RSTRING_LEN(VALUE v)
// These become inlines in Ruby 3 that get imported
int rbg_RB_TEST(VALUE v) { return RB_TEST(v); }
int rbg_RB_NIL_P(VALUE v) { return RB_NIL_P(v); }

// See comment on call in RbVM.swift
void rbg_RUBY_INIT_STACK(void) {
RUBY_INIT_STACK;
}
3 changes: 2 additions & 1 deletion Tests/RubyGatewayTests/TestVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class TestVM: XCTestCase {
try Ruby.load(filename: Helpers.fixturePath("unloadable.rb"))
XCTFail("Managed to load unloadable file")
} catch RbError.rubyException(let exn) {
XCTAssertTrue(exn.description.contains("SyntaxError:"))
let desc = exn.description
XCTAssertTrue(desc.hasPrefix("SyntaxError:") || desc.hasPrefix("NameError:"))
}
}
}
Expand Down
Loading