Skip to content

Commit f8b2a68

Browse files
committed
Update pybind11 patch inlined in torch patch
1 parent bcb1a45 commit f8b2a68

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

graalpython/lib-graalpython/patches/pybind11/metadata.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ patch = 'pybind11-2.11.patch'
55
license = 'BSD-3-Clause'
66

77
[[rules]]
8-
# Note: This patch is also inlined in torch
98
# Note: This patch file is also used directly outside of pip during onnxruntime build
109
# Note: This patch file is also used directly outside of pip during tensorflow build
10+
# Note: This patch is also inlined in torch
1111
version = '>= 2.10.1, < 2.11.0'
1212
patch = 'pybind11-2.10.1.patch'
1313
license = 'BSD-3-Clause'

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)