PyArg_ParseTuple on steroids?

Grant Munsey gmunsey at
Mon Mar 12 23:10:00 CET 2001

I have been doing a lot of Python to C library adapters recently.
Currently I'm generating the code for each Python cover routine with
a Python program which uses a crude IDL to drive the generator. I
build the IDL descriptors by hand or with another Python program in
the case where the API is described in a "regular" way.

Currently the C source that is output by the generator looks pretty
much like code that would be generated by hand  ... with PyArg_ParseTuple()
at the beginning and Py_BuildValue() at the end.

I was thinking of changing this to have the generator generate a table
of parameter descriptions for each procedure and one call to an "uber"
argument handler ... that would check the parameters, get the C values,
call the function, and convert the results back into a Python return value.
Kind of a PyArg_ParseTuple(), call function, Py_BuildValue() all rolled
into one but that could handle many more parameter types than the standard
routines do.

This would have the benefit of smaller overall code generation and the
various parameter handlers would be in one place instead of spread all
over a large Python program which generates code.

Anyone done this in the past and have any advice?

More information about the Python-list mailing list