boost::python::numpy causing python crash when numpy not installed
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- C++
- Stars
- 537
- Forks
- 223
- Avg merge
- 11h 22m
- Merged PRs (30d)
- 2
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/python
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
-
BoostDetectToolset-1.90.0.cmake file not found in an include() call in boost_python-config.cmake Open
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
AuTest Bug Tests
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/trafficserver#13714 ·
-
bug build
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
facebookincubator/velox#19143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tenstorrent/tt-metal#57393 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/eo-graphs#74 ·