Skip to content

Commit

Permalink
nb_type_new(): adaption for older Python versions, follow ``tp_traver…
Browse files Browse the repository at this point in the history
…se`` recommendations in test suite
  • Loading branch information
wjakob committed Sep 8, 2024
1 parent b2bed68 commit 87711b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/nb_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,9 @@ PyObject *nb_type_new(const type_init_data *t) noexcept {
*s++ = { Py_tp_members, (void*) members };

#if PY_VERSION_HEX < 0x03090000
(void) is_generic; // unsupported on Python 3.8
// Features that are unsupported in Python 3.8
(void) is_generic;
type_vectorcall = nullptr;
#else
if (is_generic)
*s++ = { Py_tp_methods, (void*) class_getitem_method };
Expand Down
4 changes: 4 additions & 0 deletions tests/test_stl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ int funcwrapper_tp_traverse(PyObject *self, visitproc visit, void *arg) {
nb::object f = nb::cast(w->f, nb::rv_policy::none);
Py_VISIT(f.ptr());

#if PY_VERSION_HEX >= 0x03090000
Py_VISIT(Py_TYPE(self));
#endif

return 0;
}

Expand Down

0 comments on commit 87711b0

Please sign in to comment.