Skip to content

Commit

Permalink
test builds on PyPy 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Aug 14, 2023
1 parent fb55089 commit 2ed108a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmake/darwin-ld-pypy.sym
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/nanobind/nb_class.h
Expand Up @@ -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 <typename T> 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);
Expand Down
16 changes: 16 additions & 0 deletions include/nanobind/nb_defs.h
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion include/nanobind/nb_lib.h
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/nb_type.cpp
Expand Up @@ -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
Expand All @@ -400,7 +400,7 @@ template <size_t I1, size_t I2, size_t Offset1, size_t Offset2> 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;
Expand Down Expand Up @@ -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];

Expand All @@ -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
Expand Down

0 comments on commit 2ed108a

Please sign in to comment.