This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PY_SSIZE_T_MAX is not an integer constant expression
Type: enhancement Stage:
Components: C API Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ov2k
Priority: normal Keywords:

Created on 2022-02-06 21:20 by ov2k, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg412670 - (view) Author: (ov2k) Date: 2022-02-06 21:20
PY_SSIZE_T_MAX is currently defined in Include/pyport.h as: 

#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))

This is not an integer constant expression, which means it can't be used in preprocessor conditionals.  For example: 

#if PY_SSIZE_T_MAX > UINT32_MAX

will fail to compile.  This was touched upon and ignored a long time ago: 

https://mail.python.org/archives/list/python-dev@python.org/thread/27X7LINL4UO7DAJE6J3IFQEZGUKAO4VL/

I think the best fix is to move the definition of PY_SSIZE_T_MAX (and PY_SSIZE_T_MIN) next to the definition of Py_ssize_t, and use the proper corresponding limit macro.  If Py_ssize_t is a typedef for ssize_t, then PY_SSIZE_T_MAX should be SSIZE_MAX.  If Py_ssize_t is a typedef for Py_intptr_t, then PY_SSIZE_T_MAX should be INTPTR_MAX.  There's a minor complication because Py_ssize_t can be defined in PC/pyconfig.h.  I'm not so familiar with the various Windows compilers, so I'm not sure what's best to do here.  I think __int64 has a corresponding _I64_MAX macro, and int obviously has INT_MAX.
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90822
2022-02-06 21:37:17ov2ksettype: compile error -> enhancement
2022-02-06 21:20:42ov2kcreate