Skip to content

[BUG] Segmentation fault with loop over memoryview followed by an exception #4662

@da-woods

Description

@da-woods

Describe the bug

Iterating over a memoryview in a generator expression causes a crash (on cleanup I think). pandas-dev/pandas#46029 (comment)

To Reproduce
Code to reproduce the behaviour:

# testmviewbug.pyx
def f(const double[:] qs):
    for x in qs:
        pass
    raise ValueError()

Build it with cythonize -if testmviewbug.pyx

and run it in python to give:

>>> import testmviewbug
>>> import numpy as np
>>> testmviewbug.f(np.array([1.,2.,3.0]))
Fatal Python error: Acquisition count is -1 (line 3421)
Python runtime state: initialized
Traceback (most recent call last):
  File "testmviewbug.pyx", line 4, in testmviewbug.f
    raise ValueError()
ValueError
Aborted (core dumped)

Expected behavior
No crash

Environment (please complete the following information):

  • OS: [e.g. Linux, Windows, macOS]
  • Python version 3.8.12
  • Cython version current master

Additional context

Bisect says it started in ab1d728, which makes sense because it's a commit that'd significantly change what was generated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions