Skip to content

Commit 19a7eef

Browse files
committed
Add patch for jiter
Fixes #418
1 parent 3e1766e commit 19a7eef

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/crates/jiter/src/py_string_cache.rs b/crates/jiter/src/py_string_cache.rs
2+
index 96dcf66..21e6979 100644
3+
--- a/crates/jiter/src/py_string_cache.rs
4+
+++ b/crates/jiter/src/py_string_cache.rs
5+
@@ -200,7 +200,7 @@ pub fn pystring_fast_new<'py>(py: Python<'py>, s: &str, ascii_only: bool) -> Bou
6+
7+
/// Faster creation of PyString from an ASCII string, inspired by
8+
/// https://github.com/ijl/orjson/blob/3.10.0/src/str/create.rs#L41
9+
-#[cfg(not(PyPy))]
10+
+#[cfg(all(not(PyPy), not(GraalPy)))]
11+
unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> {
12+
let ptr = pyo3::ffi::PyUnicode_New(s.len() as isize, 127);
13+
// see https://github.com/pydantic/jiter/pull/72#discussion_r1545485907
14+
@@ -212,7 +212,7 @@ unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyStri
15+
}
16+
17+
// ffi::PyUnicode_DATA seems to be broken for pypy, hence this, marked as unsafe to avoid warnings
18+
-#[cfg(PyPy)]
19+
+#[cfg(any(PyPy, GraalPy))]
20+
unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> {
21+
PyString::new_bound(py, s)
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[rules]]
2+
patch = 'jiter.patch'
3+
license = 'MIT'

0 commit comments

Comments
 (0)