Skip to content

Commit 9026ef0

Browse files
committed
[GR-58384] Add patch for newer pybind11
PullRequest: graalpython/3492
2 parents 5b7a097 + f8b2a68 commit 9026ef0

File tree

6 files changed

+211
-11
lines changed

6 files changed

+211
-11
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
diff --git a/src/greenlet/TThreadStateDestroy.cpp b/src/greenlet/TThreadStateDestroy.cpp
2+
index 37fcc8c..8cf33ae 100644
3+
--- a/src/greenlet/TThreadStateDestroy.cpp
4+
+++ b/src/greenlet/TThreadStateDestroy.cpp
5+
@@ -71,6 +71,7 @@ private:
6+
static bool
7+
MarkGreenletDeadIfNeeded(ThreadState* const state)
8+
{
9+
+#if 0 // GraalPy change
10+
if (state && state->has_main_greenlet()) {
11+
// mark the thread as dead ASAP.
12+
// this is racy! If we try to throw or switch to a
13+
@@ -83,6 +84,7 @@ private:
14+
return true;
15+
}
16+
return false;
17+
+#endif // GraalPy change
18+
}
19+
20+
static void
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[[rules]]
2-
version = '>= 3.0.0'
2+
version = '>= 3.1.1'
3+
patch = 'greenlet-3.1.1.patch'
4+
license = 'MIT'
5+
6+
[[rules]]
7+
version = '>= 3.0.0, < 3.1.1'
38
patch = 'greenlet-3.0.0.patch'
49
license = 'MIT'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[[rules]]
2+
# Upstreamed, should not be needed in the next release
3+
version = '<= 0.5.0'
4+
install-priority = 0
25
patch = 'jiter.patch'
36
license = 'MIT'
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
[[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+
17
[[rules]]
28
# Note: This patch file is also used directly outside of pip during onnxruntime build
39
# Note: This patch file is also used directly outside of pip during tensorflow build
410
# 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.

graalpython/lib-graalpython/patches/torch/torch-2.4.1.patch

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,19 @@ index 454e6061b..7feafc7d7 100644
191191
# define PYBIND11_SIMPLE_GIL_MANAGEMENT
192192
#endif
193193

194+
diff --git a/third_party/pybind11/include/pybind11/detail/internals.h b/third_party/pybind11/include/pybind11/detail/internals.h
195+
index c1047e4a0..c8453f30e 100644
196+
--- a/third_party/pybind11/include/pybind11/detail/internals.h
197+
+++ b/third_party/pybind11/include/pybind11/detail/internals.h
198+
@@ -442,7 +442,7 @@ inline void translate_local_exception(std::exception_ptr p) {
199+
200+
inline object get_python_state_dict() {
201+
object state_dict;
202+
-#if PYBIND11_INTERNALS_VERSION <= 4 || PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION)
203+
+#if PYBIND11_INTERNALS_VERSION <= 4 || PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)
204+
state_dict = reinterpret_borrow<object>(PyEval_GetBuiltins());
205+
#else
206+
# if PY_VERSION_HEX < 0x03090000
194207
diff --git a/third_party/pybind11/include/pybind11/detail/type_caster_base.h b/third_party/pybind11/include/pybind11/detail/type_caster_base.h
195208
index 518d3107b..1b9edca02 100644
196209
--- a/third_party/pybind11/include/pybind11/detail/type_caster_base.h
@@ -205,36 +218,69 @@ index 518d3107b..1b9edca02 100644
205218
#elif PY_VERSION_HEX < 0x030D0000
206219
return _PyThreadState_UncheckedGet();
207220
diff --git a/third_party/pybind11/include/pybind11/eval.h b/third_party/pybind11/include/pybind11/eval.h
208-
index bd5f981f5..c25f036b1 100644
221+
index bd5f981f5..ee271672d 100644
209222
--- a/third_party/pybind11/include/pybind11/eval.h
210223
+++ b/third_party/pybind11/include/pybind11/eval.h
211-
@@ -94,7 +94,7 @@ void exec(const char (&s)[N], object global = globals(), object local = object()
224+
@@ -94,18 +94,18 @@ void exec(const char (&s)[N], object global = globals(), object local = object()
212225
eval<eval_statements>(s, std::move(global), std::move(local));
213226
}
214227

215228
-#if defined(PYPY_VERSION)
216229
+#if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)
217230
template <eval_mode mode = eval_statements>
218231
object eval_file(str, object, object) {
219-
pybind11_fail("eval_file not supported in PyPy3. Use eval");
232+
- pybind11_fail("eval_file not supported in PyPy3. Use eval");
233+
+ pybind11_fail("eval_file not supported in PyPy3 or GraalPy. Use eval");
234+
}
235+
template <eval_mode mode = eval_statements>
236+
object eval_file(str, object) {
237+
- pybind11_fail("eval_file not supported in PyPy3. Use eval");
238+
+ pybind11_fail("eval_file not supported in PyPy3 or GraalPy. Use eval");
239+
}
240+
template <eval_mode mode = eval_statements>
241+
object eval_file(str) {
242+
- pybind11_fail("eval_file not supported in PyPy3. Use eval");
243+
+ pybind11_fail("eval_file not supported in PyPy3 or GraalPy. Use eval");
244+
}
245+
#else
246+
template <eval_mode mode = eval_statements>
220247
diff --git a/third_party/pybind11/include/pybind11/pybind11.h b/third_party/pybind11/include/pybind11/pybind11.h
221-
index 131d2e18a..9e11c4c8d 100644
248+
index 131d2e18a..86f3c5cad 100644
222249
--- a/third_party/pybind11/include/pybind11/pybind11.h
223250
+++ b/third_party/pybind11/include/pybind11/pybind11.h
224-
@@ -592,7 +592,7 @@ protected:
251+
@@ -591,8 +591,7 @@ protected:
252+
// chain.
225253
chain_start = rec;
226254
rec->next = chain;
227-
auto rec_capsule
255+
- auto rec_capsule
228256
- = reinterpret_borrow<capsule>(((PyCFunctionObject *) m_ptr)->m_self);
229-
+ = reinterpret_borrow<capsule>(PyCFunction_GetSelf(m_ptr));
257+
+ auto rec_capsule = reinterpret_borrow<capsule>(PyCFunction_GET_SELF(m_ptr));
230258
rec_capsule.set_pointer(unique_rec.release());
231259
guarded_strdup.release();
232260
} else {
233-
@@ -2762,7 +2762,7 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
261+
@@ -652,9 +651,15 @@ protected:
262+
263+
/* Install docstring */
264+
auto *func = (PyCFunctionObject *) m_ptr;
265+
+#if !defined(GRAALVM_PYTHON)
266+
//std::free(const_cast<char *>(GraalPyCFunction_GetDoc((PyObject*)(func))));
267+
// Install docstring if it's non-empty (when at least one option is enabled)
268+
GraalPyCFunction_SetDoc((PyObject*)(func), signatures.empty() ? nullptr : PYBIND11_COMPAT_STRDUP(signatures.c_str()));
269+
+#else
270+
+ std::free(const_cast<char *>(GraalPyCFunction_GetDoc(m_ptr)));
271+
+ GraalPyCFunction_SetDoc(
272+
+ m_ptr, signatures.empty() ? nullptr : PYBIND11_COMPAT_STRDUP(signatures.c_str()));
273+
+#endif
274+
275+
if (rec->is_method) {
276+
m_ptr = PYBIND11_INSTANCE_METHOD_NEW(m_ptr, rec->scope.ptr());
277+
@@ -2761,8 +2766,8 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
278+
}
234279

235280
/* Don't call dispatch code if invoked from overridden function.
236-
Unfortunately this doesn't work on PyPy. */
281+
- Unfortunately this doesn't work on PyPy. */
237282
-#if !defined(PYPY_VERSION)
283+
+ Unfortunately this doesn't work on PyPy and GraalPy. */
238284
+#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)
239285
# if PY_VERSION_HEX >= 0x03090000
240286
PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());

0 commit comments

Comments
 (0)