STINNER Victor added the comment:

> __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.

----------
nosy: +haypo

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26423>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to