boostorg / boostorg/python

Converting shared_ptr<const T> fails

オープン
#178 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C++
スター
537
フォーク
223
平均マージ
11時間 22分
マージ済み PR(30日)
2

説明

Boost Python (1.63) works well with `shared_ptr`; if I write this in C++:

shared_ptr create_shared_ptr() { return shared_ptr{...}; }
void accept_shared_ptr(const shared_ptr& p) { }

...

class_("Foo", no_init); //Expose abstract class

register_ptr_to_python< shared_ptr >();
def("create_shared_ptr", create_shared_ptr);
def("accept_shared_ptr", accept_shared_ptr);

Then I can write this in Python and everything works:

accept_shared_ptr(create_shared_ptr())

**The problem comes when I try and wrap `shared_ptr`.** (Which I need to do because I am wrapping a library that returns this.) If I modify the C++ functions as follows:

shared_ptr create_shared_ptr() { return shared_ptr{...}; }
void accept_shared_ptr(const shared_ptr& p) { }

Then I get the error:

> Boost.Python.ArgumentError: Python argument types in
> w3w_python.accept_shared_ptr(Foo)
> did not match C++ signature:
> accept_shared_ptr(std::shared_ptr)

It seems the internals are implementing conversion from python `Foo` to C++ `shared_ptr`, but not to C++ `shared_ptr`. Using

register_ptr_to_python< shared_ptr >();

doesn't help. How can I fix this?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。