[Patches] simple 64-bit fixes in Objects/ dir
M.-A. Lemburg
mal@lemburg.com
Tue, 06 Jun 2000 00:56:37 +0200
> This patch makes some simple changes for the benefit of 64-bit platforms (to
> avoid possible overflows where C data types have changed sizes and to
> eliminate unnecessary warnings). Each change fits into one of the following
> categories:
>
> - Change a local variable declaration from int to size_t where appropriate.
> This is typically done for variables that hold strlen() or sizeof()
> results. On 64-bit platforms sizeof(int) < sizeof(size_t), so using size_t
> avoids a downcast warning (or overflow). The variable is often later
> downcast to an int anyway but it is (IMO) more appropriate to do the
> downcast where the downcast is necessary and not before. 32-bit platforms
> are not affected by this change.
> - Change (int) casts to (size_t) casts within comparisons where appropriate.
> This can avoid an unnecessary possible overflow (in somecases) and a
> warning on 64-bit platforms.
> - Remove pointer downcasts to (long) for comparison (see Objects/object.c).
> This is unreliable on Win64 where sizeof(void*) > sizeof(long).
> - Add a check for int overflow and raise and OverflowError where it cannot be
> proven a priori that int will not overflow. This is usually associated with
> string lengths. While it may seem overkill to have a check to ensure that a
> string does not overflow 2G characters it *is* a potential for silent
> overflow.
> - [Python/thread_nt.c] Use %p instead of %ld printf formatter for debugging
> output to print a pointer. %ld results in data loss on Win64.
Trent,
do you have some kind of web page on this ? I think it would
be useful for extension package writers to have such a list
of things to watch out for handy -- I do for sure, as I'm
very keen on getting my mx Extensions to work on 64-bit
platforms too.
If it's not a web-page, a flat file for Misc/ would be
fine as well -- something like Misc/porting-to-64bit.txt
Thanks,
--
Marc-Andre Lemburg
______________________________________________________________________
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/