Skip to content

Resolve "pybind11:接口中存在 vector | map 容器引用为参数时,并没有达到引用的效果"

mingfa.yang requested to merge 404-pybind11 into master

Closes #404 (closed)

  1. 收集接口中出现过的 vector | map 实例化容器引用类型
  2. 生成pybind11_opaque.hpp文件调用PYBIND11_MAKE_OPAQUE(T),用于消除pybind11/stl_bind.hpp中对实例化容器类型T的自动cast。对于引用了pybind11/stl_bind.hpp的位置都需要同时引用pybind11_opaque.hpp,否则会出现映射错误
  3. binder接口(绑定接口统一调用入口)中调用bind_vector<T, name>,pybind11::bind_map<T, name>,完成容器的引用语义自动绑定。(pybind11不支持set的引用语义自动绑定)
  4. 在接口参数,返回值,变量翻译中,针对收集的实例化容器类型进行区分绑定: a. 若为vector&,map& 采用引用语义绑定; b. 若为vector,map,const vector &, const map &,则用lambda函数包装原生接口,使用pybind11::listpybind11::dict类型绑定cpp vectormap类型
  5. 对于模板嵌套类型,如std::vector<std::vector<std::string>>>,其中模板参数类型std::vector<std::string>>,会被翻译为默认类型,即若std::vector<std::string>>默认绑定为ListString,则std::vector<std::vector<std::string>>>& 被翻译为 ListListString, 内部储存ListStringstd::vector<std::vector<std::string>>>const std::vector<std::vector<std::string>>> & 被翻译为 list[ListString]

文档: https://alidocs.dingtalk.com/i/nodes/dpYLaezmVNLNN1X0hkL4blax8rMqPxX6?utm_scene=team_space&iframeQuery=anchorId%3Duu_mixy0pcu7acq4zen6d7

Edited by mingfa.yang

Merge request reports

Loading