[Cython] Bug: Extension Type inheriting from int cause a MemoryError

Stephen LARROQUE lrq3000 at gmail.com
Mon Jun 15 12:34:35 CEST 2015


Hello,

I am trying to make an extension type inheriting from int or cython.int (to
do arithmetic operations in Galois Fields). However, this causes a
MemoryError because it seems such extension type is not freed correctly.
Other than that, it works perfectly well.

Here is a test case to reproduce the bug on Python 2.7.9 Win32 (I'm running
Windows 7, but it may happen on other platform, I did not test) with Cython
v0.22 on Anaconda:

########################
# mode: run

import sys

cdef class ExtendedInt(int): pass

_ERRORS = u"""
MemoryError
"""

# Simple test case to raise a MemoryError by generating lots of ExtendedInt
total_it = 1000
for i in xrange(total_it):
    for j in xrange(10000000):
        ExtendedInt(j)
    sys.stdout.write("\rGenerating lists of ExtendedInt : %i/%i" % (i,
total_it))
########################

My current workaround as advised in the cython-users list:
https://groups.google.com/forum/#!topic/cython-users/WJ5BJ5moAh4

is to inherit from standard (object) and then reimplement all int magic
methods, which is cumbersome and less optimized, but at least there's no
MemoryError.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20150615/caee9b94/attachment.html>


More information about the cython-devel mailing list