Martin v. Löwis | c06917b | 2012-06-22 12:49:08 +0200 | [diff] [blame] | 1 | .. highlightlang:: c |
| 2 | |
| 3 | .. _stable: |
| 4 | |
Nick Coghlan | 7d82c86 | 2013-03-07 23:14:44 +1000 | [diff] [blame] | 5 | *********************************** |
| 6 | Stable Application Binary Interface |
| 7 | *********************************** |
Martin v. Löwis | c06917b | 2012-06-22 12:49:08 +0200 | [diff] [blame] | 8 | |
| 9 | Traditionally, the C API of Python will change with every release. |
| 10 | Most changes will be source-compatible, typically by only adding API, |
| 11 | rather than changing existing API or removing API (although some |
| 12 | interfaces do get removed after being deprecated first). |
| 13 | |
| 14 | Unfortunately, the API compatibility does not extend to binary |
| 15 | compatibility (the ABI). The reason is primarily the evolution of |
| 16 | struct definitions, where addition of a new field, or changing |
| 17 | the type of a field, might not break the API, but can break the ABI. |
Martin v. Löwis | 466bfff | 2012-06-22 12:49:59 +0200 | [diff] [blame] | 18 | As a consequence, extension modules need to be recompiled for |
| 19 | every Python release (although an exception is possible on Unix |
Martin v. Löwis | c06917b | 2012-06-22 12:49:08 +0200 | [diff] [blame] | 20 | when none of the affected interfaces are used). In addition, on |
| 21 | Windows, extension modules link with a specific pythonXY.dll and |
| 22 | need to be recompiled to link with a newer one. |
| 23 | |
| 24 | Since Python 3.2, a subset of the API has been declared to guarantee |
| 25 | a stable ABI. Extension modules wishing to use this API need to define |
Nick Coghlan | 7d82c86 | 2013-03-07 23:14:44 +1000 | [diff] [blame] | 26 | ``Py_LIMITED_API``. A number of interpreter details then become hidden |
Martin v. Löwis | c06917b | 2012-06-22 12:49:08 +0200 | [diff] [blame] | 27 | from the extension module; in return, a module is built that works |
Nick Coghlan | 7d82c86 | 2013-03-07 23:14:44 +1000 | [diff] [blame] | 28 | on any 3.x version (x>=2) without recompilation. |
| 29 | |
| 30 | In some cases, the stable ABI needs to be extended with new functions. |
| 31 | Extension modules wishing to use these new APIs need to set |
| 32 | ``Py_LIMITED_API`` to the ``PY_VERSION_HEX`` value (see |
| 33 | :ref:`apiabiversion`) of the minimum Python version they want to |
| 34 | support (e.g. ``0x03030000`` for Python 3.3). Such modules will work |
Martin v. Löwis | c06917b | 2012-06-22 12:49:08 +0200 | [diff] [blame] | 35 | on all subsequent Python releases, but fail to load (because of |
| 36 | missing symbols) on the older releases. |
| 37 | |
| 38 | As of Python 3.2, the set of functions available to the limited API |
| 39 | is documented in PEP 384. |
| 40 | |
| 41 | .. XXX copy exact list here? Into each functions definition? |