Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unterminated string literal causes cython compiler to go into an infinite loop. #5977

Closed
culler opened this issue Feb 5, 2024 · 2 comments · Fixed by #5994
Closed

Unterminated string literal causes cython compiler to go into an infinite loop. #5977

culler opened this issue Feb 5, 2024 · 2 comments · Fixed by #5994

Comments

@culler
Copy link

culler commented Feb 5, 2024

Describe the bug

Running cythonize bug.pyx on the following file bug.pyx hangs:

# cython: language_level=3str

class Bug():
    """Cythonizing this creates an infinite loop."""

    something = "hello"
    
    def dumb(self):
        print("Say something: %s'%self.something)
 
# Local Variables:
# mode: Python
# End

The traceback produced by hitting Control-C says:

Dependencies.py", line 509, in parse_dependencies
    source, literals = strip_string_literals(source)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/culler/Library/Python/3.12/lib/python/site-packages/Cython/Build/Dependencies.py", line 349, in strip_string_literals
    while True:
          ^^^^

Code to reproduce the behaviour:

cythonize bug.pyx

Expected behaviour

An error message saying that the file contains an unterminated string literal.

OS

linux and macOS, at least

Python version

3.10 on linux and 3.12 on macOS

Cython version

3.0.8

Additional context

No response

scoder added a commit to scoder/cython that referenced this issue Feb 11, 2024
@scoder scoder added this to the 3.1 milestone Feb 11, 2024
@scoder
Copy link
Contributor

scoder commented Feb 11, 2024

Thanks for the report and the reproducer. That function was bound to be reimplemented at some point, so I just did that in #5994.

@culler
Copy link
Author

culler commented Feb 11, 2024

Thanks!!!

scoder added a commit that referenced this issue Feb 13, 2024
Reimplement "Dependencies.strip_string_literals()" to handle unclosed string literals and recursive f-strings.

Closes #5977
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants