“Python/docs/3.9/c-api/stable”的版本间差异

来自菜鸟教程
Python/docs/3.9/c-api/stable
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:稳定的应用程序二进制接口 — Python 文档}}
 
<div id="stable-application-binary-interface" class="section">
 
<div id="stable-application-binary-interface" class="section">
  
 
<span id="stable"></span>
 
<span id="stable"></span>
= Stable Application Binary Interface =
+
= 稳定的应用程序二进制接口 =
  
Traditionally, the C API of Python will change with every release. Most changes
+
传统上,Python 的 C API 会随着每个版本而改变。 大多数更改将与源代码兼容,通常仅通过添加 API,而不是更改现有 API 或删除 API(尽管某些接口在首先被弃用后确实会被删除)。
will be source-compatible, typically by only adding API, rather than changing
 
existing API or removing API (although some interfaces do get removed after
 
being deprecated first).
 
  
Unfortunately, the API compatibility does not extend to binary compatibility
+
不幸的是,API 兼容性并未扩展到二进制兼容性(ABI)。 原因主要是结构定义的演变,其中添加新字段或更改字段类型可能不会破坏 API,但会破坏 ABI。 因此,每个 Python 版本都需要重新编译扩展模块(尽管在 Unix 上没有使用任何受影响的接口时可能会出现异常)。 此外,在 Windows 上,扩展模块与特定的 pythonXY.dll 链接,需要重新编译以与更新的链接。
(the ABI). The reason is primarily the evolution of struct definitions, where
 
addition of a new field, or changing the type of a field, might not break the
 
API, but can break the ABI. As a consequence, extension modules need to be
 
recompiled for every Python release (although an exception is possible on Unix
 
when none of the affected interfaces are used). In addition, on Windows,
 
extension modules link with a specific pythonXY.dll and need to be recompiled to
 
link with a newer one.
 
  
Since Python 3.2, a subset of the API has been declared to guarantee a stable
+
Python 3.2 起,已声明 API 的一个子集以保证稳定的 ABI。 希望使用此 API(称为“受限 API”)的扩展模块需要定义 <code>Py_LIMITED_API</code>。 一些解释器的细节会从扩展模块中隐藏起来; 作为回报,构建了一个无需重新编译即可在任何 3.x 版本 (x&gt;=2) 上运行的模块。
ABI. Extension modules wishing to use this API (called &quot;limited API&quot;) need to
 
define <code>Py_LIMITED_API</code>. A number of interpreter details then become hidden
 
from the extension module; in return, a module is built that works on any 3.x
 
version (x&gt;=2) without recompilation.
 
  
In some cases, the stable ABI needs to be extended with new functions.
+
在某些情况下,需要使用新功能扩展稳定的 ABI。 希望使用这些新 API 的扩展模块需要将 <code>Py_LIMITED_API</code> 设置为他们想要支持的最低 Python 版本(例如 <code>0x03030000</code> 用于 Python 3.3)。 此类模块将适用于所有后续 Python 版本,但无法在旧版本上加载(由于缺少符号)。
Extension modules wishing to use these new APIs need to set <code>Py_LIMITED_API</code>
 
to the <code>PY_VERSION_HEX</code> value (see [[../apiabiversion#apiabiversion|<span class="std std-ref">API and ABI Versioning</span>]]) of the minimum Python
 
version they want to support (e.g. <code>0x03030000</code> for Python 3.3). Such modules
 
will work on all subsequent Python releases, but fail to load (because of
 
missing symbols) on the older releases.
 
  
As of Python 3.2, the set of functions available to the limited API is
+
Python 3.2 开始,可用于有限 API 的函数集记录在 <span id="index-0" class="target"></span>[https://www.python.org/dev/peps/pep-0384 PEP 384] 中。 在 C API 文档中,不属于受限 API API 元素被标记为“不属于受限 API”。
documented in <span id="index-0" class="target"></span>[https://www.python.org/dev/peps/pep-0384 '''PEP 384''']. In the C API documentation, API elements that are not
 
part of the limited API are marked as &quot;Not part of the limited API.&quot;
 
  
  
 
</div>
 
</div>
 +
<div class="clearer">
  
[[Category:Python 3.9 中文文档]]
+
 
 +
 
 +
</div>
 +
 
 +
[[Category:Python 3.9 文档]]

2021年10月31日 (日) 04:50的最新版本

稳定的应用程序二进制接口

传统上,Python 的 C API 会随着每个版本而改变。 大多数更改将与源代码兼容,通常仅通过添加 API,而不是更改现有 API 或删除 API(尽管某些接口在首先被弃用后确实会被删除)。

不幸的是,API 兼容性并未扩展到二进制兼容性(ABI)。 原因主要是结构定义的演变,其中添加新字段或更改字段类型可能不会破坏 API,但会破坏 ABI。 因此,每个 Python 版本都需要重新编译扩展模块(尽管在 Unix 上没有使用任何受影响的接口时可能会出现异常)。 此外,在 Windows 上,扩展模块与特定的 pythonXY.dll 链接,需要重新编译以与更新的链接。

自 Python 3.2 起,已声明 API 的一个子集以保证稳定的 ABI。 希望使用此 API(称为“受限 API”)的扩展模块需要定义 Py_LIMITED_API。 一些解释器的细节会从扩展模块中隐藏起来; 作为回报,构建了一个无需重新编译即可在任何 3.x 版本 (x>=2) 上运行的模块。

在某些情况下,需要使用新功能扩展稳定的 ABI。 希望使用这些新 API 的扩展模块需要将 Py_LIMITED_API 设置为他们想要支持的最低 Python 版本(例如 0x03030000 用于 Python 3.3)。 此类模块将适用于所有后续 Python 版本,但无法在旧版本上加载(由于缺少符号)。

从 Python 3.2 开始,可用于有限 API 的函数集记录在 PEP 384 中。 在 C API 文档中,不属于受限 API 的 API 元素被标记为“不属于受限 API”。