You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix usage of Py_ssize_t type in Python/compile.c #63816
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=Noneclosed_at=<Date2013-11-19.21:24:37.918>created_at=<Date2013-11-15.23:08:07.747>labels= []
title='Fix usage of Py_ssize_t type in Python/compile.c'updated_at=<Date2013-11-19.22:56:55.865>user='https://github.com/vstinner'
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.
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.
> 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.
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 bpo-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.
Activity
vstinner commentedon Nov 15, 2013
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.
benjaminp commentedon Nov 15, 2013
You could use the Py_SAFE_DOWNCAST macro everywhere.
vstinner commentedon Nov 18, 2013
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.
benjaminp commentedon Nov 18, 2013
I meant where you added casts, you could use it.
2013/11/18 STINNER Victor <report@bugs.python.org>:
vstinner commentedon Nov 19, 2013
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 bpo-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.
python-dev commentedon Nov 19, 2013
New changeset 8d3e85dfa46f by Victor Stinner in branch 'default':
Issue bpo-9566, bpo-19617: Fix compilation on Windows
http://hg.python.org/cpython/rev/8d3e85dfa46f
python-dev commentedon Nov 19, 2013
New changeset ee4da7291211 by Victor Stinner in branch 'default':
Issue bpo-9566, bpo-19617: New try to fix compilation on Windows
http://hg.python.org/cpython/rev/ee4da7291211
python-dev commentedon Nov 19, 2013
New changeset 116bd550e309 by Victor Stinner in branch 'default':
Issue bpo-9566, bpo-19617: Fix more compiler warnings in compile.c on Windows 64-bit
http://hg.python.org/cpython/rev/116bd550e309