Segmentation Fault (core dumped) on Python 3.5.2 but not Python 2.7.12
So I'm trying to create a boost python module that simply creates and returns a numpy array, but the function crashes (sometimes) and it doesn't ever seem to crash on Python 2. Here's the source code I made: #include <boost/python.hpp> #include <numpy/ndarrayobject.h> using namespace boost::python; object create_numpy_array() { npy_intp dims = 1; long* data = new long[1]; data[0] = 1; PyObject* obj = PyArray_SimpleNewFromData(1, &dims, PyArray_LONGLTR, data); boost::python::handle<> handle(obj); boost::python::numeric::array arr(handle); return arr.copy(); } BOOST_PYTHON_MODULE(create) { import_array(); numeric::array::set_module_and_type("numpy", "ndarray"); def("numpy_array", &create_numpy_array); } using a simple python script to test: import create print(create.numpy_array()) The stack trace indicates that the crash occurs on a boost::python::handle destructor trying to decrease the ref count of a PyObject with a ref count of 0. I've tried this on both Windows 7 and Ubuntu 16.04 both 64-bit. Thank you.
Hi Matthew, would you mind submitting an issue on https://github.com/boostorg/python/issues for this. Thanks, Stefan On 04.08.2016 13:10, Matthew Conte wrote:
So I'm trying to create a boost python module that simply creates and returns a numpy array, but the function crashes (sometimes) and it doesn't ever seem to crash on Python 2.
Here's the source code I made:
#include <boost/python.hpp> #include <numpy/ndarrayobject.h>
using namespace boost::python;
object create_numpy_array() { npy_intp dims = 1; long* data = new long[1]; data[0] = 1; PyObject* obj = PyArray_SimpleNewFromData(1, &dims, PyArray_LONGLTR, data); boost::python::handle<> handle(obj); boost::python::numeric::array arr(handle); return arr.copy(); }
BOOST_PYTHON_MODULE(create) { import_array(); numeric::array::set_module_and_type("numpy", "ndarray"); def("numpy_array", &create_numpy_array); }
using a simple python script to test:
import create print(create.numpy_array())
The stack trace indicates that the crash occurs on a boost::python::handle destructor trying to decrease the ref count of a PyObject with a ref count of 0.
I've tried this on both Windows 7 and Ubuntu 16.04 both 64-bit.
Thank you.
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig
-- ...ich hab' noch einen Koffer in Berlin...
I will, thank you. On Thu, Aug 4, 2016 at 1:14 PM, Stefan Seefeld <stefan@seefeld.name> wrote:
Hi Matthew,
would you mind submitting an issue on https://github.com/boostorg/python/issues for this.
Thanks, Stefan
On 04.08.2016 13:10, Matthew Conte wrote:
So I'm trying to create a boost python module that simply creates and returns a numpy array, but the function crashes (sometimes) and it doesn't ever seem to crash on Python 2.
Here's the source code I made:
#include <boost/python.hpp> #include <numpy/ndarrayobject.h>
using namespace boost::python;
object create_numpy_array() { npy_intp dims = 1; long* data = new long[1]; data[0] = 1; PyObject* obj = PyArray_SimpleNewFromData(1, &dims, PyArray_LONGLTR, data); boost::python::handle<> handle(obj); boost::python::numeric::array arr(handle); return arr.copy(); }
BOOST_PYTHON_MODULE(create) { import_array(); numeric::array::set_module_and_type("numpy", "ndarray"); def("numpy_array", &create_numpy_array); }
using a simple python script to test:
import create print(create.numpy_array())
The stack trace indicates that the crash occurs on a boost::python::handle destructor trying to decrease the ref count of a PyObject with a ref count of 0.
I've tried this on both Windows 7 and Ubuntu 16.04 both 64-bit.
Thank you.
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig
--
...ich hab' noch einen Koffer in Berlin...
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig
participants (2)
-
Matthew Conte -
Stefan Seefeld