[C++-sig] Segmentation Fault (core dumped) on Python 3.5.2 but not Python 2.7.12

Matthew Conte matt.p.conte at gmail.com
Thu Aug 4 13:16:58 EDT 2016


I will, thank you.

On Thu, Aug 4, 2016 at 1:14 PM, Stefan Seefeld <stefan at 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 at python.org
> > https://mail.python.org/mailman/listinfo/cplusplus-sig
>
>
> --
>
>       ...ich hab' noch einen Koffer in Berlin...
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> https://mail.python.org/mailman/listinfo/cplusplus-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20160804/b50c011c/attachment.html>


More information about the Cplusplus-sig mailing list