[Patches] [ python-Patches-660559 ] Use METH_O and METH_NOARGS where possible

noreply@sourceforge.net noreply@sourceforge.net
Fri, 03 Jan 2003 00:13:50 -0800


Patches item #660559, was opened at 2003-01-01 00:19
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=660559&group_id=5470

Category: Modules
Group: Python 2.3
Status: Open
>Resolution: Accepted
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
>Assigned to: Raymond Hettinger (rhettinger)
Summary: Use METH_O and METH_NOARGS where possible

Initial Comment:
Speed-up calls and tighten code in operator.c 
arraymodule.c, and cStringIO.c by using METH_O, 
METH_NOARGS and PyArg_UnpackTuple.

Didn't touch other modules that I wasn't familiar with 
or that didn't look like they would benefit from the 
speedup.

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

>Comment By: Martin v. Löwis (loewis)
Date: 2003-01-03 09:13

Message:
Logged In: YES 
user_id=21627

I agree that the patch looks fine; Raymond, please apply it.

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

Comment By: Brett Cannon (bcannon)
Date: 2003-01-03 08:12

Message:
Logged In: YES 
user_id=357491

So I just finished reading the diff and it all looks good to
me (I think).  I basically just read through the diff and
when I saw  the original I tried to guess how Raymond
changed it and see what he did, in fact, change it to in the
end.  All turned out the way I expected it.

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-01-02 03:27

Message:
Logged In: YES 
user_id=80475

Fixed.  Revised patch attached.

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

Comment By: Tim Peters (tim_one)
Date: 2003-01-02 02:52

Message:
Logged In: YES 
user_id=31435

Note that a METH_NOARGS function is still called, at the C 
level, with two arguments.  The second argument is always 
NULL, and sooner or later some platform C is going to blow 
up when that's passed to a function declared to take only 
one argument ("the usual" cast to PyCFunction shuts up the 
compile-time warnings).

It's not your job to fix that everywhere, but new uses of 
METH_NOARGS shouldn't add to this problem.  Declaring a 
second PyObject * argument with a name like "unused" 
or "dummy" would be fine.

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

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