From 527c01ff18d06e5d83462a54ef28c0852b833fc5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 8 Apr 2017 12:23:59 +0300 Subject: [PATCH 1/3] bpo-29943: Do not replace the function PySlice_GetIndicesEx() with a macro if Py_LIMITED_API is not defined. --- Include/sliceobject.h | 2 +- Misc/NEWS | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Include/sliceobject.h b/Include/sliceobject.h index 36263544607096..0ffae10d4b6072 100644 --- a/Include/sliceobject.h +++ b/Include/sliceobject.h @@ -44,7 +44,7 @@ PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength); -#if !defined(Py_LIMITED_API) || (Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100 +#if (Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100 #define PySlice_GetIndicesEx(slice, length, start, stop, step, slicelen) ( \ PySlice_Unpack((slice), (start), (stop), (step)) < 0 ? \ ((*(slicelen) = 0), -1) : \ diff --git a/Misc/NEWS b/Misc/NEWS index 49926830dcb3a6..7f78338e326ced 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -151,8 +151,8 @@ C API ----- - Issue #27867: Function PySlice_GetIndicesEx() is replaced with a macro if - Py_LIMITED_API is not set or set to the value between 0x03050400 - and 0x03060000 (not including) or 0x03060100 or higher. + Py_LIMITED_API is set to the value between 0x03050400 and 0x03060000 (not + including) or 0x03060100 or higher. - Issue #29083: Fixed the declaration of some public API functions. PyArg_VaParse() and PyArg_VaParseTupleAndKeywords() were not available in From dd92050fd78cec991fc740469b7a49f7decda47f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 16 Apr 2017 10:12:29 +0300 Subject: [PATCH 2/3] Check the value of Py_LIMITED_API only if it is defined. --- Include/sliceobject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/sliceobject.h b/Include/sliceobject.h index 0ffae10d4b6072..599e5f9175c2ea 100644 --- a/Include/sliceobject.h +++ b/Include/sliceobject.h @@ -44,7 +44,7 @@ PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength); -#if (Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100 +#if defined(Py_LIMITED_API) && ((Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100) #define PySlice_GetIndicesEx(slice, length, start, stop, step, slicelen) ( \ PySlice_Unpack((slice), (start), (stop), (step)) < 0 ? \ ((*(slicelen) = 0), -1) : \ From c86640508c957913b3c504e5317ca84c38fe034f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 16 Apr 2017 10:41:48 +0300 Subject: [PATCH 3/3] But PySlice_Unpack and PySlice_AdjustIndices should be defined. --- Include/sliceobject.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Include/sliceobject.h b/Include/sliceobject.h index 599e5f9175c2ea..579ac073d0f241 100644 --- a/Include/sliceobject.h +++ b/Include/sliceobject.h @@ -44,12 +44,14 @@ PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength); -#if defined(Py_LIMITED_API) && ((Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100) +#if !defined(Py_LIMITED_API) || (Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100 +#ifdef Py_LIMITED_API #define PySlice_GetIndicesEx(slice, length, start, stop, step, slicelen) ( \ PySlice_Unpack((slice), (start), (stop), (step)) < 0 ? \ ((*(slicelen) = 0), -1) : \ ((*(slicelen) = PySlice_AdjustIndices((length), (start), (stop), *(step))), \ 0)) +#endif PyAPI_FUNC(int) PySlice_Unpack(PyObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step); PyAPI_FUNC(Py_ssize_t) PySlice_AdjustIndices(Py_ssize_t length,