|
| 1 | +From 1e4e88533f860a0a06668b973264db17cb52387e Mon Sep 17 00:00:00 2001 |
| 2 | +From: Tim Felgentreff <tim.felgentreff@oracle.com> |
| 3 | +Date: Tue, 19 Sep 2023 07:05:59 +0200 |
| 4 | +Subject: [PATCH] get it to build on graalpy |
| 5 | + |
| 6 | +--- |
| 7 | + Cargo.lock | 6 ++---- |
| 8 | + Cargo.toml | 4 ++-- |
| 9 | + src/ffi/fragment.rs | 3 +++ |
| 10 | + src/ffi/list.rs | 3 +++ |
| 11 | + src/lib.rs | 18 +++++++++++++++--- |
| 12 | + src/serialize/datetime.rs | 4 ++++ |
| 13 | + src/serialize/default.rs | 4 ++-- |
| 14 | + src/serialize/numpy.rs | 6 ++++++ |
| 15 | + src/serialize/tuple.rs | 3 +++ |
| 16 | + src/util.rs | 4 ++-- |
| 17 | + 10 files changed, 42 insertions(+), 13 deletions(-) |
| 18 | + |
| 19 | +diff --git a/Cargo.lock b/Cargo.lock |
| 20 | +index f8ec582..e835fd4 100644 |
| 21 | +--- a/Cargo.lock |
| 22 | ++++ b/Cargo.lock |
| 23 | +@@ -227,8 +227,7 @@ dependencies = [ |
| 24 | + [[package]] |
| 25 | + name = "pyo3-build-config" |
| 26 | + version = "0.19.2" |
| 27 | +-source = "registry+https://github.com/rust-lang/crates.io-index" |
| 28 | +-checksum = "076c73d0bc438f7a4ef6fdd0c3bb4732149136abd952b110ac93e4edb13a6ba5" |
| 29 | ++source = "git+https://github.com/timfel/pyo3.git?branch=v0.19.2.graalpy#a1869b1127916f2ac1f12a915828e7d5570dddf3" |
| 30 | + dependencies = [ |
| 31 | + "once_cell", |
| 32 | + "target-lexicon", |
| 33 | +@@ -237,8 +236,7 @@ dependencies = [ |
| 34 | + [[package]] |
| 35 | + name = "pyo3-ffi" |
| 36 | + version = "0.19.2" |
| 37 | +-source = "registry+https://github.com/rust-lang/crates.io-index" |
| 38 | +-checksum = "e53cee42e77ebe256066ba8aa77eff722b3bb91f3419177cf4cd0f304d3284d9" |
| 39 | ++source = "git+https://github.com/timfel/pyo3.git?branch=v0.19.2.graalpy#a1869b1127916f2ac1f12a915828e7d5570dddf3" |
| 40 | + dependencies = [ |
| 41 | + "libc", |
| 42 | + "pyo3-build-config", |
| 43 | +diff --git a/Cargo.toml b/Cargo.toml |
| 44 | +index 8ca77f7..9b15f81 100644 |
| 45 | +--- a/Cargo.toml |
| 46 | ++++ b/Cargo.toml |
| 47 | +@@ -59,7 +59,7 @@ encoding_rs = { version = "0.8", default_features = false } |
| 48 | + itoa = { version = "1", default_features = false } |
| 49 | + itoap = { version = "1", features = ["std", "simd"] } |
| 50 | + once_cell = { version = "1", default_features = false, features = ["race"] } |
| 51 | +-pyo3-ffi = { version = "^0.19.2", default_features = false, features = ["extension-module"]} |
| 52 | ++pyo3-ffi = { git = "https://github.com/timfel/pyo3.git", branch = "v0.19.2.graalpy", default_features = false, features = ["extension-module"] } |
| 53 | + ryu = { version = "1", default_features = false } |
| 54 | + serde = { version = "1", default_features = false } |
| 55 | + serde_json = { version = "1", default_features = false, features = ["std", "float_roundtrip"] } |
| 56 | +@@ -68,7 +68,7 @@ smallvec = { version = "^1.11", default_features = false, features = ["union", " |
| 57 | + |
| 58 | + [build-dependencies] |
| 59 | + cc = { version = "1" } |
| 60 | +-pyo3-build-config = { version = "^0.19.2" } |
| 61 | ++pyo3-build-config = { git = "https://github.com/timfel/pyo3.git", branch = "v0.19.2.graalpy" } |
| 62 | + version_check = { version = "0.9" } |
| 63 | + |
| 64 | + [profile.dev] |
| 65 | +diff --git a/src/ffi/fragment.rs b/src/ffi/fragment.rs |
| 66 | +index 44d4517..006111a 100644 |
| 67 | +--- a/src/ffi/fragment.rs |
| 68 | ++++ b/src/ffi/fragment.rs |
| 69 | +@@ -39,7 +39,10 @@ pub unsafe extern "C" fn orjson_fragment_tp_new( |
| 70 | + raise_args_exception(); |
| 71 | + null_mut() |
| 72 | + } else { |
| 73 | ++ #[cfg(not(any(GraalPy, PyPy)))] |
| 74 | + let contents = PyTuple_GET_ITEM(args, 0); |
| 75 | ++ #[cfg(any(GraalPy, PyPy))] |
| 76 | ++ let contents = PyTuple_GetItem(args, 0); |
| 77 | + Py_INCREF(contents); |
| 78 | + let obj = Box::new(Fragment { |
| 79 | + ob_refcnt: 1, |
| 80 | +diff --git a/src/ffi/list.rs b/src/ffi/list.rs |
| 81 | +index 44b386c..5800ac3 100644 |
| 82 | +--- a/src/ffi/list.rs |
| 83 | ++++ b/src/ffi/list.rs |
| 84 | +@@ -29,7 +29,10 @@ impl Iterator for PyListIter { |
| 85 | + if self.pos == self.len { |
| 86 | + None |
| 87 | + } else { |
| 88 | ++ #[cfg(not(any(GraalPy, PyPy)))] |
| 89 | + let elem = unsafe { *((*self.obj).ob_item).add(self.pos) }; |
| 90 | ++ #[cfg(any(GraalPy, PyPy))] |
| 91 | ++ let elem = unsafe { pyo3_ffi::PyList_GetItem(self.obj as *mut pyo3_ffi::PyObject, self.pos as isize) }; |
| 92 | + self.pos += 1; |
| 93 | + Some(nonnull!(elem)) |
| 94 | + } |
| 95 | +diff --git a/src/lib.rs b/src/lib.rs |
| 96 | +index 7728d45..5f9547a 100644 |
| 97 | +--- a/src/lib.rs |
| 98 | ++++ b/src/lib.rs |
| 99 | +@@ -214,9 +214,18 @@ fn raise_loads_exception(err: deserialize::DeserializeError) -> *mut PyObject { |
| 100 | + PyUnicode_FromStringAndSize(msg.as_ptr() as *const c_char, msg.len() as isize); |
| 101 | + let args = PyTuple_New(3); |
| 102 | + let pos = PyLong_FromLongLong(pos); |
| 103 | +- PyTuple_SET_ITEM(args, 0, err_msg); |
| 104 | +- PyTuple_SET_ITEM(args, 1, doc); |
| 105 | +- PyTuple_SET_ITEM(args, 2, pos); |
| 106 | ++ #[cfg(not(any(GraalPy, PyPy)))] |
| 107 | ++ { |
| 108 | ++ PyTuple_SET_ITEM(args, 0, err_msg); |
| 109 | ++ PyTuple_SET_ITEM(args, 1, doc); |
| 110 | ++ PyTuple_SET_ITEM(args, 2, pos); |
| 111 | ++ } |
| 112 | ++ #[cfg(any(GraalPy, PyPy))] |
| 113 | ++ { |
| 114 | ++ PyTuple_SetItem(args, 0, err_msg); |
| 115 | ++ PyTuple_SetItem(args, 1, doc); |
| 116 | ++ PyTuple_SetItem(args, 2, pos); |
| 117 | ++ } |
| 118 | + PyErr_SetObject(typeref::JsonDecodeError, args); |
| 119 | + debug_assert!(ffi!(Py_REFCNT(args)) == 2); |
| 120 | + Py_DECREF(args); |
| 121 | +@@ -330,7 +339,10 @@ pub unsafe extern "C" fn dumps( |
| 122 | + } |
| 123 | + if !kwnames.is_null() { |
| 124 | + for i in 0..=Py_SIZE(kwnames).saturating_sub(1) { |
| 125 | ++ #[cfg(not(any(GraalPy, PyPy)))] |
| 126 | + let arg = PyTuple_GET_ITEM(kwnames, i as Py_ssize_t); |
| 127 | ++ #[cfg(any(GraalPy, PyPy))] |
| 128 | ++ let arg = PyTuple_GetItem(kwnames, i as Py_ssize_t); |
| 129 | + if arg == typeref::DEFAULT { |
| 130 | + if unlikely!(num_args & 2 == 2) { |
| 131 | + return raise_dumps_exception_fixed( |
| 132 | +diff --git a/src/serialize/datetime.rs b/src/serialize/datetime.rs |
| 133 | +index adf35fb..13d5747 100644 |
| 134 | +--- a/src/serialize/datetime.rs |
| 135 | ++++ b/src/serialize/datetime.rs |
| 136 | +@@ -164,7 +164,11 @@ impl DateTimeLike for DateTime { |
| 137 | + } |
| 138 | + |
| 139 | + fn has_tz(&self) -> bool { |
| 140 | ++ #[cfg(not(GraalPy))] |
| 141 | + unsafe { (*(self.ptr as *mut pyo3_ffi::PyDateTime_DateTime)).hastzinfo == 1 } |
| 142 | ++ |
| 143 | ++ #[cfg(GraalPy)] |
| 144 | ++ unsafe { pyo3_ffi::Py_IsNone(pyo3_ffi::PyDateTime_DATE_GET_TZINFO(self.ptr as *mut pyo3_ffi::PyObject)) == 0 } |
| 145 | + } |
| 146 | + |
| 147 | + fn slow_offset(&self) -> Result<Offset, DateTimeError> { |
| 148 | +diff --git a/src/serialize/default.rs b/src/serialize/default.rs |
| 149 | +index 6f2d098..eefca82 100644 |
| 150 | +--- a/src/serialize/default.rs |
| 151 | ++++ b/src/serialize/default.rs |
| 152 | +@@ -46,13 +46,13 @@ impl Serialize for DefaultSerializer { |
| 153 | + if unlikely!(self.default_calls == RECURSION_LIMIT) { |
| 154 | + err!(SerializeError::DefaultRecursionLimit) |
| 155 | + } |
| 156 | +- #[cfg(not(Py_3_10))] |
| 157 | ++ #[cfg(any(not(Py_3_10), GraalPy, PyPy))] |
| 158 | + let default_obj = ffi!(PyObject_CallFunctionObjArgs( |
| 159 | + callable.as_ptr(), |
| 160 | + self.ptr, |
| 161 | + std::ptr::null_mut() as *mut pyo3_ffi::PyObject |
| 162 | + )); |
| 163 | +- #[cfg(Py_3_10)] |
| 164 | ++ #[cfg(all(Py_3_10, not(GraalPy), not(PyPy)))] |
| 165 | + let default_obj = unsafe { |
| 166 | + pyo3_ffi::PyObject_Vectorcall( |
| 167 | + callable.as_ptr(), |
| 168 | +diff --git a/src/serialize/numpy.rs b/src/serialize/numpy.rs |
| 169 | +index 2ae9204..9dc97b4 100644 |
| 170 | +--- a/src/serialize/numpy.rs |
| 171 | ++++ b/src/serialize/numpy.rs |
| 172 | +@@ -1137,8 +1137,14 @@ impl NumpyDatetimeUnit { |
| 173 | + fn from_pyobject(ptr: *mut PyObject) -> Self { |
| 174 | + let dtype = ffi!(PyObject_GetAttr(ptr, DTYPE_STR)); |
| 175 | + let descr = ffi!(PyObject_GetAttr(dtype, DESCR_STR)); |
| 176 | ++ #[cfg(not(any(GraalPy, PyPy)))] |
| 177 | + let el0 = ffi!(PyList_GET_ITEM(descr, 0)); |
| 178 | ++ #[cfg(any(GraalPy, PyPy))] |
| 179 | ++ let el0 = ffi!(PyList_GetItem(descr, 0)); |
| 180 | ++ #[cfg(not(any(GraalPy, PyPy)))] |
| 181 | + let descr_str = ffi!(PyTuple_GET_ITEM(el0, 1)); |
| 182 | ++ #[cfg(any(GraalPy, PyPy))] |
| 183 | ++ let descr_str = ffi!(PyTuple_GetItem(el0, 1)); |
| 184 | + let uni = crate::str::unicode_to_str(descr_str).unwrap(); |
| 185 | + if uni.len() < 5 { |
| 186 | + return Self::NaT; |
| 187 | +diff --git a/src/serialize/tuple.rs b/src/serialize/tuple.rs |
| 188 | +index 7ad76e4..46881cf 100644 |
| 189 | +--- a/src/serialize/tuple.rs |
| 190 | ++++ b/src/serialize/tuple.rs |
| 191 | +@@ -43,7 +43,10 @@ impl Serialize for TupleSerializer { |
| 192 | + } else { |
| 193 | + let mut seq = serializer.serialize_seq(None).unwrap(); |
| 194 | + for i in 0..=ffi!(Py_SIZE(self.ptr)) as usize - 1 { |
| 195 | ++ #[cfg(not(any(GraalPy, PyPy)))] |
| 196 | + let elem = ffi!(PyTuple_GET_ITEM(self.ptr, i as isize)); |
| 197 | ++ #[cfg(any(GraalPy, PyPy))] |
| 198 | ++ let elem = ffi!(PyTuple_GetItem(self.ptr, i as isize)); |
| 199 | + let value = PyObjectSerializer::new( |
| 200 | + elem, |
| 201 | + self.opts, |
| 202 | +diff --git a/src/util.rs b/src/util.rs |
| 203 | +index fa3b7e1..2b2df61 100644 |
| 204 | +--- a/src/util.rs |
| 205 | ++++ b/src/util.rs |
| 206 | +@@ -100,7 +100,7 @@ macro_rules! ffi { |
| 207 | + }; |
| 208 | + } |
| 209 | + |
| 210 | +-#[cfg(Py_3_9)] |
| 211 | ++#[cfg(all(Py_3_9, not(any(PyPy, GraalPy))))] |
| 212 | + macro_rules! call_method { |
| 213 | + ($obj1:expr, $obj2:expr) => { |
| 214 | + unsafe { pyo3_ffi::PyObject_CallMethodNoArgs($obj1, $obj2) } |
| 215 | +@@ -110,7 +110,7 @@ macro_rules! call_method { |
| 216 | + }; |
| 217 | + } |
| 218 | + |
| 219 | +-#[cfg(not(Py_3_9))] |
| 220 | ++#[cfg(any(not(Py_3_9), PyPy, GraalPy))] |
| 221 | + macro_rules! call_method { |
| 222 | + ($obj1:expr, $obj2:expr) => { |
| 223 | + unsafe { |
| 224 | +-- |
| 225 | +2.34.1 |
0 commit comments