[Cython] Segfault with large cdef'd list

Dan Stromberg drsalists at gmail.com
Mon Jan 8 15:36:24 EST 2018


On Sun, Jan 7, 2018 at 2:18 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Robert Bradshaw schrieb am 07.01.2018 um 09:48:
>> Cython itself doesn't impose any limits, but it does inherit whatever
>> limit exists in the C complier and runtime. The variance may be due to
>> whatever else happens to be placed on the stack.
>
> Let me add that I wouldn't consider it a good idea to allocate large chunks
> of memory on the stack. If it's meant to hold substantial amounts of data
> (which also suggests that there is a substantial amount of processing
> and/or copying involved), it's probably also worth a [PyMem_]malloc() call.
> Heap allocation allows you to respond to allocation failures with a
> MemoryError rather than a crash, as you get now. How much stack space you
> have left is user controlled through call depth and recursion, which makes
> it a somewhat easy target.

Thanks - it's working now with malloc() and free().

Code at:
http://stromberg.dnsalias.org/svn/why-is-python-slow/trunk/cython3_types_t.pyx

It turns out the 2.x and 3.x versions are identical.  :)


More information about the cython-devel mailing list