Notice: While Javascript is not essential for this website, your interaction with the content will be limited. Please turn Javascript on for the full experience.

SIG for development of Python/C++ integration

SIG for development of Python/C++ integration

The Python C++ SIG is a forum for discussions about the integration of Python and C++, with an emphasis on the development of the Boost.Python library. At the point of this writing (Jan 2002), Boost.Python is undergoing a major rewrite to add powerful new features and to take full advantage of the new type system introduced in Python 2.2. Suggestions regarding the direction of the development work and contributions in the form of source code should be posted to this SIG.

About Boost.Python

Boost.Python is a popular open-source tool for interfacing Python and C++. Boost.Python is built on accessible, well-maintained, well documented components (the Boost C++ Library), so it does not tie its users to the services of any one programmer or organization. Developers worldwide have contributed significant unsolicited improvements to the project. The main developer and coordinator of the library is David Abrahams.

Development goals

The following sections describe the current development goals. Suggestions regarding the direction of the development work and contributions in the form of source code should be posted to the Python C++ SIG.
Reference/Pointer support
Boost.Python currently refuses to wrap C++ functions which return pointers or non-const references, in order to prevent dangling pointers and references from causing crashes on the Python side. This limits the library's ability to export arbitrary C++ functions.

Goal: Implementation of a mechanism by which references and pointers to internal elements of function and method arguments can be returned safely. This will include a mechanism by which any argument object can be kept alive during the lifetime of any other argument object, so that Wrapped C++ objects can adopt one another without the direct use of smart pointers.

Globally Registered Type Coercions
Goal: Provide a mechanism for global registration of type relationships between arbitrary Python and C++ types, so that, for example, a Python tuple might be automatically converted to a C++ std::vector when passed to a wrapped function accepting a std::vector argument.

Full Cross-Module Support
Inheritance hierarchies which span Python extension modules are not currently supported by Boost.Python. Other inter-module interaction issues, e.g. exception handling, are expected to arise.

Goal: Full support for the interaction of wrapped types and functions residing in different extension modules.

Improved Overloading Support
Boost.Python's support for overloaded functions and operators is based on throwing C++ exceptions when a signature fails to match the appropriate function. This has several disadvantages: firstly, on many implementations the C++ exception-handling mechanism is highly optimized for the case where no exception is thrown, and throwing an exception can pose serious performance penalties. Secondly, enough C++ implementations have bugs in their exception-handling mechanisms that it is best not to rely on exceptions for routine control flow.

Goal: Modification of the type conversion mechanism so that overloading can be implemented without the use of C++ exceptions.

C++ to Python Exception Translation
It is critical for any mature C++ software package to be able to report error conditions via arbitrary exception types. Boost.Python currently provides support for translating only a limited selection of exception types to Python.

Goal: Implementation of a feature which allows arbitrary new exception types to be registered and automatically translated.

Default Argument Support
C++ functions with default argument values can currently be exposed to Python, but the defaults are lost.

Goal: Implementation of compile-time constant default argument expressions. Potentially implementation of lambda expressions for describing default arguments.

Keyword Argument Support
Python supports the specification of particular function arguments by name, rather than by position.

Goal: Implementation of a feature which allows keyword arguments to be used from Python for wrapped C++ functions.

Generic C++ to Python Object Interface
It is often necessary for C++ functions to manipulate objects passed to them directly from Python, without converting them to some other representation. Currently Boost.Python has undocumented support for that usage when the expected Python type is known.

Goal: Addition of a C++ type which wraps any Python object and provides a similar interface to Python's, with the validity of any operation checked at runtime.

Interface for the application of standard C++ algorithms to Python objects
Goal: Implementation of interfaces for the application of C++ Standard Template Library algorithms and boost algorithms to Python objects, such as Python lists, tuples, strings and Python objects that support the buffer interface.

Python LONG support
Python provides an arbitrary-precision LONG integer type which is not currently supported by Boost.Python.

Goal: Addition of an interface to Python LONGs which allows them to be directly manipulated in C++ with a natural interface.

Improved Built-In Numeric Type Coercion
Goal: Python supplies at least 4 numeric types, any of which should be able to be passed where an argument of any C++ numeric type is expected, provided that the conversion does not lose significant information.

Python Iterator Support
Goal: Python 2.2 provides an iteration interface which should allow C++ sequences to be easily exposed to Python in a natural way.

Automatic C++ Object Initialization
While Python allows classes to be created without initialization, C++ does not. Boost.Python currently allows C++ base classes of Python extension classes to remain uninitialized. That behavior is not always appropriate.

Goal: Optional support for the automatic default construction of C++ base classes and error reporting when base classes are not initialized.

DocString Support
Modules, Types, and Functions in Python can be documented with "docstrings", which allow the automatic extraction of documentation (and even testing code) at runtime. Goal: Full support for docstrings on the elements of C++ extension modules and classes.

C++ long long support
The long long type is a popular extension to C++ which allows the representation of integer numeric values of at least 64 bits.

Goal: Automatic conversions of C++ long long values to/from Python.

Code Footprint Reduction
Currently Boost.Python is not optimized to reduce the code size of the C++ extension modules.

Goal: Reengineering of Boost.Python so that the code footprint for each extension module is as small as feasible.

Data Memory Footprint Reduction
Wrapped C++ classes that are not subclassed in Python use more dynamic allocation than necessary, increasing the overall data footprint of an application using Boost.Python extension classes.

Goal: Embedding of C++ classes directly in Python objects. This will eliminate the overhead due to dynamic allocation.