Skip to content

Commit

Permalink
Detect use of type vectorcall slot and use fallback implementation
Browse files Browse the repository at this point in the history
Following the merge of python/cpython#123332,
type slot 82 is reserved for type vector calls. This means that we can
safely intercept this value if provided to nanobind even on older
versions of Python where the feature isn't supported yet. In this case,
the metaclass-based implementation is used.
  • Loading branch information
wjakob committed Sep 14, 2024
1 parent bceec36 commit 77f910f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/nb_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# pragma warning(disable: 4706) // assignment within conditional expression
#endif

// #if !defined(Py_tp_vectorcall)
// # define Py_tp_vectorcall 82
// #endif
#if !defined(Py_tp_vectorcall)
# define Py_tp_vectorcall 82
#endif

NAMESPACE_BEGIN(NB_NAMESPACE)
NAMESPACE_BEGIN(detail)
Expand Down Expand Up @@ -1118,11 +1118,11 @@ PyObject *nb_type_new(const type_init_data *t) noexcept {
has_custom_init_or_new |=
slot_id == Py_tp_init || slot_id == Py_tp_new;

// if (slot_id == Py_tp_vectorcall) {
// type_vectorcall = (vectorcallfunc) ts.pfunc;
// has_custom_type_vectorcall = true;
// continue;
// }
if (slot_id == Py_tp_vectorcall) {
type_vectorcall = (vectorcallfunc) ts.pfunc;
has_custom_type_vectorcall = true;
continue;
}

*s++ = ts;
}
Expand Down

0 comments on commit 77f910f

Please sign in to comment.