Skip to content

Commit 77f910f

Browse files
committed
Detect use of type vectorcall slot and use fallback implementation
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.
1 parent bceec36 commit 77f910f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/nb_type.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# pragma warning(disable: 4706) // assignment within conditional expression
1414
#endif
1515

16-
// #if !defined(Py_tp_vectorcall)
17-
// # define Py_tp_vectorcall 82
18-
// #endif
16+
#if !defined(Py_tp_vectorcall)
17+
# define Py_tp_vectorcall 82
18+
#endif
1919

2020
NAMESPACE_BEGIN(NB_NAMESPACE)
2121
NAMESPACE_BEGIN(detail)
@@ -1118,11 +1118,11 @@ PyObject *nb_type_new(const type_init_data *t) noexcept {
11181118
has_custom_init_or_new |=
11191119
slot_id == Py_tp_init || slot_id == Py_tp_new;
11201120

1121-
// if (slot_id == Py_tp_vectorcall) {
1122-
// type_vectorcall = (vectorcallfunc) ts.pfunc;
1123-
// has_custom_type_vectorcall = true;
1124-
// continue;
1125-
// }
1121+
if (slot_id == Py_tp_vectorcall) {
1122+
type_vectorcall = (vectorcallfunc) ts.pfunc;
1123+
has_custom_type_vectorcall = true;
1124+
continue;
1125+
}
11261126

11271127
*s++ = ts;
11281128
}

0 commit comments

Comments
 (0)