Message260773
> __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. |
|
Date |
User |
Action |
Args |
2016-02-24 09:04:55 | vstinner | set | recipients:
+ vstinner, georg.brandl, paul.moore, mark.dickinson, tim.golden, zach.ware, steve.dower, RazerM, Dave Hibbitts |
2016-02-24 09:04:55 | vstinner | set | messageid: <1456304695.66.0.48837009637.issue26423@psf.upfronthosting.co.za> |
2016-02-24 09:04:55 | vstinner | link | issue26423 messages |
2016-02-24 09:04:54 | vstinner | create | |
|