boost::python::numpy causing python crash when numpy not installed
- 主要語言
- C++
- 星號
- 537
- 分支
- 223
- 平均合併
- 11 小時 22 分鐘
- 30 天內合併 PR
- 2
描述
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
#include
#include
#include
namespace py = boost::python;
namespace np = boost::python::numpy;
template
np::ndarray to_numpy(const std::vector &vec)
{
Py_intptr_t shape[1] = { static_cast(vec.size()) };
np::ndarray result = np::zeros(1, shape, np::dtype::get_builtin());
std::copy(vec.begin(), vec.end(), reinterpret_cast(result.get_data()));
return result;
}
BOOST_PYTHON_MODULE(HelloBoostPython)
{
np::initialize();
py::class_>("DoubleVector")
.def(py::init())
.def(py::init())
.def(py::vector_indexing_suite>())
.def("to_numpy", to_numpy)
;
}
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.
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
Start with the reported BOOST_PYTHON_MODULE entry point and the np::initialize() call, then reproduce the import with numpy absent. Inspect how Boost.Python NumPy initialization propagates ModuleNotFoundError or ImportError during extension import. Done means the failure is catchable by Python instead of terminating the interpreter.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- cpp, numpy, python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100