[C++-sig] Python API wrapping details
daveh at cadlink.com
Thu Jun 20 15:44:07 CEST 2002
I'm proposing the following techniques for wrapping the python API for BPL.
Boost header files will be created from a python script. The script will
contain a list of all the supported API functions and their attributes, such
as whether borrowed or new references are returned, error handling, etc. All
the API metadata will be defined in the python script. The python script
will then use a set of rules to generate the API wrappers from this
This way if we find at some point we don't like the structure of the
wrappers it is just a matter of adjusting the generator rules rather than
re-editing all the headers.
There are a few issues about the structure of the wrappers:
1) For functions that take non-PyObjects (ie int) as arguments should we
still insist that the arg is wrapped in an object? Maybe there should be
overloaded functions so that either type of arg is acceptable?
2) How should we deal with PyObect** args (ie PyString_InternInPlace) should
the argument type be object& or object*? I suspect its probably better to
force the user to do an explicit &obj.
3) Should all functions always return an object (unless they are void)?
There may be efficiency concerns if we keep wrapping int returns all the
time. We could also provide versions of the functions that do either (though
we can't overload on return type). Some return types may not even be
appropriate to return as an object (ie FILE*).
More information about the Cplusplus-sig