If a C++ templated function has more than one template argument, it cannot be used inside a "with nogil:" block, at least in 0.21.1, the version in debian sid. I have attached a MWE:
cythonside1.pyx does not use nogil, compiles and runs fine.
cythonside2.pyx uses nogil, fails to compile with the following error:
Error compiling Cython file:
...
def test():
cdef int arg
with nogil:
fun[&arg)
^
cythonside2.pyx:9:7: Constructing Python tuple not allowed without gil
cside.cpp:
template<typename A, typename B> void fun(A arg1, B arg2) {
printf("In fun\n");
}
template void fun(int arg1, int arg2);
cside.cppcythonside1.pyx:
cdef extern from "cside.hpp" nogil:
void fun[A,B](int,int](&arg,)(A arg1, B arg2)
def test():
cdef int arg
fun[&arg)
cside.cppcythonside2.pyx:
cdef extern from "cside.hpp" nogil:
void fun[A,B](int,int](&arg,)(A arg1, B arg2)
def test():
cdef int arg
with nogil:
fun[int,int](&arg, &arg)
At 2015-04-27T19:07:27Z josedavid added attachment cythonbug.zip
If a C++ templated function has more than one template argument, it cannot be used inside a "with nogil:" block, at least in 0.21.1, the version in debian sid. I have attached a MWE:
cythonside1.pyx does not use nogil, compiles and runs fine.
cythonside2.pyx uses nogil, fails to compile with the following error:
Error compiling Cython file:
...
def test(): cdef int arg with nogil: fun[&arg)
^
cythonside2.pyx:9:7: Constructing Python tuple not allowed without gil
template<typename A, typename B> void fun(A arg1, B arg2) { printf("In fun\n"); }
template void fun(int arg1, int arg2);
cdef extern from "cside.hpp" nogil: void fun[A,B](int,int](&arg,)(A arg1, B arg2)
def test(): cdef int arg fun[&arg)
cdef extern from "cside.hpp" nogil: void fun[A,B](int,int](&arg,)(A arg1, B arg2)
def test(): cdef int arg with nogil: fun[int,int](&arg, &arg)
At 2015-04-27T19:07:27Z josedavid added attachment cythonbug.zip
Migrated from http://trac.cython.org/ticket/848