Backport patch to add PyType_GetDict for Python 3.12
This commit is contained in:
parent
787b7fcbf4
commit
8c9ea3fe06
2 changed files with 65 additions and 1 deletions
56
408.patch
Normal file
56
408.patch
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
From c0d62d041371970297c31ac86465cf8983386191 Mon Sep 17 00:00:00 2001
|
||||
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
|
||||
Date: Sun, 23 Jul 2023 17:15:18 +0200
|
||||
Subject: [PATCH] Use PyType_GetDict to safely access tp_dict [3.12]
|
||||
|
||||
---
|
||||
src/util.rs | 15 ++++++++++++++-
|
||||
test/test_default.py | 12 ++++++++++++
|
||||
2 files changed, 26 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/util.rs b/src/util.rs
|
||||
index 3b451bd5..ba011c1a 100644
|
||||
--- a/src/util.rs
|
||||
+++ b/src/util.rs
|
||||
@@ -125,7 +125,20 @@ macro_rules! str_hash {
|
||||
};
|
||||
}
|
||||
|
||||
-#[cfg(Py_3_10)]
|
||||
+#[cfg(Py_3_12)]
|
||||
+macro_rules! pydict_contains {
|
||||
+ ($obj1:expr, $obj2:expr) => {
|
||||
+ unsafe {
|
||||
+ pyo3_ffi::_PyDict_Contains_KnownHash(
|
||||
+ pyo3_ffi::PyType_GetDict($obj1),
|
||||
+ $obj2,
|
||||
+ (*$obj2.cast::<pyo3_ffi::PyASCIIObject>()).hash,
|
||||
+ ) == 1
|
||||
+ }
|
||||
+ };
|
||||
+}
|
||||
+
|
||||
+#[cfg(all(Py_3_10, not(Py_3_12)))]
|
||||
macro_rules! pydict_contains {
|
||||
($obj1:expr, $obj2:expr) => {
|
||||
unsafe {
|
||||
diff --git a/test/test_default.py b/test/test_default.py
|
||||
index d1e95587..547fce8c 100644
|
||||
--- a/test/test_default.py
|
||||
+++ b/test/test_default.py
|
||||
@@ -275,3 +275,15 @@ def default(obj):
|
||||
orjson.dumps(ref, default=default)
|
||||
|
||||
assert sys.getrefcount(ref) == 2 # one for ref, one for default
|
||||
+
|
||||
+ def test_default_set(self):
|
||||
+ """
|
||||
+ dumps() default function with set
|
||||
+ """
|
||||
+
|
||||
+ def default(obj):
|
||||
+ if isinstance(obj, set):
|
||||
+ return list(obj)
|
||||
+ raise TypeError
|
||||
+
|
||||
+ assert orjson.dumps({1, 2}, default=default) == b"[1,2]"
|
||||
|
|
@ -9,12 +9,16 @@
|
|||
|
||||
Name: python-orjson
|
||||
Version: 3.9.2
|
||||
Release: 1%{?dist}
|
||||
Release: 2%{?dist}
|
||||
Summary: Fast, correct Python JSON library
|
||||
|
||||
License: Apache-2.0 OR MIT
|
||||
URL: https://github.com/ijl/orjson
|
||||
Source: %{pypi_source orjson}
|
||||
|
||||
# Compatibility with Python 3.12
|
||||
Patch: https://github.com/ijl/orjson/pull/408.patch
|
||||
|
||||
# Ineligble for upstreaming
|
||||
Patch: Remove-unstable-simd-feature.patch
|
||||
|
||||
|
|
@ -91,6 +95,10 @@ export RUSTFLAGS='%{build_rustflags}'
|
|||
|
||||
|
||||
%changelog
|
||||
* Tue Jul 25 2023 Tomáš Hrnčiar <thrnciar@redhat.com> - 3.9.2-2
|
||||
- Backport patch to add PyType_GetDict for Python 3.12
|
||||
- Fixes: rhbz#2220383
|
||||
|
||||
* Fri Jul 21 2023 Maxwell G <maxwell@gtmx.me> - 3.9.2-1
|
||||
- Update to 3.9.2. Fixes rhbz#2211703.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue