Repository: PyAV-Org/PyAV

Issue #339: OverflowError: Python int too large to convert to C long
Created: 2018-06-19T10:06:49Z
This error happening just importing the av library (on Python 3.4.3), not even starting using it.
File "av/enums.pyx", line 145, in av.enums.EnumItem.cinit
The full trace:
File "/usr/local/lib/python3.4/dist-packages/av/__init__.py", line 15, in <module>
    from av.audio.fifo import AudioFifo
  File "/usr/local/lib/python3.4/dist-packages/av/audio/__init__.py", line 1, in <module>
    from .frame import AudioFrame
  File "av/audio/frame.pyx", line 1, in init av.audio.frame
  File "av/codec/codec.pxd", line 6, in init av.frame
  File "/usr/local/lib/python3.4/dist-packages/av/codec/__init__.py", line 1, in <module>
    from .codec import Codec, codecs_available, codec_descriptor
  File "av/descriptor.pxd", line 4, in init av.codec.codec
  File "av/option.pxd", line 4, in init av.descriptor
  File "av/option.pyx", line 18, in init av.option
  File "av/enums.pyx", line 225, in av.enums.define_enum
  File "av/enums.pyx", line 28, in av.enums.EnumType._init
  File "av/enums.pyx", line 32, in av.enums.EnumType._create
  File "av/enums.pyx", line 145, in av.enums.EnumItem.__cinit__
OverflowError: Python int too large to convert to C long

Here is where the trace points to:
cdef class EnumItem(object):

    cdef readonly str name
    cdef readonly long value #int
    cdef long _hash

    def __cinit__(self, sentinel_, name, value):

        if sentinel_ is not sentinel:
            raise RuntimeError("Cannot instantiate {}.".format(self.__class__.__name__))
        self.name = name
        self.value = value

        # Establish a hash that doesn't collide with anything that would return
        # true from __eq__.
        hash_ = id(self)
        name_hash = hash(name)
        value_hash = hash(value)
        while hash_ == name_hash or hash_ == value_hash:
            hash_ += 1
        self._hash = hash_ # <--- here is where the trace points to !!!

I've tried lot of things but nothing goes. Any idea?
Thanks!

Duplicate issue #341: Cython 0.28, enums.pyx "OverflowError: Python int too large to convert to C long"
Created: 2018-07-02T10:01:49Z
I could pip install pyav on linux arm with cython 0.28, but when i try to import it i get:
>>> import av
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tangible/.local/lib/python2.7/site-packages/av/__init__.py", line 15, in <module>
    from av.audio.fifo import AudioFifo
  File "/home/tangible/.local/lib/python2.7/site-packages/av/audio/__init__.py", line 1, in <module>
    from .frame import AudioFrame
  File "av/audio/frame.pyx", line 1, in init av.audio.frame
  File "av/codec/codec.pxd", line 6, in init av.frame
  File "/home/tangible/.local/lib/python2.7/site-packages/av/codec/__init__.py", line 1, in <module>
    from .codec import Codec, codecs_available, codec_descriptor
  File "av/descriptor.pxd", line 4, in init av.codec.codec
  File "av/option.pxd", line 4, in init av.descriptor
  File "av/option.pyx", line 18, in init av.option
  File "av/enums.pyx", line 225, in av.enums.define_enum
  File "av/enums.pyx", line 28, in av.enums.EnumType._init
  File "av/enums.pyx", line 32, in av.enums.EnumType._create
  File "av/enums.pyx", line 145, in av.enums.EnumItem.__cinit__
OverflowError: Python int too large to convert to C long

i can see that it's from this bit of code.
        # Establish a hash that doesn't collide with anything that would return
        # true from __eq__.
        hash_ = id(self)
        name_hash = hash(name)
        value_hash = hash(value)
        while hash_ == name_hash or hash_ == value_hash:
            hash_ += 1
        self._hash = hash_

the last one being 145.
If i change _hash declaration to.
cdef unsigned long _hash

Then i can import it correctly.
Doing a PR.

Closing comment (2018-07-02T10:07:48Z): Duplicate of #339. Therefore, your PR, #342, is actually a fix for that.