Skip to content

Commit

Permalink
Beta 6 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfairh committed Sep 6, 2024
1 parent ec422d2 commit e4669d9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: false
- name: Ruby
run: |
gem install rouge
Expand Down Expand Up @@ -70,6 +71,8 @@ jobs:
- short: '3.3'
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.rby.short }}
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:6.0

// Package.swift
// RubyGateway
Expand Down
9 changes: 2 additions & 7 deletions Sources/RubyGateway/RbBlockCall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,8 @@ private func rbproc_value_block_callback(context: VALUE,
internal enum RbBlock {
/// One-time init to register the callbacks
private static let initOnce: Void = {
// Swift 6 breakage, 'func's apparently don't work for C functions
rbg_register_pvoid_block_proc_callback { a, b, c, d, e in
rbproc_pvoid_block_callback(rawContext: a, argc: b, argv: c, blockArg: d, returnValue: e)
}
rbg_register_value_block_proc_callback { a, b, c, d, e in
rbproc_value_block_callback(context: a, argc: b, argv: c, blockArg: d, returnValue: e)
}
rbg_register_pvoid_block_proc_callback(rbproc_pvoid_block_callback)
rbg_register_value_block_proc_callback(rbproc_value_block_callback)
}()

/// Call a method on an object passing a Swift closure as its block
Expand Down
6 changes: 1 addition & 5 deletions Sources/RubyGateway/RbClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ internal enum RbClassBinding {

/// One-time init to register the callbacks
private static let initOnce: Void = {
// Swift 6 breakage :(
rbg_register_object_binding_callbacks(
{ rbbinding_alloc(className: $0) },
{ rbbinding_free(className: $0, instance: $1) }
)
rbg_register_object_binding_callbacks(rbbinding_alloc, rbbinding_free)
}()

private static let bindings = LockedDictionary<String, any RbBoundClassProtocol>()
Expand Down
4 changes: 1 addition & 3 deletions Sources/RubyGateway/RbGlobalVar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ private enum RbGlobalVar {

/// One-time init to register the callbacks
private static let initOnce: Void = {
// Swift 6 breakage
rbg_register_gvar_callbacks( { rbobject_gvar_get_callback(id: $0) },
{ rbobject_gvar_set_callback(id: $0, newValue: $1, returnValue: $2) })
rbg_register_gvar_callbacks(rbobject_gvar_get_callback, rbobject_gvar_set_callback)
}()

/// Callbacks + store - type-erased at this point
Expand Down
5 changes: 1 addition & 4 deletions Sources/RubyGateway/RbMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ private struct RbMethodExec {
private struct RbMethodDispatch {
/// One-time init to register the callbacks
private static let initOnce: Void = {
// Swift 6 breakage
rbg_register_method_callback {
rbmethod_callback(symbol: $0, targetCount: $1, rawTargets: $2, rubySelf: $3, argc: $4, argv: $5, returnValue: $6)
}
rbg_register_method_callback(rbmethod_callback)
}()

/// List of all method callbacks
Expand Down
4 changes: 4 additions & 0 deletions Sources/RubyGateway/RbObjectAccess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ internal import RubyGatewayHelpers
/// ...
/// }
/// ```
///
/// When passing a Swift function as a block there are two methods to choose from. If the block is used
/// only within the method execution you can provide a non-escaping, non-sendable function; if the block
/// is persisted and used later then you must provide a retention rule and an escaping, sendable function.
public class RbObjectAccess {
/// Getter for the `VALUE` associated with this object
private let getValue: () -> VALUE
Expand Down
18 changes: 7 additions & 11 deletions Sources/RubyGateway/RbThread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public enum RbThread {
withoutActuallyEscaping(callback) { escapingCallback in
let context = RbThreadContext(escapingCallback)
context.withRaw { rawContext in
// Swift 6
rb_thread_call_without_gvl( { rbthread_callback(rawContext: $0) }, rawContext, nil, nil)
rb_thread_call_without_gvl(rbthread_callback, rawContext, nil, nil)
}
}
}
Expand Down Expand Up @@ -127,16 +126,14 @@ public enum RbThread {
withoutActuallyEscaping(ubfFunc) { escapingUbfFunc in
let ubfContext = RbThreadContext(escapingUbfFunc)
ubfContext.withRaw { rawUbfContext in
// Swift 6
rb_thread_call_without_gvl( { rbthread_callback(rawContext: $0) },
rawContext,
{ rbthread_ubf_callback(rawContext: $0) },
rawUbfContext)
rb_thread_call_without_gvl(rbthread_callback,
rawContext,
rbthread_ubf_callback,
rawUbfContext)
}
}
case .io:
// Swift 6
rb_thread_call_without_gvl( { rbthread_callback(rawContext: $0) }, rawContext, rbg_RUBY_UBF_IO(), nil)
rb_thread_call_without_gvl(rbthread_callback, rawContext, rbg_RUBY_UBF_IO(), nil)
}
}
}
Expand All @@ -151,8 +148,7 @@ public enum RbThread {
withoutActuallyEscaping(callback) { escapingCallback in
let context = RbThreadContext(escapingCallback)
context.withRaw { rawContext in
// Swift 6
rb_thread_call_with_gvl( { rbthread_callback(rawContext: $0) }, rawContext)
rb_thread_call_with_gvl(rbthread_callback, rawContext)
}
}
}
Expand Down

0 comments on commit e4669d9

Please sign in to comment.