[Python-Dev] 2.5, 64 bit

"Martin v. Löwis" martin at v.loewis.de
Mon Oct 9 19:53:23 CEST 2006

Kristján V. Jónsson schrieb:
> the VisualStudio8 64 bit build of 2.5 doesn't compile clean.  We have a
> number of warnings of truncation from 64 bit to 32:
> Often it is a question of doing an explicit cast, but sometimes we are
> using "int" for results from strlen and such.
> Is there any interest in fixing this up?

Yes; I had fixed many of them already for the Python 2.5 release (there
were *way* more of these before I started).

Notice that many of them are bogus. For example, if I do strlen on a
buffer that is known to have MAXPATH bytes, the strlen result *can't*
exceed an int. So care is necessary for each case:
- if there is a conceivable case where it can overflow (i.e. if
  you could come up with a Python program that makes it overflow),
  fix the types appropriately
- if it is certain through inspection that it can't overflow, add
  a cast (Py_SAFE_DOWNCAST, or, when it is really obvious, a plain
  cast), and a comment on why the cast is correct. Notice that
  Py_SAFE_DOWNCAST has an assertion in debug mode. Also notice
  that it evaluates it argument twice.
- if it shouldn't overflow as long as extension modules play by
  the rules, it's your choice of either adding a runtime error,
  or just widening the representation.

IIRC, the biggest chunk of "real" work left is SRE: this can
realistically overflow when it operates on large strings. You
have to really understand SRE before fixing it. For example,
I believe that large strings might have impacts on compilation,
too (e.g. if the regex itself is >2GiB, or some repetition
count is >2**31). In these cases, it might be saner to guarantee
an exception (and document the limitation) than to try expanding
the SRE bytecode.

Another set of remaining changes deals with limitations on
byte code and reflection. For example, there is currently
a limit on the number of local variables imposed by the Python
bytecode. From this limit, it follows that certain casts are
correct. One should document each limit first, and then
refer to these limits when adding casts.

Helping here would be definitely appreciated.


More information about the Python-Dev mailing list