Author vstinner
Recipients Dave Hibbitts, RazerM, georg.brandl, mark.dickinson, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Date 2016-02-24.09:04:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1456304695.66.0.48837009637.issue26423@psf.upfronthosting.co.za>
In-reply-to
Content
> __len__() always returns an int which on windows machines is tied to the size of a c long and is always 32 bits even if it's compiled for 64 bit.

Hum, I don't understand this statement. It looks like the code uses Py_ssize_t everywhere and Py_ssize_t is supposed to be able to store a whole pointer, so be 64-bit when Python is compiled in 64-bit mode.

> Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Jul  2 2014, 15:12:11) [MSC v.1500 64 bit (AMD64)] on win32

This is a 32-bit build ("win32"), no? max.size is 2147483647 on 32-bit mode if I recall correctly. On 64-bit, it's 9223372036854775807. By the way, on 64-bit, sys.maxsize == sys.maxint.


In Python 2:

len(obj) => builtin_len() => PyObject_Size() which returns a Py_ssize_t

For string, PyObject_Size() => string_length() => Py_SIZE(obj) => ((PyVarObject *)obj)->ob_size

PyVarObject.ob_size has the type Py_ssize_t.

builtin_len() gets a Py_ssize_t which is converted to a Python int or long with PyInt_FromSsize_t().

PyInt_FromSsize_t() creates an int if the value fits into a C long, or it calls _PyLong_FromSsize_t().


Difference in Python 3:

builtin_len() also gets a Py_ssize_t, but it calls PyLong_FromSsize_t() (since Python short integers as gone, long became int in Python 3).

string_length() is replaced with unicode_length() => PyUnicode_GET_LENGTH() => (PyASCIIObject *)obj)->length and PyASCIIObject.length type is Py_ssize_t.
History
Date User Action Args
2016-02-24 09:04:55vstinnersetrecipients: + vstinner, georg.brandl, paul.moore, mark.dickinson, tim.golden, zach.ware, steve.dower, RazerM, Dave Hibbitts
2016-02-24 09:04:55vstinnersetmessageid: <1456304695.66.0.48837009637.issue26423@psf.upfronthosting.co.za>
2016-02-24 09:04:55vstinnerlinkissue26423 messages
2016-02-24 09:04:54vstinnercreate