Skip to content

Commit 2ed108a

Browse files
committed
test builds on PyPy 3.10
1 parent fb55089 commit 2ed108a

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
os: ['ubuntu-latest', 'windows-2022', 'macos-latest']
24-
python: ['3.8', '3.9', '3.10', '3.11', '3.12.0-rc.1', 'pypy3.9']
24+
python: ['3.8', '3.9', '3.10', '3.11', '3.12.0-rc.1', 'pypy3.9', 'pypy3.10']
2525
exclude:
2626
- os: 'macos-latest'
2727
python: 'pypy3.9'
28+
- os: 'macos-latest'
29+
python: 'pypy3.10'
2830
- os: 'windows-2022'
2931
python: '3.12.0-rc.1'
3032

@@ -53,7 +55,7 @@ jobs:
5355
python -m pip install pytest pytest-github-actions-annotate-failures
5456
5557
- name: Install NumPy
56-
if: matrix.python != 'pypy3.9' && matrix.python != '3.12.0-rc.1'
58+
if: matrix.python != 'pypy3.9' && matrix.python != 'pypy3.10' && matrix.python != '3.12.0-rc.1'
5759
run: |
5860
python -m pip install numpy scipy
5961

cmake/darwin-ld-pypy.sym

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
-U _PyPyFile_WriteString
268268
-U _PyPyFloat_AS_DOUBLE
269269
-U _PyPyFloat_AsDouble
270+
-U _PyPyFloat_Check
270271
-U _PyPyFloat_FromDouble
271272
-U _PyPyFloat_FromString
272273
-U _PyPyFloat_Type

include/nanobind/nb_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ inline void inst_replace_copy(handle dst, handle src) { detail::nb_inst_replace_
276276
inline void inst_replace_move(handle dst, handle src) { detail::nb_inst_replace_move(dst.ptr(), src.ptr()); }
277277
template <typename T> T *inst_ptr(handle h) { return (T *) detail::nb_inst_ptr(h.ptr()); }
278278
inline void *type_get_slot(handle h, int slot_id) {
279-
#if PY_VERSION_HEX < 0x030A0000
279+
#if NB_TYPE_GET_SLOT_IMPL
280280
return detail::type_get_slot((PyTypeObject *) h.ptr(), slot_id);
281281
#else
282282
return PyType_GetSlot((PyTypeObject *) h.ptr(), slot_id);

include/nanobind/nb_defs.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@
139139
# define NB_DOMAIN_STR nullptr
140140
#endif
141141

142+
#if !defined(PYPY_VERSION)
143+
# if PY_VERSION_HEX < 0x030A0000
144+
# define NB_TYPE_GET_SLOT_IMPL 1 // Custom implementation of nb::type_get_slot
145+
# else
146+
# define NB_TYPE_GET_SLOT_IMPL 0
147+
# endif
148+
# if PY_VERSION_HEX < 0x030C0000
149+
# define NB_TYPE_FROM_METACLASS_IMPL 1 // Custom implementation of PyType_FromMetaclass
150+
# else
151+
# define NB_TYPE_FROM_METACLASS_IMPL 0
152+
# endif
153+
#else
154+
# define NB_TYPE_FROM_METACLASS_IMPL 1
155+
# define NB_TYPE_GET_SLOT_IMPL 1
156+
#endif
157+
142158
#define NB_MODULE_IMPL(name) \
143159
extern "C" [[maybe_unused]] NB_EXPORT PyObject *PyInit_##name(); \
144160
extern "C" NB_EXPORT PyObject *PyInit_##name()

include/nanobind/nb_lib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ NB_CORE void slice_compute(PyObject *slice, Py_ssize_t size,
498498
NB_CORE PyObject *repr_list(PyObject *o);
499499
NB_CORE PyObject *repr_map(PyObject *o);
500500

501-
#if PY_VERSION_HEX < 0x030A0000
501+
#if NB_TYPE_GET_SLOT_IMPL
502502
NB_CORE void *type_get_slot(PyTypeObject *t, int slot_id);
503503
#endif
504504

src/nb_type.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ static int nb_type_setattro(PyObject* obj, PyObject* name, PyObject* value) {
385385
return NB_SLOT(PyType_Type, tp_setattro)(obj, name, value);
386386
}
387387

388-
#if PY_VERSION_HEX < 0x030C0000
388+
#if NB_TYPE_FROM_METACLASS_IMPL || NB_TYPE_GET_SLOT_IMPL
389389

390390
struct nb_slot {
391-
#if PY_VERSION_HEX < 0x030A0000
391+
#if NB_TYPE_GET_SLOT_IMPL
392392
uint8_t indirect_1;
393393
uint8_t indirect_2;
394394
#endif
@@ -400,7 +400,7 @@ template <size_t I1, size_t I2, size_t Offset1, size_t Offset2> nb_slot constexp
400400
static_assert(I1 == I2 && (Offset1 % sizeof(void *)) == 0 && (Offset2 % sizeof(void *)) == 0,
401401
"nb_slot construction: internal error");
402402

403-
#if PY_VERSION_HEX < 0x030A0000
403+
#if NB_TYPE_GET_SLOT_IMPL
404404
size_t o = 0;
405405
switch (Offset1) {
406406
case offsetof(PyHeapTypeObject, as_async): o = offsetof(PyTypeObject, tp_as_async); break;
@@ -518,7 +518,7 @@ static constexpr nb_slot type_slots[] {
518518
#endif
519519
};
520520

521-
#if PY_VERSION_HEX < 0x030A0000
521+
#if NB_TYPE_GET_SLOT_IMPL
522522
void *type_get_slot(PyTypeObject *t, int slot_id) {
523523
nb_slot slot = type_slots[slot_id - 1];
524524

@@ -537,7 +537,7 @@ void *type_get_slot(PyTypeObject *t, int slot_id) {
537537

538538
static PyObject *nb_type_from_metaclass(PyTypeObject *meta, PyObject *mod,
539539
PyType_Spec *spec) {
540-
#if PY_VERSION_HEX >= 0x030C0000
540+
#if NB_TYPE_FROM_METACLASS_IMPL == 0
541541
// Life is good, PyType_FromMetaclass() is available
542542
return PyType_FromMetaclass(meta, mod, spec, nullptr);
543543
#else

0 commit comments

Comments
 (0)