1- commit a889953c08d33854e574ab06e9593e0484c4c147
2- Author: stepan <stepan.sindelar@oracle.com>
3- Date: Wed Jul 9 18:50:37 2025 +0200
4-
5- Adapt for GraalPy
6-
71diff --git a/build.rs b/build.rs
8- index 43538c0..85857ba 100644
2+ index 43538c0..d6394a5 100644
93--- a/build.rs
104+++ b/build.rs
11- @@ -40,7 +40,8 @@ fn main() {
5+ @@ -40,14 +40,15 @@ fn main() {
126
137 #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
148 if is_64_bit_python {
@@ -17,7 +11,26 @@ index 43538c0..85857ba 100644
1711+ // println!("cargo:rustc-cfg=feature=\"inline_int\"");
1812 }
1913
20- if env::var("ORJSON_DISABLE_YYJSON").is_ok() {
14+ - if env::var("ORJSON_DISABLE_YYJSON").is_ok() {
15+ - if env::var("CARGO_FEATURE_YYJSON").is_ok() {
16+ - panic!("ORJSON_DISABLE_YYJSON and --features=yyjson both enabled.")
17+ - }
18+ - } else {
19+ + // if env::var("ORJSON_DISABLE_YYJSON").is_ok() {
20+ + // if env::var("CARGO_FEATURE_YYJSON").is_ok() {
21+ + // panic!("ORJSON_DISABLE_YYJSON and --features=yyjson both enabled.")
22+ + // }
23+ + // } else {
24+ match cc::Build::new()
25+ .file("include/yyjson/yyjson.c")
26+ .include("include/yyjson")
27+ @@ -68,5 +69,5 @@ fn main() {
28+ }
29+ }
30+ }
31+ - }
32+ + //}
33+ }
2134diff --git a/include/pyo3/pyo3-ffi/src/cpython/abstract_.rs b/include/pyo3/pyo3-ffi/src/cpython/abstract_.rs
2235index 477ad02..0b649f3 100644
2336--- a/include/pyo3/pyo3-ffi/src/cpython/abstract_.rs
@@ -484,6 +497,20 @@ index 505840e..e984191 100644
484497 match pyobject_to_obtype(value, self.state.opts()) {
485498 ObType::Str => {
486499 seq.serialize_element(&StrSerializer::new(value))?;
500+ diff --git a/src/serialize/per_type/numpy.rs b/src/serialize/per_type/numpy.rs
501+ index f888029..4a0fe0e 100644
502+ --- a/src/serialize/per_type/numpy.rs
503+ +++ b/src/serialize/per_type/numpy.rs
504+ @@ -196,8 +196,7 @@ impl NumpyArray {
505+ pub fn new(ptr: *mut PyObject, opts: Opt) -> Result<Self, PyArrayError> {
506+ let capsule = ffi!(PyObject_GetAttr(ptr, ARRAY_STRUCT_STR));
507+ let array = unsafe {
508+ - (*capsule.cast::<PyCapsule>())
509+ - .pointer
510+ + ffi!(PyCapsule_GetPointer(capsule, core::ptr::null_mut()))
511+ .cast::<PyArrayInterface>()
512+ };
513+ if unsafe { (*array).two != 2 } {
487514diff --git a/src/serialize/serializer.rs b/src/serialize/serializer.rs
488515index 7b9a5de..e291912 100644
489516--- a/src/serialize/serializer.rs
@@ -769,7 +796,7 @@ index 7b1c2df..5ac8dec 100644
769796 }
770797 }
771798diff --git a/src/str/scalar.rs b/src/str/scalar.rs
772- index 12adb63..99fce8f 100644
799+ index 12adb63..e0cdd8b 100644
773800--- a/src/str/scalar.rs
774801+++ b/src/str/scalar.rs
775802@@ -1,11 +1,17 @@
@@ -790,17 +817,6 @@ index 12adb63..99fce8f 100644
790817 let num_chars = bytecount::num_chars(buf.as_bytes());
791818 if buf.len() == num_chars {
792819 return pyunicode_ascii(buf.as_ptr(), num_chars);
793- @@ -40,7 +46,9 @@ pub fn str_impl_kind_scalar(buf: &str) -> *mut pyo3_ffi::PyObject {
794- #[inline(always)]
795- pub fn unicode_from_str(buf: &str) -> *mut pyo3_ffi::PyObject {
796- if unlikely!(buf.is_empty()) {
797- - return use_immortal!(crate::typeref::EMPTY_UNICODE);
798- + // Not immortal on GraalPy
799- + ffi!(Py_INCREF(crate::typeref::EMPTY_UNICODE));
800- + return unsafe { crate::typeref::EMPTY_UNICODE };
801- }
802- str_impl_kind_scalar(buf)
803- }
804820diff --git a/src/typeref.rs b/src/typeref.rs
805821index bf925a4..388c9f4 100644
806822--- a/src/typeref.rs
@@ -851,7 +867,7 @@ index bf925a4..388c9f4 100644
851867 ptr
852868 }
853869diff --git a/src/util.rs b/src/util.rs
854- index ccf425c..bc9268d 100644
870+ index ccf425c..ce99eaa 100644
855871--- a/src/util.rs
856872+++ b/src/util.rs
857873@@ -10,7 +10,7 @@ macro_rules! is_type {
@@ -889,25 +905,35 @@ index ccf425c..bc9268d 100644
889905 #[cfg(all(Py_3_12, not(Py_3_13)))]
890906 macro_rules! pydict_contains {
891907 ($obj1:expr, $obj2:expr) => {
892- @@ -222,6 +221,7 @@ macro_rules! pydict_contains {
908+ @@ -222,18 +221,20 @@ macro_rules! pydict_contains {
893909 unsafe { pyo3_ffi::PyDict_Contains((*$obj1).tp_dict, $obj2) == 1 }
894910 };
895911 }
896912+ */
897913
898- #[cfg(Py_3_12)]
899- macro_rules! use_immortal {
900- @@ -234,6 +234,9 @@ macro_rules! use_immortal {
914+ - #[cfg(Py_3_12)]
915+ - macro_rules! use_immortal {
916+ - ($op:expr) => {
917+ - unsafe { $op }
918+ - };
919+ - }
920+ + // #[cfg(Py_3_12)]
921+ + // macro_rules! use_immortal {
922+ + // ($op:expr) => {
923+ + // unsafe { $op }
924+ + // };
925+ + // }
926+
927+ - #[cfg(not(Py_3_12))]
928+ + // #[cfg(not(Py_3_12))]
901929 macro_rules! use_immortal {
902930 ($op:expr) => {
903931 unsafe {
904- + // orjson makes assumption about something being immortal that is not immortal
905- + // on GraalPy: update the caller to do proper refcounting instead
906- + debug_assert!(ffi!(_Py_IsImmortal($op)) == 1);
932+ + // We let GraalPy's Py_INCREF decide what is immortal and what not
907933 ffi!(Py_INCREF($op));
908934 $op
909935 }
910- @@ -256,20 +259 ,11 @@ macro_rules! pydict_next {
936+ @@ -256,20 +257 ,11 @@ macro_rules! pydict_next {
911937
912938 macro_rules! pydict_setitem {
913939 ($dict:expr, $pykey:expr, $pyval:expr) => {
0 commit comments