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

[BUG] broken C code generated: variable undeclared #6473

Open
matwey opened this issue Oct 31, 2024 · 1 comment
Open

[BUG] broken C code generated: variable undeclared #6473

matwey opened this issue Oct 31, 2024 · 1 comment

Comments

@matwey
Copy link

matwey commented Oct 31, 2024

Describe the bug

Hello,

I am running Cython 3.0.11 with gcc 7.5.0. When I compile attached minimal example I see the following issue with C compiler:

      src/chunksize/my.c: In function ‘__pyx_f_2my__foo’:
      src/chunksize/my.c:4743:33: error: ‘__pyx_v_chunksize’ undeclared (first use in this function); did you mean ‘__pyx_k_chunksize’?
                           __pyx_t_3 = __pyx_v_chunksize;
                                       ^~~~~~~~~~~~~~~~~
                                       __pyx_k_chunksize
      src/chunksize/my.c:4743:33: note: each undeclared identifier is reported only once for each function it appears in

Code to reproduce the behaviour:

import numpy as np
from cython.parallel cimport prange, parallel

cimport numpy as np
cimport cython

def foo(int chunksize=0):
        return _foo(chunksize)

@cython.boundscheck(False)
@cython.wraparound(False)
cdef void _foo(int chunksize=0):
        cdef Py_ssize_t x_index

        with nogil, parallel():
                for x_index in prange(1024, schedule='static', chunksize=chunksize):
                        pass

Expected behaviour

The code compiled successfully.

OS

Linux

Python version

3.11.9

Cython version

3.0.11

Additional context

No response

matwey added a commit to snad-space/coniferest that referenced this issue Oct 31, 2024
@da-woods
Copy link
Contributor

If you add x = chunksize or even <void>chunksize before the with nogil, parallel() block then it works.

I think it only unpacks the optional arguments that it believes are used, and it somehow misses the use as an argument to prange.

Definitely a bug though, thanks

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

No branches or pull requests

2 participants