Skip to content

Commit

Permalink
fix crash on aarch64 linux wheels (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt authored Dec 2, 2024
1 parent 4397293 commit 866b667
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ jobs:
source venv/bin/activate
python3 -m pip install -U pip -r tests/requirements.txt
python3 -m pip install jiter --no-index --no-deps --find-links dist --force-reinstall
python3 -m pytest
python3 -c 'import jiter; print(jiter.__version__)'
test-builds-os:
Expand Down Expand Up @@ -507,6 +508,7 @@ jobs:
python3 -m pip install -U pip -r tests/requirements.txt
python3 -m pip install jiter --no-index --no-deps --find-links dist --force-reinstall
python3 -m pytest
python3 -c 'import jiter; print(jiter.__version__)'
working-directory: crates/jiter-python

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
Expand Down
23 changes: 19 additions & 4 deletions crates/jiter/src/py_string_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,17 @@ pub fn pystring_fast_new<'py>(py: Python<'py>, s: &str, ascii_only: bool) -> Bou

/// Faster creation of PyString from an ASCII string, inspired by
/// https://github.com/ijl/orjson/blob/3.10.0/src/str/create.rs#L41
#[cfg(all(not(PyPy), not(GraalPy)))]
#[cfg(all(
any(
all(target_arch = "x86_64", target_os = "linux"),
all(target_arch = "aarch64", target_os = "macos"),
),
not(any(PyPy, GraalPy))
))]
unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> {
// disabled on everything except tier-1 platforms because of a crash in the built wheels from CI,
// see https://github.com/pydantic/jiter/pull/175

let ptr = pyo3::ffi::PyUnicode_New(s.len() as isize, 127);
// see https://github.com/pydantic/jiter/pull/72#discussion_r1545485907
debug_assert_eq!(pyo3::ffi::PyUnicode_KIND(ptr), pyo3::ffi::PyUnicode_1BYTE_KIND);
Expand All @@ -219,8 +228,14 @@ unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyStri
Bound::from_owned_ptr(py, ptr).downcast_into_unchecked()
}

// ffi::PyUnicode_DATA seems to be broken for pypy, hence this, marked as unsafe to avoid warnings
#[cfg(any(PyPy, GraalPy))]
// unoptimized version (albeit not that much slower) on other platforms
#[cfg(not(all(
any(
all(target_arch = "x86_64", target_os = "linux"),
all(target_arch = "aarch64", target_os = "macos"),
),
not(any(PyPy, GraalPy)),
)))]
unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> {
PyString::new_bound(py, s)
PyString::new(py, s)
}

0 comments on commit 866b667

Please sign in to comment.