Mitigation for pybind11 exceptions being forcibly exported

未关闭
#1,416 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

  • #1418 来自 @feltech —— 已关闭,未合并

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
cpp, python
领域
api

调研方向

未指定文件或测试。首先评估所述的 PYBIND11_EXPORT_EXCEPTION 和 PYBIND11_NAMESPACE 选项,以及它们对跨越 OpenAssetIO Python 模块和宿主应用程序的异常的影响。完成的标准是已实现选定的缓解措施,并验证其跨版本的异常和 ABI 行为。

由索引模型根据 Issue 内容生成。

描述

What

Decide whether to mitigate and if so design and implement a mitigation for exception types defined by pybind11 being exported by the pybind11 library (i.e. default visibility).

Why

Ideally, all OpenAssetIO dependencies are private and do not leak to the host application (with the notable exception of Python itself). This includes pybind11, where it would be ideal if OpenAssetIO's Python bindings are independent from the host application, i.e. where the host could use a different version of pybind11 if they wished, and everything would still work.

However, it turns out that pybind11 exports it's exception classes. In particular, the pybind11::error_already_set exception type that is used to carry Python exception data through a C++ exception (and potentially back to Python again).

For example, the ABI of the error_already_set type was changed radically between pybind11 2.9 and 2.10. If OpenAssetIO is built with 2.10 and the host is built with 2.9, and the exception is caught in the host (even as a std::exception), and .what() is called on it, the wrong implementation of .what() might be executed, giving garbled text.

The only solution for now is for consumers to ensure OpenAssetIO is built with the same version of pybind11 as the host application.

Notes

One quick solution to this is to set -DPYBIND11_EXPORT_EXCEPTION="", but this may have other unwanted side-effects - e.g. if we needed to catch a pybind11-specific exception in openassetio-python.so (Python<->C++ bridge) that was thrown by _openassetio.so (Python extension module).

Another option is to change the pybind11 namespace. This isn't trivial to do. We can completely change pybind11 to something else (by setting PYBIND11_NAMESPACE), and update all our code usages. But ideally the pybind11 authors would add an inline namespace to protect against ABI changes, as we do.

主要语言
C++
星标
352
派生
48
平均合并
4 天 14 小时
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

OpenAssetIO/OpenAssetIO 的其他 Issue

查看 OpenAssetIO/OpenAssetIO 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。