Doing so just makes all methods implicitly nogil. This also makes nogil
on a cdef extern from statement do the right thing to cppclasses (and
their methods) contained inside.
---
Cython/Compiler/Parsing.py | 3 ++-
tests/compile/cpp_nogil.h | 9 +++++++++
tests/compile/cpp_nogil.pyx | 18 ++++++++++++++++++
3 files changed, 29 insertions(+), 1 deletion(-)
create mode 100644 tests/compile/cpp_nogil.h
create mode 100644 tests/compile/cpp_nogil.pyx
base_classes = []
if s.sy == '[':
error(s.position(), "Name options not allowed for C++ class")
+ nogil = p_nogil(s)
if s.sy == ':':
s.next()
s.expect('NEWLINE')
s.expect_indent()
attributes = []
- body_ctx = Ctx(visibility = ctx.visibility, level='cpp_class')
+ body_ctx = Ctx(visibility = ctx.visibility, level='cpp_class', nogil=nogil or ctx.nogil)
body_ctx.templates = templates
while s.sy != 'DEDENT':
if s.systring == 'cppclass':
--- /dev/null
+struct NoGilTest1 {
+ NoGilTest1() { }
+ void doSomething() { }
+};
+
+struct NoGilTest2 {
+ NoGilTest2() { }
+ void doSomething() { }
+};
--- /dev/null
+# tag: cpp
+# mode: compile
+
+cdef extern from "cpp_nogil.h" nogil:
+ cdef cppclass NoGilTest1:
+ NoGilTest1()
+ void doSomething()
+
+# This is declared in cpp_nogil.h, but here we're testing
+# that we can put nogil directly on the cppclass.
+cdef extern from *:
+ cdef cppclass NoGilTest2 nogil:
+ NoGilTest2()
+ void doSomething()
+
+with nogil:
+ NoGilTest1().doSomething()
+ NoGilTest2().doSomething()