use 'with GIL' instead of 'withGIL' to avoid introducing a non-Python keyword and...
authorStefan Behnel <scoder@users.berlios.de>
Tue, 11 Sep 2007 19:12:49 +0000 (21:12 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 11 Sep 2007 19:12:49 +0000 (21:12 +0200)
Cython/Compiler/Parsing.py
Cython/Compiler/PyrexTypes.py
Cython/Compiler/Scanning.py

index 08a40d942689700ed32b7730c1501539e65df7dc..9ed276397234840ea7ff67a6d4f47a574ae3ac6c 100644 (file)
@@ -5,7 +5,7 @@
 import os, re
 from string import join, replace
 from types import ListType, TupleType
-from Scanning import PyrexScanner
+from Scanning import PyrexScanner, function_contexts
 import Nodes
 import ExprNodes
 from ModuleNode import ModuleNode
@@ -1477,28 +1477,33 @@ def p_exception_value_clause(s):
             exc_val = p_simple_expr(s) #p_exception_value(s)
     return exc_val, exc_check
 
-def p_c_with_gil(s):
-    if s.sy == 'withGIL':
+def p_c_with(s):
+    if s.sy == 'with':
         s.next()
-        return True
-    return False
+        return p_ident_list(s)
+    return ()
 
 def p_c_func_options(s):
     exc_val = None
     exc_check = 0
-    with_gil = False
+    contexts = []
 
     if s.sy == 'except':
         exc_val, exc_check = p_exception_value_clause(s)
-        with_gil = p_c_with_gil(s)
-    elif s.sy == 'withGIL':
-        with_gil = p_c_with_gil(s)
+        contexts = p_c_with(s)
+    elif s.sy == 'with':
+        contexts = p_c_with(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 = {
         'exception_value': exc_val,
         'exception_check': exc_check,
-        'with_gil': with_gil,
+        'with_gil': 'GIL' in contexts,
         }
 
     return ret
index a19033d3719396295131aaf9f8ad215a8f4e10d0..d05db0ce98431676b2c094debed9c8cf74ea7d90 100644 (file)
@@ -596,7 +596,7 @@ class CFuncType(CType):
             elif self.exception_check:
                 exc_clause = " except *"
             if self.with_gil:
-                with_gil_clause = " withGIL"
+                with_gil_clause = " with GIL"
         return self.return_type.declaration_code(
             "(%s(%s)%s%s)" % (entity_code, arg_decl_code,
                               exc_clause, with_gil_clause),
index d57137626964a57255f2908ec3df011ee924ea7e..48ae39aff322b895838802edfd5a8fa7058d5173 100644 (file)
@@ -138,7 +138,11 @@ reserved_words = [
     "raise", "import", "exec", "try", "except", "finally",
     "while", "if", "elif", "else", "for", "in", "assert",
     "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: