From 2ed108a73bd5fbe0e1c43a8db07e40a165fc265f Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 14 Aug 2023 16:38:25 +0200 Subject: [PATCH] test builds on PyPy 3.10 --- .github/workflows/ci.yml | 6 ++++-- cmake/darwin-ld-pypy.sym | 1 + include/nanobind/nb_class.h | 2 +- include/nanobind/nb_defs.h | 16 ++++++++++++++++ include/nanobind/nb_lib.h | 2 +- src/nb_type.cpp | 10 +++++----- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e62a7ff4..a9336b6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,10 +21,12 @@ jobs: fail-fast: false matrix: os: ['ubuntu-latest', 'windows-2022', 'macos-latest'] - python: ['3.8', '3.9', '3.10', '3.11', '3.12.0-rc.1', 'pypy3.9'] + python: ['3.8', '3.9', '3.10', '3.11', '3.12.0-rc.1', 'pypy3.9', 'pypy3.10'] exclude: - os: 'macos-latest' python: 'pypy3.9' + - os: 'macos-latest' + python: 'pypy3.10' - os: 'windows-2022' python: '3.12.0-rc.1' @@ -53,7 +55,7 @@ jobs: python -m pip install pytest pytest-github-actions-annotate-failures - name: Install NumPy - if: matrix.python != 'pypy3.9' && matrix.python != '3.12.0-rc.1' + if: matrix.python != 'pypy3.9' && matrix.python != 'pypy3.10' && matrix.python != '3.12.0-rc.1' run: | python -m pip install numpy scipy diff --git a/cmake/darwin-ld-pypy.sym b/cmake/darwin-ld-pypy.sym index 5940cfb2..1863c134 100644 --- a/cmake/darwin-ld-pypy.sym +++ b/cmake/darwin-ld-pypy.sym @@ -267,6 +267,7 @@ -U _PyPyFile_WriteString -U _PyPyFloat_AS_DOUBLE -U _PyPyFloat_AsDouble +-U _PyPyFloat_Check -U _PyPyFloat_FromDouble -U _PyPyFloat_FromString -U _PyPyFloat_Type diff --git a/include/nanobind/nb_class.h b/include/nanobind/nb_class.h index 7a0eaaa5..3f1801a2 100644 --- a/include/nanobind/nb_class.h +++ b/include/nanobind/nb_class.h @@ -276,7 +276,7 @@ inline void inst_replace_copy(handle dst, handle src) { detail::nb_inst_replace_ inline void inst_replace_move(handle dst, handle src) { detail::nb_inst_replace_move(dst.ptr(), src.ptr()); } template T *inst_ptr(handle h) { return (T *) detail::nb_inst_ptr(h.ptr()); } inline void *type_get_slot(handle h, int slot_id) { -#if PY_VERSION_HEX < 0x030A0000 +#if NB_TYPE_GET_SLOT_IMPL return detail::type_get_slot((PyTypeObject *) h.ptr(), slot_id); #else return PyType_GetSlot((PyTypeObject *) h.ptr(), slot_id); diff --git a/include/nanobind/nb_defs.h b/include/nanobind/nb_defs.h index 6b677a49..f082af54 100644 --- a/include/nanobind/nb_defs.h +++ b/include/nanobind/nb_defs.h @@ -139,6 +139,22 @@ # define NB_DOMAIN_STR nullptr #endif +#if !defined(PYPY_VERSION) +# if PY_VERSION_HEX < 0x030A0000 +# define NB_TYPE_GET_SLOT_IMPL 1 // Custom implementation of nb::type_get_slot +# else +# define NB_TYPE_GET_SLOT_IMPL 0 +# endif +# if PY_VERSION_HEX < 0x030C0000 +# define NB_TYPE_FROM_METACLASS_IMPL 1 // Custom implementation of PyType_FromMetaclass +# else +# define NB_TYPE_FROM_METACLASS_IMPL 0 +# endif +#else +# define NB_TYPE_FROM_METACLASS_IMPL 1 +# define NB_TYPE_GET_SLOT_IMPL 1 +#endif + #define NB_MODULE_IMPL(name) \ extern "C" [[maybe_unused]] NB_EXPORT PyObject *PyInit_##name(); \ extern "C" NB_EXPORT PyObject *PyInit_##name() diff --git a/include/nanobind/nb_lib.h b/include/nanobind/nb_lib.h index 73d57c29..20267031 100644 --- a/include/nanobind/nb_lib.h +++ b/include/nanobind/nb_lib.h @@ -498,7 +498,7 @@ NB_CORE void slice_compute(PyObject *slice, Py_ssize_t size, NB_CORE PyObject *repr_list(PyObject *o); NB_CORE PyObject *repr_map(PyObject *o); -#if PY_VERSION_HEX < 0x030A0000 +#if NB_TYPE_GET_SLOT_IMPL NB_CORE void *type_get_slot(PyTypeObject *t, int slot_id); #endif diff --git a/src/nb_type.cpp b/src/nb_type.cpp index c3f87e40..084947a3 100644 --- a/src/nb_type.cpp +++ b/src/nb_type.cpp @@ -385,10 +385,10 @@ static int nb_type_setattro(PyObject* obj, PyObject* name, PyObject* value) { return NB_SLOT(PyType_Type, tp_setattro)(obj, name, value); } -#if PY_VERSION_HEX < 0x030C0000 +#if NB_TYPE_FROM_METACLASS_IMPL || NB_TYPE_GET_SLOT_IMPL struct nb_slot { -#if PY_VERSION_HEX < 0x030A0000 +#if NB_TYPE_GET_SLOT_IMPL uint8_t indirect_1; uint8_t indirect_2; #endif @@ -400,7 +400,7 @@ template nb_slot constexp static_assert(I1 == I2 && (Offset1 % sizeof(void *)) == 0 && (Offset2 % sizeof(void *)) == 0, "nb_slot construction: internal error"); -#if PY_VERSION_HEX < 0x030A0000 +#if NB_TYPE_GET_SLOT_IMPL size_t o = 0; switch (Offset1) { case offsetof(PyHeapTypeObject, as_async): o = offsetof(PyTypeObject, tp_as_async); break; @@ -518,7 +518,7 @@ static constexpr nb_slot type_slots[] { #endif }; -#if PY_VERSION_HEX < 0x030A0000 +#if NB_TYPE_GET_SLOT_IMPL void *type_get_slot(PyTypeObject *t, int slot_id) { nb_slot slot = type_slots[slot_id - 1]; @@ -537,7 +537,7 @@ void *type_get_slot(PyTypeObject *t, int slot_id) { static PyObject *nb_type_from_metaclass(PyTypeObject *meta, PyObject *mod, PyType_Spec *spec) { -#if PY_VERSION_HEX >= 0x030C0000 +#if NB_TYPE_FROM_METACLASS_IMPL == 0 // Life is good, PyType_FromMetaclass() is available return PyType_FromMetaclass(meta, mod, spec, nullptr); #else