Skip to content

Commit bcb1a45

Browse files
committed
Add patch for pybind11+
1 parent 6c14cd4 commit bcb1a45

File tree

2 files changed

+128
-2
lines changed

2 files changed

+128
-2
lines changed
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
[[rules]]
2+
# Note: This patch is also inlined in torch
3+
version = '>= 2.11.0'
4+
patch = 'pybind11-2.11.patch'
5+
license = 'BSD-3-Clause'
6+
7+
[[rules]]
8+
# Note: This patch is also inlined in torch
29
# Note: This patch file is also used directly outside of pip during onnxruntime build
310
# Note: This patch file is also used directly outside of pip during tensorflow build
4-
# Note: This patch is also inlined in torch
5-
version = '>= 2.10.1'
11+
version = '>= 2.10.1, < 2.11.0'
612
patch = 'pybind11-2.10.1.patch'
713
license = 'BSD-3-Clause'
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
diff --git a/pybind11/include/pybind11/detail/common.h b/pybind11/include/pybind11/detail/common.h
2+
index c51d1d6..3976dd3 100644
3+
--- a/pybind11/include/pybind11/detail/common.h
4+
+++ b/pybind11/include/pybind11/detail/common.h
5+
@@ -299,7 +299,7 @@ PYBIND11_WARNING_DISABLE_MSVC(4505)
6+
# define PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED
7+
#endif
8+
9+
-#if defined(PYPY_VERSION) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
10+
+#if (defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
11+
# define PYBIND11_SIMPLE_GIL_MANAGEMENT
12+
#endif
13+
14+
diff --git a/pybind11/include/pybind11/detail/internals.h b/pybind11/include/pybind11/detail/internals.h
15+
index 232bc32..acde741 100644
16+
--- a/pybind11/include/pybind11/detail/internals.h
17+
+++ b/pybind11/include/pybind11/detail/internals.h
18+
@@ -449,7 +449,7 @@ inline void translate_local_exception(std::exception_ptr p) {
19+
20+
inline object get_python_state_dict() {
21+
object state_dict;
22+
-#if PYBIND11_INTERNALS_VERSION <= 4 || PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION)
23+
+#if PYBIND11_INTERNALS_VERSION <= 4 || PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)
24+
state_dict = reinterpret_borrow<object>(PyEval_GetBuiltins());
25+
#else
26+
# if PY_VERSION_HEX < 0x03090000
27+
diff --git a/pybind11/include/pybind11/detail/type_caster_base.h b/pybind11/include/pybind11/detail/type_caster_base.h
28+
index e40e44b..e7b94af 100644
29+
--- a/pybind11/include/pybind11/detail/type_caster_base.h
30+
+++ b/pybind11/include/pybind11/detail/type_caster_base.h
31+
@@ -459,7 +459,7 @@ PYBIND11_NOINLINE handle get_object_handle(const void *ptr, const detail::type_i
32+
}
33+
34+
inline PyThreadState *get_thread_state_unchecked() {
35+
-#if defined(PYPY_VERSION)
36+
+#if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)
37+
return PyThreadState_GET();
38+
#elif PY_VERSION_HEX < 0x030D0000
39+
return _PyThreadState_UncheckedGet();
40+
diff --git a/pybind11/include/pybind11/eval.h b/pybind11/include/pybind11/eval.h
41+
index bd5f981..ee27167 100644
42+
--- a/pybind11/include/pybind11/eval.h
43+
+++ b/pybind11/include/pybind11/eval.h
44+
@@ -94,18 +94,18 @@ void exec(const char (&s)[N], object global = globals(), object local = object()
45+
eval<eval_statements>(s, std::move(global), std::move(local));
46+
}
47+
48+
-#if defined(PYPY_VERSION)
49+
+#if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)
50+
template <eval_mode mode = eval_statements>
51+
object eval_file(str, object, object) {
52+
- pybind11_fail("eval_file not supported in PyPy3. Use eval");
53+
+ pybind11_fail("eval_file not supported in PyPy3 or GraalPy. Use eval");
54+
}
55+
template <eval_mode mode = eval_statements>
56+
object eval_file(str, object) {
57+
- pybind11_fail("eval_file not supported in PyPy3. Use eval");
58+
+ pybind11_fail("eval_file not supported in PyPy3 or GraalPy. Use eval");
59+
}
60+
template <eval_mode mode = eval_statements>
61+
object eval_file(str) {
62+
- pybind11_fail("eval_file not supported in PyPy3. Use eval");
63+
+ pybind11_fail("eval_file not supported in PyPy3 or GraalPy. Use eval");
64+
}
65+
#else
66+
template <eval_mode mode = eval_statements>
67+
diff --git a/pybind11/include/pybind11/pybind11.h b/pybind11/include/pybind11/pybind11.h
68+
index 949bc9b..6e17baa 100644
69+
--- a/pybind11/include/pybind11/pybind11.h
70+
+++ b/pybind11/include/pybind11/pybind11.h
71+
@@ -573,8 +573,7 @@ protected:
72+
// chain.
73+
chain_start = rec;
74+
rec->next = chain;
75+
- auto rec_capsule
76+
- = reinterpret_borrow<capsule>(((PyCFunctionObject *) m_ptr)->m_self);
77+
+ auto rec_capsule = reinterpret_borrow<capsule>(PyCFunction_GET_SELF(m_ptr));
78+
rec_capsule.set_pointer(unique_rec.release());
79+
guarded_strdup.release();
80+
} else {
81+
@@ -636,9 +635,15 @@ protected:
82+
83+
/* Install docstring */
84+
auto *func = (PyCFunctionObject *) m_ptr;
85+
+#if !defined(GRAALVM_PYTHON)
86+
//std::free(const_cast<char *>(GraalPyCFunction_GetDoc((PyObject*)(func))));
87+
// Install docstring if it's non-empty (when at least one option is enabled)
88+
GraalPyCFunction_SetDoc((PyObject*)(func), signatures.empty() ? nullptr : PYBIND11_COMPAT_STRDUP(signatures.c_str()));
89+
+#else
90+
+ std::free(const_cast<char *>(GraalPyCFunction_GetDoc(m_ptr)));
91+
+ GraalPyCFunction_SetDoc(
92+
+ m_ptr, signatures.empty() ? nullptr : PYBIND11_COMPAT_STRDUP(signatures.c_str()));
93+
+#endif
94+
95+
if (rec->is_method) {
96+
m_ptr = PYBIND11_INSTANCE_METHOD_NEW(m_ptr, rec->scope.ptr());
97+
@@ -2766,8 +2771,8 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
98+
}
99+
100+
/* Don't call dispatch code if invoked from overridden function.
101+
- Unfortunately this doesn't work on PyPy. */
102+
-#if !defined(PYPY_VERSION)
103+
+ Unfortunately this doesn't work on PyPy and GraalPy. */
104+
+#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)
105+
# if PY_VERSION_HEX >= 0x03090000
106+
PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());
107+
if (frame != nullptr) {
108+
diff --git a/pybind11/include/pybind11/pytypes.h b/pybind11/include/pybind11/pytypes.h
109+
index 8052f2e..7aafab6 100644
110+
--- a/pybind11/include/pybind11/pytypes.h
111+
+++ b/pybind11/include/pybind11/pytypes.h
112+
@@ -643,7 +643,7 @@ struct error_fetch_and_normalize {
113+
114+
bool have_trace = false;
115+
if (m_trace) {
116+
-#if !defined(PYPY_VERSION)
117+
+#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)
118+
auto *tb = reinterpret_cast<PyTracebackObject *>(m_trace.ptr());
119+
120+
// Get the deepest trace possible.

0 commit comments

Comments
 (0)