Commit f0e32c2e authored by John Stumpo's avatar John Stumpo

Allow cppclasses to be declared nogil.

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
parent aa012cc8
......@@ -3128,12 +3128,13 @@ def p_cpp_class_definition(s, pos, ctx):
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':
......
struct NoGilTest1 {
NoGilTest1() { }
void doSomething() { }
};
struct NoGilTest2 {
NoGilTest2() { }
void doSomething() { }
};
# 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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment