extern "C" PyObject* PyTuple_GetItem(PyObject* op, Py_ssize_t i) noexcept { RELEASE_ASSERT(PyTuple_Check(op), ""); RELEASE_ASSERT(i >= 0, ""); // unlike tuple.__getitem__, PyTuple_GetItem doesn't do index wrapping try { return tupleGetitemUnboxed(static_cast<BoxedTuple*>(op), i); } catch (ExcInfo e) { abort(); } }
Box* tupleGetitem(BoxedTuple* self, Box* slice) { assert(self->cls == tuple_cls); if (PyIndex_Check(slice)) { Py_ssize_t i = PyNumber_AsSsize_t(slice, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) throwCAPIException(); return tupleGetitemUnboxed(self, i); } else if (slice->cls == slice_cls) return tupleGetitemSlice(self, static_cast<BoxedSlice*>(slice)); else raiseExcHelper(TypeError, "tuple indices must be integers, not %s", getTypeName(slice)); }
template <ExceptionStyle S> Box* tupleGetitem(BoxedTuple* self, Box* slice) { if (S == CAPI) { try { return tupleGetitem<CXX>(self, slice); } catch (ExcInfo e) { setCAPIException(e); return NULL; } } assert(isSubclass(self->cls, tuple_cls)); if (PyIndex_Check(slice)) { Py_ssize_t i = PyNumber_AsSsize_t(slice, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) throwCAPIException(); return tupleGetitemUnboxed(self, i); } else if (slice->cls == slice_cls) return tupleGetitemSlice(self, static_cast<BoxedSlice*>(slice)); else raiseExcHelper(TypeError, "tuple indices must be integers, not %s", getTypeName(slice)); }
Box* tupleGetitemInt(BoxedTuple* self, BoxedInt* slice) { return tupleGetitemUnboxed(self, slice->n); }