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: Fix usage of Py_ssize_t type in Python/compile.c
Type: Stage:
Components: Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2013-11-15 23:08 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
compile_ssize_t.patch vstinner, 2013-11-15 23:08
Messages (8)
msg202976 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-15 23:08
On Windows 64-bit, Visual Studio generates a lot of warnings because Py_ssize_t values are downcasted to int.

Attached patch fixes all warnings and move the final downcast into compiler_addop_i(). This function uses an assertion to check that integer parameter fits into an C int type. I don't know if it's safe to "return 0" on overflow error.

The patch fixes also some indentation issues seen was I wrote the patch.

Nobody complained before, I don't know if the bugs can be seen in practice, so I prefer to not touch Python 2.7 nor 3.2.
msg202982 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2013-11-15 23:59
You could use the Py_SAFE_DOWNCAST macro everywhere.
msg203263 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-18 09:14
> You could use the Py_SAFE_DOWNCAST macro everywhere.

I prefer to store sizes in a size type (Py_ssize_t), and only downcast where it is really needed, in compiler_addop_i(). So in the future, if someone wants to support values larger than INT_MAX, only one function need to be changed.
msg203292 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2013-11-18 13:18
I meant where you added casts, you could use it.

2013/11/18 STINNER Victor <report@bugs.python.org>:
>
> STINNER Victor added the comment:
>
>> You could use the Py_SAFE_DOWNCAST macro everywhere.
>
> I prefer to store sizes in a size type (Py_ssize_t), and only downcast where it is really needed, in compiler_addop_i(). So in the future, if someone wants to support values larger than INT_MAX, only one function need to be changed.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue19617>
> _______________________________________
msg203425 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-19 21:24
Oops, I forgot to mention this issue number in the commit:
---
changeset:   87277:68fd86a83ece
tag:         tip
user:        Victor Stinner <victor.stinner@gmail.com>
date:        Tue Nov 19 22:23:20 2013 +0100
files:       Python/compile.c
description:
Issue #9566: compile.c uses Py_ssize_t instead of int to store sizes to fix
compiler warnings on Windows 64-bit. Use Py_SAFE_DOWNCAST() where the final
downcast is needed.

The bytecode doesn't support integer parameters larger than 32-bit yet.
---

I added some more Py_SAFE_DOWNCAST() in the final commit.
msg203427 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-19 21:28
New changeset 8d3e85dfa46f by Victor Stinner in branch 'default':
Issue #9566, #19617: Fix compilation on Windows
http://hg.python.org/cpython/rev/8d3e85dfa46f
msg203433 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-19 22:03
New changeset ee4da7291211 by Victor Stinner in branch 'default':
Issue #9566, #19617: New try to fix compilation on Windows
http://hg.python.org/cpython/rev/ee4da7291211
msg203441 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-19 22:56
New changeset 116bd550e309 by Victor Stinner in branch 'default':
Issue #9566, #19617: Fix more compiler warnings in compile.c on Windows 64-bit
http://hg.python.org/cpython/rev/116bd550e309
History
Date User Action Args
2022-04-11 14:57:53adminsetgithub: 63816
2013-11-19 22:56:55python-devsetmessages: + msg203441
2013-11-19 22:03:46python-devsetmessages: + msg203433
2013-11-19 21:28:14python-devsetnosy: + python-dev
messages: + msg203427
2013-11-19 21:24:37vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg203425
2013-11-18 13:18:31benjamin.petersonsetmessages: + msg203292
2013-11-18 09:14:15vstinnersetmessages: + msg203263
2013-11-15 23:59:05benjamin.petersonsetmessages: + msg202982
2013-11-15 23:08:07vstinnercreate