Commit a1e80790 authored by Stefan Behnel's avatar Stefan Behnel

use 'with GIL' instead of 'withGIL' to avoid introducing a non-Python keyword...

use 'with GIL' instead of 'withGIL' to avoid introducing a non-Python keyword and to support later extension for other contexts
parent b356ac87
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import os, re import os, re
from string import join, replace from string import join, replace
from types import ListType, TupleType from types import ListType, TupleType
from Scanning import PyrexScanner from Scanning import PyrexScanner, function_contexts
import Nodes import Nodes
import ExprNodes import ExprNodes
from ModuleNode import ModuleNode from ModuleNode import ModuleNode
...@@ -1477,28 +1477,33 @@ def p_exception_value_clause(s): ...@@ -1477,28 +1477,33 @@ def p_exception_value_clause(s):
exc_val = p_simple_expr(s) #p_exception_value(s) exc_val = p_simple_expr(s) #p_exception_value(s)
return exc_val, exc_check return exc_val, exc_check
def p_c_with_gil(s): def p_c_with(s):
if s.sy == 'withGIL': if s.sy == 'with':
s.next() s.next()
return True return p_ident_list(s)
return False return ()
def p_c_func_options(s): def p_c_func_options(s):
exc_val = None exc_val = None
exc_check = 0 exc_check = 0
with_gil = False contexts = []
if s.sy == 'except': if s.sy == 'except':
exc_val, exc_check = p_exception_value_clause(s) exc_val, exc_check = p_exception_value_clause(s)
with_gil = p_c_with_gil(s) contexts = p_c_with(s)
elif s.sy == 'withGIL': elif s.sy == 'with':
with_gil = p_c_with_gil(s) contexts = p_c_with(s)
exc_val, exc_check = p_exception_value_clause(s) exc_val, exc_check = p_exception_value_clause(s)
for context in contexts:
if context not in function_contexts:
s.error("Unknown context: " + context)
return None
ret = { ret = {
'exception_value': exc_val, 'exception_value': exc_val,
'exception_check': exc_check, 'exception_check': exc_check,
'with_gil': with_gil, 'with_gil': 'GIL' in contexts,
} }
return ret return ret
......
...@@ -596,7 +596,7 @@ class CFuncType(CType): ...@@ -596,7 +596,7 @@ class CFuncType(CType):
elif self.exception_check: elif self.exception_check:
exc_clause = " except *" exc_clause = " except *"
if self.with_gil: if self.with_gil:
with_gil_clause = " withGIL" with_gil_clause = " with GIL"
return self.return_type.declaration_code( return self.return_type.declaration_code(
"(%s(%s)%s%s)" % (entity_code, arg_decl_code, "(%s(%s)%s%s)" % (entity_code, arg_decl_code,
exc_clause, with_gil_clause), exc_clause, with_gil_clause),
......
...@@ -138,7 +138,11 @@ reserved_words = [ ...@@ -138,7 +138,11 @@ reserved_words = [
"raise", "import", "exec", "try", "except", "finally", "raise", "import", "exec", "try", "except", "finally",
"while", "if", "elif", "else", "for", "in", "assert", "while", "if", "elif", "else", "for", "in", "assert",
"and", "or", "not", "is", "in", "lambda", "from", "and", "or", "not", "is", "in", "lambda", "from",
"NULL", "cimport", "by", "withGIL" "NULL", "cimport", "by", "with"
]
function_contexts = [ # allowed arguments to the "with" option
"GIL"
] ]
class Method: class Method:
......
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