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

Initializing array with values requires GIL? #3160

Open
jakirkham opened this issue Oct 1, 2019 · 1 comment

Comments

@jakirkham
Copy link
Contributor

commented Oct 1, 2019

When trying to compile the following code with Cython, I get the error message below.

cdef void func() nogil: 
    cdef int[4] a = [0, 1, 2, 3]
/Users/jkirkham/miniconda/envs/cython/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /Users/jkirkham/test.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
cdef void func() nogil: 
    cdef int[4] a = [0, 1, 2, 3]
        ^
------------------------------------------------------------

test.pyx:2:9: Slicing Python object not allowed without gil

Dropping the nogil makes the error go away. However the C code generated looks something like this and as such doesn't appear to be using the GIL.

static void __pyx_f_4test_func(void) {
  ...

  int __pyx_t_1[4];

  __pyx_t_1[0] = 0;
  __pyx_t_1[1] = 1;
  __pyx_t_1[2] = 2;
  __pyx_t_1[3] = 3;

  ...
}
@jakirkham

This comment has been minimized.

Copy link
Contributor Author

commented Oct 1, 2019

Also if I write the code like so, it appears I've run into issue ( #1662 ).

cdef void func() nogil: 
    cdef int[4] a
    a[:] = [0, 1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.