[Cython] Memory views: dereferencing pointer does break strict-aliasing rules
Yury V. Zaytsev
yury at shurup.com
Thu Jul 4 17:34:45 CEST 2013
Hi Robert,
On Tue, 2013-07-02 at 09:07 -0700, Robert Bradshaw wrote:
>
> You should compile with -fno-strict-aliasing--if you were using
> distutils rather than gcc directly it should add the all necessary
> flags for you.
Indeed, I'm using autotools to compile the module, so now I've added the
AX_CHECK_COMPILE_FLAG macro from the Autoconf Archive to check whether
-fno-strict-aliasing is supported by the compiler and append it to
CXXFLAGS if necessary.
> Aliasing different pointer types is necessary for Cython--it's how it
> implements inheritance (in plain C, a PyObject* could be a pointer to
> a list or dict or your own cdef class--pointer aliasing right there.
> Also with memory views (and numpy arrays), the underlying data is
> allocated as a char* and interpreted as a float* or int* or according
> to the metadata in the array.
Thank you very much for this explanation, I just wanted to make sure
that this is unavoidable!
--
Sincerely yours,
Yury V. Zaytsev
More information about the cython-devel
mailing list