0

このコードを取る

#include<boost/python>
namespace bp = boost::python;

bp::list py_points; //initial list
other_class* C; // this class have a bp::list attribute called py_list

// ... some code ....

// in this part C.py_list.ptr() is 0x0

other_class->py_list = py_list; // problem here!!

問題は演算子「=」にあります

object_core.hpp ファイルのデバッガーでは、これはブースト python コア ファイルです。

inline api::object_base& api::object_base::operator=(api::object_base const& rhs)
{
    Py_INCREF(rhs.m_ptr);
    Py_DECREF(this->m_ptr); // in this line the program fail
    this->m_ptr = rhs.m_ptr;
    return *this;
}

演算子 "=" を使用する適切な方法は何ですか?

編集済み

問題はスタックです。ポインター other_class->py_list が null (または、クラス コンストラクターが呼び出されていないため None) の場合、プログラムは関数Py_DECREFを呼び出すことができません (NULL ポインターの前に参照が存在しない)。

問題は、コンストラクターの呼び出しを修正することです

other_class* C = new othe_class(); // fixed!!
4

1 に答える 1