[Patches] [ python-Patches-659536 ] Use PyArg_UnpackTuple where possible

noreply@sourceforge.net noreply@sourceforge.net
Sun, 29 Dec 2002 06:55:02 -0800


Patches item #659536, was opened at 2002-12-29 01:46
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=659536&group_id=5470

Category: None
Group: None
Status: Open
Resolution: Accepted
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Use PyArg_UnpackTuple where possible

Initial Comment:
Obtain cleaner coding and a system wide 
performance boost by using the fast, pre-parsed 
PyArg_Unpack function instead of PyArg_ParseTuple 
function which is driven by a format string.

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

>Comment By: Walter Dörwald (doerwalter)
Date: 2002-12-29 15:55

Message:
Logged In: YES 
user_id=89016

The patch looks good, apart from the following:the last
patched line in Python/bltinmodule.c has
   if (!PyArg_UnpackTuple(args, "OO:issubclass", 2, 2,
&derived, &cls))
instead of
   if (!PyArg_UnpackTuple(args, "issubclass", 2, 2,
&derived, &cls))

"" #OP must be used, because OP is not passed in as a string
constant, i.e. the macro is called as spami(truth,
PyObject_IsTrue), not as spami("truth", PyObject_IsTrue), so
IMHO that part of the patch is OK.

There are several more spots, when this could be used:
Modules/_codecsmodule.c: register
Modules/_hotshot.c: runcall
Modules/_localemodule.c: strcoll
Modules/_sre.c: __deepcopy__, expand, stat, end, span
Modules/_tkinter.c: deletefilehandler, _flatten
Modules/arraymodule.c: count, index, remove, extend, append,
 tofile, fromlist
Modules/cPickle.c: Unpickler, load
Modules/cStringIO.c: getval, writelines, StringIO
Modules/mpzmodule.c: several unnamed functions
Modules/puremodule.c: purify_map_pool_id
Modules/pyexpat.c: ParseFile
Modules/selectmodule.c: select, unregister, poll
Modules/timemodule.c asctime, mktime
Modules/_bsddb.c: append, has_key, keys, items, values
Modules/posixmodule.c: setgid
Modules/typeobject.c: Many unnamed functions
PC/_winreg.c: CloseKey,  FlushKey, QueryInfoKey
Python/exception.c: __getitem__ and __str__ three times
Python/marshal.c: dump, load, dumps
Python/sysmodule.c: exit

Furthermore, , there are several spots where the format
string starts with :, i.e. ":foo". Should those functions
all be changed to METH_NOARGS?

Martin, can this patch be accepted, so it can go in before
2.3a1 is released?


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

Comment By: Martin v. Löwis (loewis)
Date: 2002-12-29 09:08

Message:
Logged In: YES 
user_id=21627

One more change: Please try to report the correct function
name for min/max, using ?:.

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

Comment By: Martin v. Löwis (loewis)
Date: 2002-12-29 09:00

Message:
Logged In: YES 
user_id=21627

The changes to spam* are non-sensical: there is no point in
concatenating the empty string with #OP, just remove the
empty string.

Apart from this, the patch is fine.

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

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