Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Converting shared_ptr<const T> fails

オープン
#178 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp
領域
tooling

調査の方向性

まず、shared_ptr を使用して、示されている C++ バインディングを create_shared_ptr、accept_shared_ptr、register_ptr_to_python で再現します。const ターゲット型に対する Boost.Python の変換経路を追跡します。create_shared_ptr が返す Python の Foo が ArgumentError なしで accept_shared_ptr に受け入れられれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

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

...

class_<Foo, boost::noncopyable>("Foo", no_init); //Expose abstract class

register_ptr_to_python< shared_ptr<Foo> >();
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<const Foo>. (Which I need to do because I am wrapping a library that returns this.) If I modify the C++ functions as follows:

shared_ptr<const Foo> create_shared_ptr() { return shared_ptr{...}; }
void accept_shared_ptr(const shared_ptr<const Foo>& 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<Foo const>)

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

register_ptr_to_python< shared_ptr<const Foo> >();

doesn't help. How can I fix this?

主要言語
C++
スター
537
フォーク
223
平均マージ
11時間 22分
マージ済み PR(30日)
2

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

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

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/python のほかの issue

boostorg/python の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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