diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp
index 233ea32aebc237b837cdee7fb3e5c986e364059f..a33adc9803239a9a91169faba05f69c12a1fb4b7 100644
--- a/src/wrapper/wrap_cl.hpp
+++ b/src/wrapper/wrap_cl.hpp
@@ -1188,7 +1188,11 @@ namespace pyopencl
         PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
             (data(), CL_MEM_SIZE, sizeof(my_length), &my_length, 0));
 
+#if PY_VERSION_HEX >= 0x03020000
+        if (PySlice_GetIndicesEx(slc.ptr(),
+#else
         if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject *>(slc.ptr()),
+#endif
               my_length, &start, &end, &stride, &length) != 0)
           throw py::error_already_set();