[C++-sig] [ANN] arbitrary arity support / new callback interface

David Abrahams david.abrahams at rcn.com
Fri Apr 12 07:22:21 CEST 2002


Boost.Python v2 has been updated to support arbitrary numbers of
function arguments. Due to limitations of the EDG preprocessor (it's
*slow*), the default limit is 10 arguments on EDG-based compilers, and
12 arguments elsewhere (the "this" pointer counts as an argument in
member functions).

If you need support for more arguments, you can #define
BOOST_PYTHON_MAX_ARITY to whatever number > 10 you need. Be aware that
with most EDG-based compilers, increasing the max arity in this fashion
will slow compilation down a lot. A number of new files
(boost/python/preprocessed/*.hpp) contain expanded versions of the
functions for up to 10 arguments; these can be regenerated using the
preprocessor to get support for more without incurring a speed penalty.

The interface for calling back into Python (e.g. in virtual functions)
has changed a bit: see libs/python/test/virtual_functions.cpp and
libs/python/test/callbacks.cpp for examples. Basically, instead of
writing:

    returning<ReturnType>::call_method(self, "method_name", arg1, arg2,
arg3...)
  or
    returning<ReturnType>::call(callable, arg1, arg2, arg3...)

You now write:

    call_method<ReturnType>(self, "method_name", arg1, arg2, arg3...)
  or
    call<ReturnType>(callable, arg1, arg2, arg3...)

[If ReturnType is void, it may be ommitted.]

Unfortunately, gcc-2.95.3 (MinGW, but likely on Linux also) generates
incorrect exception-handling code for this construct, so the library's
checking for your erroneous code may not work so well with that
compiler. I'll be looking into alternatives which the compiler will be
happier with. In the meantime, just don't make mistakes ;-)

Regards,
Dave


+---------------------------------------------------------------+
                  David Abrahams
      C++ Booster (http://www.boost.org)               O__  ==
      Pythonista (http://www.python.org)              c/ /'_ ==
  resume: http://users.rcn.com/abrahams/resume.html  (*) \(*) ==
          email: david.abrahams at rcn.com
+---------------------------------------------------------------+






More information about the Cplusplus-sig mailing list