vector_indexing_suite seems to break the use of return_internal_reference
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
調査の方向性
リンク先の Boost.Python の return_internal_reference の例から始め、Foo、Bar、FooList を公開する、示されている C++ モジュールを作成します。2 つ目の Foo を追加する Python シーケンスを実行し、その後、以前返された Bar 参照が変わる一方で foo_ref.get_bar() は有効なままである理由を調査します。ベクターの拡張後も内部参照が有効なままであれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I can create a class Foo that returns an internal reference to a class Bar and everything seems to work just fine. However, when I try and expose a vector of Foo using the vector_indexing_suite, I get some weird behavior. In Python, a reference to the underlying Bar of a Foo in a vector of Foos gets corrupted when a new Foo is appended to the vector.
Since most of the code comes straight out of the Boost Python docs, I assume it should work.
The issue can be replicated by making a few modifications to an example from the Boost Python docs.
#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <boost/python/return_internal_reference.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <vector>
class Bar
{
public:
Bar(int x) : x(x) {}
int get_x() const { return x; }
void set_x(int x) { this->x = x; }
bool operator==(const Bar &other) const { return other.x == x;}
bool operator!=(const Bar &other) const { return !(other == (*this)); }
private:
int x;
};
class Foo
{
public:
Foo(int x) : b(x) {}
// Returns an internal reference
Bar const& get_bar() const { return b; }
bool operator==(const Foo &other) const {return other.b == b;}
bool operator!=(const Foo &other) const { return !(other == (*this)); }
private:
Bar b;
};
using namespace boost::python;
BOOST_PYTHON_MODULE(boosttest)
{
class_<Bar>("Bar", init<int>())
.def("get_x", &Bar::get_x)
.def("set_x", &Bar::set_x)
;
class_<Foo>("Foo", init<int>())
.def("get_bar", &Foo::get_bar
, return_internal_reference<>())
;
class_<std::vector<Foo>>("FooList")
.def(vector_indexing_suite<std::vector<Foo>>())
;
}
Then on the Python side, we get the following.
>>> import boosttest
>>> foolist = boosttest.FooList()
>>> foolist.append(boosttest.Foo(2))
>>> foo_ref = foolist[0]
>>> bar_ref = foo_ref.get_bar()
>>> bar_ref.get_x()
2
>>> foolist.append(boosttest.Foo(3))
>>> bar_ref.get_x()
-572662307
>>> foo_ref.get_bar().get_x()
2
- 主要言語
- C++
- スター
- 537
- フォーク
- 223
- 平均マージ
- 11時間 22分
- マージ済み PR(30日)
- 2
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
boostorg/python のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
-
BoostDetectToolset-1.90.0.cmake file not found in an include() call in boost_python-config.cmake オープン
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
boostorg/python の issue をすべて見る
似ている issue
-
AuTest Bug Tests
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/trafficserver#13714 ·
-
bug build
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
facebookincubator/velox#19143 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
tenstorrent/tt-metal#57393 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
objectionary/eo-graphs#74 ·