[Patches] [ python-Patches-423262 ] Change module attribute get & set

noreply@sourceforge.net noreply@sourceforge.net
Fri, 11 May 2001 14:30:53 -0700


Patches item #423262, was updated on 2001-05-11 02:11
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=423262&group_id=5470

Category: core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Tim Peters (tim_one)
>Assigned to: Tim Peters (tim_one)
Summary: Change module attribute get & set

Initial Comment:
Module objects currently don't define the tp_getattro 
or tp_setattro slots.  As a result, interning of 
attribute names does them no good:  a char* is always 
passed, so the dict lookup always needs to do a string 
compare despite that the attribute name is interned.

The patch simply implements these slots, and nulls out 
the raw-string tp_getattr and tp_setattr slots.

The former is by far the more important one, and I've 
measured speedups over 25% for simple programs that do 
lots of module lookups inside loops (random.random, 
os.path, etc).

So, sure looks like a big cheap win to me, but 
assigning for review in case I'm missing something 
obvious (i.e., if it's such an easy win, why didn't we 
already do it?).


----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-05-11 14:30

Message:
Logged In: YES 
user_id=6380

Oh, fudge.  It *should* be a convention.

But I don't care, this code won't be needed in the
descr-branch anyway.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-05-11 14:27

Message:
Logged In: YES 
user_id=31435

(getattrofunc)class_getattr, /* tp_getattro */
(getattrofunc)instance_getattr,	/* tp_getattro */
(getattrofunc)instancemethod_getattro,	/* tp_getattro */
(getattrofunc)func_getattro, /* tp_getattro */
(getattrofunc)proxy_getattr, /*tp_getattro*/
(getattrofunc)proxy_getattr,/*tp_getattro*/

It's not much of a convention when only 2 of 6 existing 
slots followed it!  Pronounce, please (make it 2 of 7, 3 of 
7, or change the non-conformers too to make it 7 of 7).

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-05-11 07:23

Message:
Logged In: YES 
user_id=6380

BTW, by convention the C function's name changes to
..._getattro and ..._setattro.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-05-11 06:35

Message:
Logged In: YES 
user_id=6380

There's no deep reason -- this code is ancient and has never
drawn anybody's attention.  I noticed the same thing while
doing a review of getattr vs. getattro for the descr-branch
code.

So I'd say, go for it!

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=423262&group_id=5470