Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PY_SSIZE_T_MAX is not an integer constant expression #90822

Closed
ov2k mannequin opened this issue Feb 6, 2022 · 1 comment · Fixed by #92071
Closed

PY_SSIZE_T_MAX is not an integer constant expression #90822

ov2k mannequin opened this issue Feb 6, 2022 · 1 comment · Fixed by #92071
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-C-API type-feature A feature request or enhancement

Comments

@ov2k
Copy link
Mannequin

ov2k mannequin commented Feb 6, 2022

BPO 46664

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2022-02-06.21:20:42.705>
labels = ['3.7', '3.8', '3.9', '3.10', '3.11', 'expert-C-API', 'type-feature']
title = 'PY_SSIZE_T_MAX is not an integer constant expression'
updated_at = <Date 2022-02-06.21:37:17.876>
user = 'https://bugs.python.org/ov2k'

bugs.python.org fields:

activity = <Date 2022-02-06.21:37:17.876>
actor = 'ov2k'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['C API']
creation = <Date 2022-02-06.21:20:42.705>
creator = 'ov2k'
dependencies = []
files = []
hgrepos = []
issue_num = 46664
keywords = []
message_count = 1.0
messages = ['412670']
nosy_count = 1.0
nosy_names = ['ov2k']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46664'
versions = ['Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

@ov2k
Copy link
Mannequin Author

ov2k mannequin commented Feb 6, 2022

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.

@ov2k ov2k mannequin added build The build process and cross-build 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-C-API type-feature A feature request or enhancement and removed build The build process and cross-build labels Feb 6, 2022
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
ganesh-k13 added a commit to ganesh-k13/cpython that referenced this issue May 2, 2022
* `PY_SSIZE_T_MAX` and `PY_SSIZE_T_MAX` could not be used with #defines
* Now it makes use of in-built macros to help with that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

0 participants