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: simple 64-bit fixes in Python/ dir
Type: Stage:
Components: None Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: gvanrossum, tim.peters, tmick
Priority: normal Keywords: patch

Created on 2000-06-07 03:44 by tmick, last changed 2022-04-10 16:02 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
None tmick, 2000-06-07 03:44 None
Messages (6)
msg32783 - (view) Author: Trent Mick (tmick) (Python triager) Date: 2000-06-07 03:44
 
msg32784 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2000-06-27 15:11
Tim, please review the Win specific changes. You can pass the rest on to me.
msg32785 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2000-06-28 06:46
Guido, as requested, passing back to you, but note that there really isn't anything Win-specific here:  Trent's changes here have to do with that strlen doesn't return an int, it returns a size_t, and that's been true since ANSI C.  He's just worming around int-vs-size_t mismatches in the code (which happen to *matter* in Win64).
I would accept this.
msg32786 - (view) Author: Trent Mick (tmick) (Python triager) Date: 2000-06-07 03:46
I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.
msg32787 - (view) Author: Trent Mick (tmick) (Python triager) Date: 2000-06-07 03:46
This patch is one of a set of five (one per python/dist/src/* directory).
They have been broken up to keep the patches small such that people might
spend the time to review them. If one single patch would be prefered I can
provide that.

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.
msg32788 - (view) Author: Trent Mick (tmick) (Python triager) Date: 2000-06-07 04:03
[Tim Peters]
> [Trent Mick]
> > ...
> > On 64-bit platforms sizeof(int) < sizeof(size_t), so
> > using size_t avoids a downcast warning (or overflow).
>
> I suppose we should be more careful about explaining the need for these
> changes.  For example, the claim above isn't true, as there are 64-bit
> platforms where sizeof(int) == sizeof(size_t) too (the Cray J90 is one such
> platform Python kind of <wink> runs on today, and indeed even shorts are 64
> bits on that one).
>
> The problems here are that Python implicitly assumes sizeof(int) ==
> sizeof(size_t), because at the time Python was written size_t didn't exist
> and the long K&R tradition preceding ANSI C was that strlen returned an
> int-sized thing and malloc took one.  So they're all in the nature of
> cleaning up after the C committee a decade later <wink>.
History
Date User Action Args
2022-04-10 16:02:01adminsetgithub: 32446
2000-06-07 03:44:49tmickcreate