bpo-34229: Check start and stop of slice object to be long when they are not int in PySlice_GetIndices (GH-8480)

diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index f57176d..67488e7 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1560,6 +1560,29 @@
 }
 
 static PyObject *
+get_indices(PyObject *self, PyObject *args)
+{
+    int result;
+    PySliceObject *slice;
+    Py_ssize_t length, start, stop, step;
+
+    if (!PyArg_ParseTuple(args, "On", &slice, &length))
+        return NULL;
+
+    result = PySlice_GetIndices(slice, length, &start, &stop, &step);
+
+    if (PyErr_Occurred()) {
+        assert(result == -1);
+        return NULL;
+    }
+
+    if (result == -1) {
+        Py_RETURN_NONE;
+    }
+    return Py_BuildValue("innn", result, start, stop, step);
+}
+
+static PyObject *
 parse_tuple_and_keywords(PyObject *self, PyObject *args)
 {
     PyObject *sub_args;
@@ -2664,6 +2687,7 @@
 #ifdef Py_USING_UNICODE
     {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS},
 #endif
+    {"get_indices", get_indices, METH_VARARGS},
     {"parse_tuple_and_keywords", parse_tuple_and_keywords, METH_VARARGS},
     {"test_null_strings",       (PyCFunction)test_null_strings,  METH_NOARGS},
     {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS},