C basetype mapping protocol difference between 2.2.1 and 2.3
I am trying to accelerate Numarray by "dropping the bottom out" and re-writing the simplest, most used portions in a C basetype. Looking at a new NumArray instance in Python-2.2.1 under GDB, I see: (gdb) p *self->ob_type->tp_as_mapping $2 = {mp_length = 0x4006eb7c <_ndarray_length>, mp_subscript = 0x80669b8 <slot_mp_subscript>, mp_ass_subscript = 0x80669e0 <slot_mp_ass_subscript>} Looking at the same code compiled for Python-2.3, _ndarray "owns" all of the mapping protocol slots, which is what I really want to happen: (gdb) p *o->ob_type->tp_as_mapping $1 = {mp_length = 0x400c1a68 <_ndarray_length>, mp_subscript = 0x400c1a80 <_ndarray_subscript>, mp_ass_subscript = 0x400c1188 <_ndarray_ass_subscript>} Did anything change between Python-2.2.1 and Python-2.3 that would account for this? Todd -- Todd Miller jmiller@stsci.edu STSCI / SSG
(gdb) p *self->ob_type->tp_as_mapping $2 = {mp_length = 0x4006eb7c <_ndarray_length>, mp_subscript = 0x80669b8 <slot_mp_subscript>, mp_ass_subscript = 0x80669e0 <slot_mp_ass_subscript>}
Looking at the same code compiled for Python-2.3, _ndarray "owns" all of the mapping protocol slots, which is what I really want to happen:
(gdb) p *o->ob_type->tp_as_mapping $1 = {mp_length = 0x400c1a68 <_ndarray_length>, mp_subscript = 0x400c1a80 <_ndarray_subscript>, mp_ass_subscript = 0x400c1188 <_ndarray_ass_subscript>}
Did anything change between Python-2.2.1 and Python-2.3 that would account for this?
Yes, I did several massive refactorings of a lot of very subtle code in typeobject.c. Note that this is only a performance improvement, not a semantic change: slot_mp_subscript will look for and call the __setitem__ descriptor in the type dict, which will be a Python wrapper around _ndarray_subscript. The new code notices that this is so and leaves _ndarray_subscript in the slot. I wish it was easy to backport this to 2.2.2, but it's not. :-( --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (2)
-
Guido van Rossum
-
Todd Miller