[Python-Dev] Proposing "Argument Clinic", a new way of specifying arguments to builtins for CPython
dmalcolm at redhat.com
Tue Dec 4 17:47:23 CET 2012
On Mon, 2012-12-03 at 14:29 -0800, Larry Hastings wrote:
[...snip compelling sales pitch...]
I like the idea.
As noted elsewhere, sane generated C code is much easier to step through
in the debugger than preprocessor macros (though "sane" in that sentence
is begging the question, I guess, but the examples you post look good to
me). It's also seems cleaner to split the argument handling from the
implementation of the function (iirc Cython already has an analogous
split and can use this to bypass arg tuple creation).
The proposal potentially also eliminates a source of bugs: mismatches
between the format strings in PyArg_Parse* vs the underlying C types
passed as varargs (which are a major pain for bigendian CPUs where int
vs long screwups can really bite you).
I got worried that this could introduce a bootstrapping issue (given
that the clinic is implemented using python itself), but given that the
generated code is checked in as part of the C source file, you always
have the source you need to regenerate the interpreter.
Presumably 3rd party extension modules could use this also, in which
case the clinic tool could be something that could be installed/packaged
as part of Python 3.4 ?
> Big unresolved questions:
> * How would we convert all the builtins to use Clinic? I fear any
> solution will involve some work by hand. Even if we can automate
> big chunks of it, fully automating it would require parsing arbitrary
> C. This seems like overkill for a one-shot conversion.
> (Mark Shannon says he has some ideas.)
Potentially my gcc python plugin could be used to autogenerate things.
FWIW I already have Python code running inside gcc that can parse the
Though my plugin runs after the C preprocessor has been run, so it may
be fiddly to use this to autogenerate patches.
Hope this is helpful
More information about the Python-Dev