|
Boost Users : |
Subject: Re: [Boost-users] Problem with casting numeric array to/from PyArrayObject
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-08-25 09:44:47
AMDG
Lionel LE ROUX wrote:
> To start with Boost, I wrote a (very simple) test_that_() function in
> C/Boost with a numeric::array& as argument. I compiled a .so file and
> I'm then able to seamlessly use this function from Python : that's for
> the successful part...
> Now I want to trace memory usage (and possible leaks) using Valgrind :
> then I don't use Python anymore and decide to stay in the C world : so
> I wrote a short test program in C which only includes a call to the
> function in the .so :
>
> /int main(void) {
> Py_Initialize();
> import_array();
>
> npy_intp dim[]={1000};
> PyArrayObject* X = (PyArrayObject*)PyArray_SimpleNew(1, dim,
> PyArray_FLOAT);
>
> test_that_((numeric::array&)X);
>
> Py_DECREF(X);
> Py_Finalize();
>
> return 0;
> }/
>
> I can compile and build the executable file with no error but when I
> run it : segmentation fault when I try to use PyArray_Size within the
> test_that() function, which only "link" a PyArrayObject to the
> numeric::array argument. The manipulation of the data seems to be OK
> but problem arises with PyArray_Size.
>
> Well, looks like the double cast (PyArrayObject -> numeric::array ->
> PyArrayObject) is not valid.
> Could someone confirm (or not) my (very) bad coding ?
What is numeric::array? I'm not sure that you can safely
cast a PyArrayObject to a numeric::array, but even if
you could you can't cast a pointer to a PyArrayObject to
a reference to a numeric::array.
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net