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

Stephen LARROQUE lrq3000 at gmail.com
Mon Jun 15 12:37:24 CEST 2015


Addendum: I tried to define __weakref__ and __dealloc__, but this did
nothing to solve the issue.

2015-06-15 12:34 GMT+02:00 Stephen LARROQUE <lrq3000 at gmail.com>:

> 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/48c787d2/attachment.html>


More information about the cython-devel mailing list