Skip to content

Commit

Permalink
fix string len issue on Ruby head for 0.5.4 release
Browse files Browse the repository at this point in the history
+ skip Ruby head on windows on CI

windows head can be behind linux/macOS which means we get into a
situation where fixing for linux/macOS breaks for windows and
visa versa
  • Loading branch information
matsadler committed Jun 8, 2023
1 parent 1f9e96a commit 5ba7438
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
exclude:
- os: macos-latest
rustup-toolchain: "1.51"
- os: windows-latest
ruby-version: head

steps:
- uses: actions/checkout@v3
Expand Down
26 changes: 23 additions & 3 deletions src/r_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ impl RString {
let f = r_basic.as_ref().flags;
if (f & ruby_rstring_flags::RSTRING_NOEMBED as VALUE) != 0 {
let h = self.as_internal().as_ref().as_.heap;
slice::from_raw_parts(h.ptr as *const u8, h.len as usize)
slice::from_raw_parts(h.ptr as *const u8, self.len())
} else {
slice::from_raw_parts(embedded_ary_ptr(self), embed_len(self, f) as usize)
slice::from_raw_parts(embedded_ary_ptr(self), self.len())
}
}

Expand Down Expand Up @@ -1277,6 +1277,26 @@ impl RString {
/// let s = RString::new("🦀 Hello, Ferris");
/// assert_eq!(s.len(), 18);
/// ```
#[cfg(ruby_gte_3_3)]
pub fn len(self) -> usize {
debug_assert_value!(self);
unsafe { self.as_internal().as_ref().len as usize }
}

/// Returns the number of bytes in `self`.
///
/// See also [`length`](RString::length).
///
/// # Examples
///
/// ```
/// use magnus::{eval, RString};
/// # let _cleanup = unsafe { magnus::embed::init() };
///
/// let s = RString::new("🦀 Hello, Ferris");
/// assert_eq!(s.len(), 18);
/// ```
#[cfg(ruby_lte_3_2)]
pub fn len(self) -> usize {
debug_assert_value!(self);
unsafe {
Expand Down Expand Up @@ -1421,7 +1441,7 @@ impl RString {
}
}

#[cfg(ruby_gte_3_2)]
#[cfg(ruby_3_2)]
unsafe fn embed_len(value: RString, _: VALUE) -> c_long {
value.as_internal().as_ref().as_.embed.len
}
Expand Down

0 comments on commit 5ba7438

Please sign in to comment.