[Python-Dev] A cast from Py_ssize_t to long (original) (raw)
Thomas Wouters thomas at python.org
Mon Aug 21 13:23:46 CEST 2006
- Previous message: [Python-Dev] A cast from Py_ssize_t to long
- Next message: [Python-Dev] A cast from Py_ssize_t to long
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 8/21/06, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:
On Aug 15, 2006, at 3:16 AM, Martin v. Löwis wrote: > > Where does it assume that it is safe to case ssizet -> long? > That would be a bug. Is this a bug? filereadinto(PyFileObject *f, PyObject *args) { ... Pyssizet ndone, nnow; ... return PyIntFromLong((long)ndone); } See Objects/fileobject.c (revision 51420).
Yes. Py_ssize_t can be bigger than a long (on LLP64 systems, such as Win64). It doesn't matter on other systems, and you have to read more than 31 bits worth of data to detect it even on Win64, but it's still a bug. file_readinto should be using PyInt_FromSsize_t() instead. (There is the SAFE_DOWNCAST macro for cases where we know the value of the (s)size_t will always fit in a long, on any supported system, but that isn't the case here.)
-- Thomas Wouters <thomas at python.org>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-dev/attachments/20060821/4e09574e/attachment.htm
- Previous message: [Python-Dev] A cast from Py_ssize_t to long
- Next message: [Python-Dev] A cast from Py_ssize_t to long
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]