Skip to content

Commit 866b667

Browse files
authored
fix crash on aarch64 linux wheels (#175)
1 parent 4397293 commit 866b667

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ jobs:
475475
source venv/bin/activate
476476
python3 -m pip install -U pip -r tests/requirements.txt
477477
python3 -m pip install jiter --no-index --no-deps --find-links dist --force-reinstall
478+
python3 -m pytest
478479
python3 -c 'import jiter; print(jiter.__version__)'
479480
480481
test-builds-os:
@@ -507,6 +508,7 @@ jobs:
507508
python3 -m pip install -U pip -r tests/requirements.txt
508509
python3 -m pip install jiter --no-index --no-deps --find-links dist --force-reinstall
509510
python3 -m pytest
511+
python3 -c 'import jiter; print(jiter.__version__)'
510512
working-directory: crates/jiter-python
511513

512514
# https://github.com/marketplace/actions/alls-green#why used for branch protection checks

crates/jiter/src/py_string_cache.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,17 @@ pub fn pystring_fast_new<'py>(py: Python<'py>, s: &str, ascii_only: bool) -> Bou
208208

209209
/// Faster creation of PyString from an ASCII string, inspired by
210210
/// https://github.com/ijl/orjson/blob/3.10.0/src/str/create.rs#L41
211-
#[cfg(all(not(PyPy), not(GraalPy)))]
211+
#[cfg(all(
212+
any(
213+
all(target_arch = "x86_64", target_os = "linux"),
214+
all(target_arch = "aarch64", target_os = "macos"),
215+
),
216+
not(any(PyPy, GraalPy))
217+
))]
212218
unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> {
219+
// disabled on everything except tier-1 platforms because of a crash in the built wheels from CI,
220+
// see https://github.com/pydantic/jiter/pull/175
221+
213222
let ptr = pyo3::ffi::PyUnicode_New(s.len() as isize, 127);
214223
// see https://github.com/pydantic/jiter/pull/72#discussion_r1545485907
215224
debug_assert_eq!(pyo3::ffi::PyUnicode_KIND(ptr), pyo3::ffi::PyUnicode_1BYTE_KIND);
@@ -219,8 +228,14 @@ unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyStri
219228
Bound::from_owned_ptr(py, ptr).downcast_into_unchecked()
220229
}
221230

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

0 commit comments

Comments
 (0)