summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGanesh Kathiresan <ganesh3597@gmail.com>2022-05-02 08:23:28 (GMT)
committerGitHub <noreply@github.com>2022-05-02 08:23:28 (GMT)
commitd414f7ece8169097a32cd228bb32da0418833db4 (patch)
treea209b1fcc55070c8e6df71c65cf0ee42f625df91
parent4d10f703d79b72a9c7f88862c0b4a9abbfb04ee2 (diff)
downloadcpython-d414f7ece8169097a32cd228bb32da0418833db4.zip
cpython-d414f7ece8169097a32cd228bb32da0418833db4.tar.gz
cpython-d414f7ece8169097a32cd228bb32da0418833db4.tar.bz2
gh-90822: Make `PY_SSIZE_T_MAX` and `PY_SSIZE_T_MIN` constant expression (GH-92071)
-rw-r--r--Include/pyport.h11
-rw-r--r--PC/pyconfig.h2
2 files changed, 8 insertions, 5 deletions
diff --git a/Include/pyport.h b/Include/pyport.h
index 5102f74..9238973 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -114,17 +114,23 @@ typedef intptr_t Py_intptr_t;
/* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
* sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
* unsigned integral type). See PEP 353 for details.
+ * PY_SSIZE_T_MAX is the largest positive value of type Py_ssize_t.
*/
#ifdef HAVE_PY_SSIZE_T
#elif HAVE_SSIZE_T
typedef ssize_t Py_ssize_t;
+# define PY_SSIZE_T_MAX SSIZE_MAX
#elif SIZEOF_VOID_P == SIZEOF_SIZE_T
typedef Py_intptr_t Py_ssize_t;
+# define PY_SSIZE_T_MAX INTPTR_MAX
#else
# error "Python needs a typedef for Py_ssize_t in pyport.h."
#endif
+/* Smallest negative value of type Py_ssize_t. */
+#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
+
/* Py_hash_t is the same size as a pointer. */
#define SIZEOF_PY_HASH_T SIZEOF_SIZE_T
typedef Py_ssize_t Py_hash_t;
@@ -138,11 +144,6 @@ typedef Py_ssize_t Py_ssize_clean_t;
/* Largest possible value of size_t. */
#define PY_SIZE_MAX SIZE_MAX
-/* Largest positive value of type Py_ssize_t. */
-#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
-/* Smallest negative value of type Py_ssize_t. */
-#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
-
/* Macro kept for backward compatibility: use "z" in new code.
*
* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
diff --git a/PC/pyconfig.h b/PC/pyconfig.h
index e8649be..5a96a4e 100644
--- a/PC/pyconfig.h
+++ b/PC/pyconfig.h
@@ -162,8 +162,10 @@ WIN32 is still required for the locale module.
/* Define like size_t, omitting the "unsigned" */
#ifdef MS_WIN64
typedef __int64 Py_ssize_t;
+# define PY_SSIZE_T_MAX LLONG_MAX
#else
typedef _W64 int Py_ssize_t;
+# define PY_SSIZE_T_MAX INT_MAX
#endif
#define HAVE_PY_SSIZE_T 1