[C++-sig] Cplusplus-sig Digest, Vol 94, Issue 2

Matthew Conte matt.p.conte at gmail.com
Mon Aug 8 10:14:26 EDT 2016


Hi Alexandra,

Thanks for your input, unfortunately I still the get same error. I think
I'll follow Stefen's advice and instead use the Boost.Numpy ndarray wrapper
in place of numeric::array.

Thank you.

On Fri, Aug 5, 2016 at 11:37 AM, <foxtog at gmail.com> wrote:

> The problem doesn't have anything to do with boost.python. The thing is in
> initializing numpy API pointer specifically PyArray_API*. If you print this
> pointer before creating the array, it'll turn out to be null. If you move
> import_array function just before the array creation call, it should work.
> You can find more details here
> http://docs.scipy.org/doc/numpy/reference/c-api.array.html in
> Miscellaneous section at the bottom.
>
> Regards,
> Alexandra
>
> 05 авг. 2016 г., в 20:00, cplusplus-sig-request at python.org написал(а):
>
> Send Cplusplus-sig mailing list submissions to
>    cplusplus-sig at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>    https://mail.python.org/mailman/listinfo/cplusplus-sig
> or, via email, send a message with subject or body 'help' to
>    cplusplus-sig-request at python.org
>
> You can reach the person managing the list at
>    cplusplus-sig-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Cplusplus-sig digest..."
>
>
> Today's Topics:
>
>   1. Segmentation Fault (core dumped) on Python 3.5.2 but not
>      Python 2.7.12 (Matthew Conte)
>   2. Re: Segmentation Fault (core dumped) on Python 3.5.2 but not
>      Python 2.7.12 (Stefan Seefeld)
>   3. Re: Segmentation Fault (core dumped) on Python 3.5.2 but not
>      Python 2.7.12 (Matthew Conte)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 4 Aug 2016 13:10:23 -0400
> From: Matthew Conte <matt.p.conte at gmail.com>
> To: cplusplus-sig at python.org
> Subject: [C++-sig] Segmentation Fault (core dumped) on Python 3.5.2
>    but not Python 2.7.12
> Message-ID:
>    <CAFwmYYjxXXVQV=6Wv8x_q4Uc2GjogR1OR_JSURhP3kCMrEb-gQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> 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.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/cplusplus-sig/
> attachments/20160804/2ad0a9ec/attachment-0001.html>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 4 Aug 2016 13:14:58 -0400
> From: Stefan Seefeld <stefan at seefeld.name>
> To: cplusplus-sig at python.org
> Subject: Re: [C++-sig] Segmentation Fault (core dumped) on Python
>    3.5.2 but not Python 2.7.12
> Message-ID: <32f9c08d-2d65-c1b5-ca1a-1055f3784240 at seefeld.name>
> Content-Type: text/plain; charset=windows-1252
>
> 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...
>
>
>
> ------------------------------
>
> Message: 3
> Date: Thu, 4 Aug 2016 13:16:58 -0400
> From: Matthew Conte <matt.p.conte at gmail.com>
> To: "Development of Python/C++ integration" <cplusplus-sig at python.org>
> Subject: Re: [C++-sig] Segmentation Fault (core dumped) on Python
>    3.5.2 but not Python 2.7.12
> Message-ID:
>    <CAFwmYYjN4CDP4sLAs0C4JACFHPOxLeDyPX+LoSpv4NdGVfhGEQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> 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-0001.html>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> https://mail.python.org/mailman/listinfo/cplusplus-sig
>
> ------------------------------
>
> End of Cplusplus-sig Digest, Vol 94, Issue 2
> ********************************************
>
>
> _______________________________________________
> 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/20160808/94882c56/attachment-0001.html>


More information about the Cplusplus-sig mailing list