Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: "3.4"
ruby-version: "4.0"
rustup-toolchain: "${{ env.NIGHTLY_VERSION }}"
bundler-cache: true
cargo-cache: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
ruby-version: "4.0"

- uses: oxidize-rb/actions/cross-gem@v1
id: cross-gem
Expand All @@ -66,7 +66,7 @@ jobs:
strategy:
matrix:
os: ["ubuntu-latest"]
ruby: ["3.4"]
ruby: ["4.0"]
steps:
- uses: actions/checkout@v6

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/memcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ on:
ruby-version:
description: "Ruby version to memcheck"
required: true
default: "3.4"
default: "4.0"
type: choice
options:
- "head"
- "4.0"
- "3.4"
- "3.3"
- "3.2"
Expand Down Expand Up @@ -38,7 +39,7 @@ jobs:

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: ${{ inputs.ruby-version || '3.4' }}
ruby-version: ${{ inputs.ruby-version || '4.0' }}
bundler-cache: true
cargo-cache: true
cache-version: v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
ruby-version: "4.0"

- uses: oxidize-rb/actions/cross-gem@v1
id: cross-gem
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: "3.4"
ruby-version: "4.0"
bundler-cache: true
cargo-cache: true
cache-version: v1
Expand Down
27 changes: 18 additions & 9 deletions ext/src/helpers/tmplock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use magnus::{
rb_sys::{protect, AsRawValue},
value::ReprValue,
RString,
};

pub trait Tmplock {
fn as_locked_slice(&self) -> Result<(&[u8], TmplockGuard), magnus::Error>;
fn as_locked_str(&self) -> Result<(&str, TmplockGuard), magnus::Error>;
fn as_locked_slice(&self) -> Result<(&[u8], Option<TmplockGuard>), magnus::Error>;
fn as_locked_str(&self) -> Result<(&str, Option<TmplockGuard>), magnus::Error>;
}

#[derive(Debug)]
Expand All @@ -25,20 +26,28 @@ impl Drop for TmplockGuard {
}

impl Tmplock for RString {
fn as_locked_slice(&self) -> Result<(&[u8], TmplockGuard), magnus::Error> {
fn as_locked_slice(&self) -> Result<(&[u8], Option<TmplockGuard>), magnus::Error> {
let raw = self.as_raw();
let slice = unsafe { self.as_slice() };
let raw = protect(|| unsafe { rb_sys::rb_str_locktmp(raw) })?;
let guard = TmplockGuard { raw };
let guard = if self.is_frozen() {
None
} else {
let raw = protect(|| unsafe { rb_sys::rb_str_locktmp(raw) })?;
Some(TmplockGuard { raw })
};

Ok((slice, guard))
}

fn as_locked_str(&self) -> Result<(&str, TmplockGuard), magnus::Error> {
fn as_locked_str(&self) -> Result<(&str, Option<TmplockGuard>), magnus::Error> {
let str_result = unsafe { self.as_str()? };
let raw = self.as_raw();
let raw = protect(|| unsafe { rb_sys::rb_str_locktmp(raw) })?;
let guard = TmplockGuard { raw };
let guard = if self.is_frozen() {
None
} else {
let raw = self.as_raw();
let raw = protect(|| unsafe { rb_sys::rb_str_locktmp(raw) })?;
Some(TmplockGuard { raw })
};

Ok((str_result, guard))
}
Expand Down
10 changes: 8 additions & 2 deletions spec/integration/ractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Wasmtime::Instance.new(store, mod).invoke("hello")
end

result = r.take
result = value(r)
expect(result).to eq([1, 2, 3.0, 4.0])
end

Expand All @@ -42,7 +42,13 @@
end

ractors.each do |ractor|
expect(ractor.take).to eq([1, 2, 3.0, 4.0])
expect(value(ractor)).to eq([1, 2, 3.0, 4.0])
end
end

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("4.0")
def value(ractor) = ractor.value
else
def value(ractor) = ractor.take
end
end
Loading