Skip to content

Commit 98ec25c

Browse files
committed
Merge branch 'master' into sh_merge_master
2 parents 43d6bfc + c4a05f9 commit 98ec25c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+212
-66
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
- 'pypy-3.8'
4141
- 'pypy-3.9'
4242
- 'pypy-3.10'
43+
- 'graalpy-24.1'
4344

4445
# Items in here will either be added to the build matrix (if not
4546
# present), or add new keys to an existing matrix element if all the
@@ -96,6 +97,11 @@ jobs:
9697
python: '3.12'
9798
args: >
9899
-DCMAKE_CXX_FLAGS="/DPYBIND11_SMART_HOLDER_DISABLE /GR /EHsc"
100+
exclude:
101+
# The setup-python action currently doesn't have graalpy for windows
102+
- python: 'graalpy-24.1'
103+
runs-on: 'windows-2022'
104+
99105

100106
name: "🐍 ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}"
101107
runs-on: ${{ matrix.runs-on }}

include/pybind11/cast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class type_caster<bool> {
343343
#else
344344
// Alternate approach for CPython: this does the same as the above, but optimized
345345
// using the CPython API so as to avoid an unneeded attribute lookup.
346-
else if (auto *tp_as_number = src.ptr()->ob_type->tp_as_number) {
346+
else if (auto *tp_as_number = Py_TYPE(src.ptr())->tp_as_number) {
347347
if (PYBIND11_NB_BOOL(tp_as_number)) {
348348
res = (*PYBIND11_NB_BOOL(tp_as_number))(src.ptr());
349349
}

include/pybind11/detail/common.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ PYBIND11_WARNING_DISABLE_MSVC(4505)
299299
# define PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED
300300
#endif
301301

302-
#if defined(PYPY_VERSION) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
302+
#if (defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
303303
# define PYBIND11_SIMPLE_GIL_MANAGEMENT
304304
#endif
305305

@@ -387,6 +387,20 @@ PYBIND11_WARNING_POP
387387
#define PYBIND11_CONCAT(first, second) first##second
388388
#define PYBIND11_ENSURE_INTERNALS_READY pybind11::detail::get_internals();
389389

390+
#if !defined(GRAALVM_PYTHON)
391+
# define PYBIND11_PYCFUNCTION_GET_DOC(func) ((func)->m_ml->ml_doc)
392+
# define PYBIND11_PYCFUNCTION_SET_DOC(func, doc) \
393+
do { \
394+
(func)->m_ml->ml_doc = (doc); \
395+
} while (0)
396+
#else
397+
# define PYBIND11_PYCFUNCTION_GET_DOC(func) (GraalPyCFunction_GetDoc((PyObject *) (func)))
398+
# define PYBIND11_PYCFUNCTION_SET_DOC(func, doc) \
399+
do { \
400+
GraalPyCFunction_SetDoc((PyObject *) (func), (doc)); \
401+
} while (0)
402+
#endif
403+
390404
#define PYBIND11_CHECK_PYTHON_VERSION \
391405
{ \
392406
const char *compiled_ver \

include/pybind11/detail/internals.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ inline void translate_local_exception(std::exception_ptr p) {
480480

481481
inline object get_python_state_dict() {
482482
object state_dict;
483-
#if PYBIND11_INTERNALS_VERSION <= 4 || defined(PYPY_VERSION)
483+
#if PYBIND11_INTERNALS_VERSION <= 4 || defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)
484484
state_dict = reinterpret_borrow<object>(PyEval_GetBuiltins());
485485
#else
486486
# if PY_VERSION_HEX < 0x03090000
@@ -753,7 +753,8 @@ const char *c_str(Args &&...args) {
753753
}
754754

755755
inline const char *get_function_record_capsule_name() {
756-
#if PYBIND11_INTERNALS_VERSION > 4
756+
// On GraalPy, pointer equality of the names is currently not guaranteed
757+
#if PYBIND11_INTERNALS_VERSION > 4 && !defined(GRAALVM_PYTHON)
757758
return get_internals().function_record_capsule_name.c_str();
758759
#else
759760
return nullptr;

include/pybind11/detail/type_caster_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ PYBIND11_NOINLINE handle get_object_handle(const void *ptr, const detail::type_i
463463
}
464464

465465
inline PyThreadState *get_thread_state_unchecked() {
466-
#if defined(PYPY_VERSION)
466+
#if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)
467467
return PyThreadState_GET();
468468
#elif PY_VERSION_HEX < 0x030D0000
469469
return _PyThreadState_UncheckedGet();

include/pybind11/eval.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,18 @@ void exec(const char (&s)[N], object global = globals(), object local = object()
9494
eval<eval_statements>(s, std::move(global), std::move(local));
9595
}
9696

97-
#if defined(PYPY_VERSION)
97+
#if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)
9898
template <eval_mode mode = eval_statements>
9999
object eval_file(str, object, object) {
100-
pybind11_fail("eval_file not supported in PyPy3. Use eval");
100+
pybind11_fail("eval_file not supported in this interpreter. Use eval");
101101
}
102102
template <eval_mode mode = eval_statements>
103103
object eval_file(str, object) {
104-
pybind11_fail("eval_file not supported in PyPy3. Use eval");
104+
pybind11_fail("eval_file not supported in this interpreter. Use eval");
105105
}
106106
template <eval_mode mode = eval_statements>
107107
object eval_file(str) {
108-
pybind11_fail("eval_file not supported in PyPy3. Use eval");
108+
pybind11_fail("eval_file not supported in this interpreter. Use eval");
109109
}
110110
#else
111111
template <eval_mode mode = eval_statements>

include/pybind11/pybind11.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,7 @@ class cpp_function : public function {
575575
// chain.
576576
chain_start = rec;
577577
rec->next = chain;
578-
auto rec_capsule
579-
= reinterpret_borrow<capsule>(((PyCFunctionObject *) m_ptr)->m_self);
578+
auto rec_capsule = reinterpret_borrow<capsule>(PyCFunction_GET_SELF(m_ptr));
580579
rec_capsule.set_pointer(unique_rec.release());
581580
guarded_strdup.release();
582581
} else {
@@ -636,12 +635,11 @@ class cpp_function : public function {
636635
}
637636
}
638637

639-
/* Install docstring */
640638
auto *func = (PyCFunctionObject *) m_ptr;
641-
std::free(const_cast<char *>(func->m_ml->ml_doc));
642639
// Install docstring if it's non-empty (when at least one option is enabled)
643-
func->m_ml->ml_doc
644-
= signatures.empty() ? nullptr : PYBIND11_COMPAT_STRDUP(signatures.c_str());
640+
auto *doc = signatures.empty() ? nullptr : PYBIND11_COMPAT_STRDUP(signatures.c_str());
641+
std::free(const_cast<char *>(PYBIND11_PYCFUNCTION_GET_DOC(func)));
642+
PYBIND11_PYCFUNCTION_SET_DOC(func, doc);
645643

646644
if (rec->is_method) {
647645
m_ptr = PYBIND11_INSTANCE_METHOD_NEW(m_ptr, rec->scope.ptr());
@@ -3119,8 +3117,8 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
31193117
}
31203118

31213119
/* Don't call dispatch code if invoked from overridden function.
3122-
Unfortunately this doesn't work on PyPy. */
3123-
#if !defined(PYPY_VERSION)
3120+
Unfortunately this doesn't work on PyPy and GraalPy. */
3121+
#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)
31243122
# if PY_VERSION_HEX >= 0x03090000
31253123
PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());
31263124
if (frame != nullptr) {

include/pybind11/pytypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ struct error_fetch_and_normalize {
643643

644644
bool have_trace = false;
645645
if (m_trace) {
646-
#if !defined(PYPY_VERSION)
646+
#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)
647647
auto *tb = reinterpret_cast<PyTracebackObject *>(m_trace.ptr());
648648

649649
// Get the deepest trace possible.
@@ -1356,7 +1356,7 @@ inline bool PyUnicode_Check_Permissive(PyObject *o) {
13561356
# define PYBIND11_STR_CHECK_FUN PyUnicode_Check
13571357
#endif
13581358

1359-
inline bool PyStaticMethod_Check(PyObject *o) { return o->ob_type == &PyStaticMethod_Type; }
1359+
inline bool PyStaticMethod_Check(PyObject *o) { return Py_TYPE(o) == &PyStaticMethod_Type; }
13601360

13611361
class kwargs_proxy : public handle {
13621362
public:

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
@pytest.fixture(scope="session", autouse=True)
3030
def use_multiprocessing_forkserver_on_linux():
31-
if sys.platform != "linux":
32-
# The default on Windows and macOS is "spawn": If it's not broken, don't fix it.
31+
if sys.platform != "linux" or sys.implementation.name == "graalpy":
32+
# The default on Windows, macOS and GraalPy is "spawn": If it's not broken, don't fix it.
3333
return
3434

3535
# Full background: https://github.com/pybind/pybind11/issues/4105#issuecomment-1301004592

tests/env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
CPYTHON = platform.python_implementation() == "CPython"
1414
PYPY = platform.python_implementation() == "PyPy"
15+
GRAALPY = sys.implementation.name == "graalpy"
1516
PY_GIL_DISABLED = bool(sysconfig.get_config_var("Py_GIL_DISABLED"))
1617

1718

0 commit comments

Comments
 (0)