boost::python::numpy causing python crash when numpy not installed
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 30/100
調査の方向性
報告されている BOOST_PYTHON_MODULE エントリポイントと np::initialize() の呼び出しから始め、numpy が存在しない状態でインポートを再現します。拡張機能のインポート中に、Boost.Python NumPy の初期化が ModuleNotFoundError または ImportError をどのように伝播させるかを調べます。Python で失敗を捕捉でき、インタープリターが終了しなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
The following code causes python to exit (crash?) upon import when numpy is not installed. It looks like a ModuleNotFoundError does get thrown but it's not catchable and python simply exits. It's hard to tell if this is exit() being called or an actual crash. I would expect a catchable ModuleNotFoundError or ImportError to be thrown and python not to exit.
#define BOOST_PYTHON_STATIC_LIB
#define BOOST_NUMPY_STATIC_LIB
#include <boost/python.hpp>
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <boost/python/numpy.hpp>
namespace py = boost::python;
namespace np = boost::python::numpy;
template<class T>
np::ndarray to_numpy(const std::vector<T> &vec)
{
Py_intptr_t shape[1] = { static_cast<Py_intptr_t>(vec.size()) };
np::ndarray result = np::zeros(1, shape, np::dtype::get_builtin<T>());
std::copy(vec.begin(), vec.end(), reinterpret_cast<T*>(result.get_data()));
return result;
}
BOOST_PYTHON_MODULE(HelloBoostPython)
{
np::initialize();
py::class_<std::vector<double>>("DoubleVector")
.def(py::init<size_t>())
.def(py::init<size_t, const double&>())
.def(py::vector_indexing_suite<std::vector<double>>())
.def("to_numpy", to_numpy<double>)
;
}
prompt:
(base) C:\Development\HelloBoostPython\Debug>python
Python 3.7.4 (default, Aug 9 2019, 18:22:51) [MSC v.1915 32 bit (Intel)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import HelloBoostPython
ModuleNotFoundError: No module named 'numpy'
ImportError: numpy.core._multiarray_umath failed to import
(base) C:\Development\HelloBoostPython\Debug>
If it matters, this is with boost 1.70 using visual studio 2017 to build.
- 主要言語
- 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
-
enhancement
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
QuantStack/git2cpp#187 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
mlcommons/mobile_app_open#1182 ·
-
Needs-Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/winget-cli#6547 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
AXERA-TECH/ax-llm#77 ·