"from cython cimport boundscheck" working
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Tue, 5 Aug 2008 17:47:49 +0000 (19:47 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Tue, 5 Aug 2008 17:47:49 +0000 (19:47 +0200)
Cython/Compiler/ParseTreeTransforms.py
tests/compile/c_options.pyx

index 983c2b99cfc233ad1eacf68e9a57baaf6e01614b..5523d2615c90b97e6ca4a41be229c73fb7dcd227 100644 (file)
@@ -276,6 +276,7 @@ class ResolveOptions(CythonTransform):
         super(ResolveOptions, self).__init__(context)
         self.compilation_option_overrides = compilation_option_overrides
         self.cython_module_names = set()
+        self.option_names = {}
 
     def visit_ModuleNode(self, node):
         options = copy.copy(Options.option_defaults)
@@ -294,8 +295,21 @@ class ResolveOptions(CythonTransform):
             else:
                 modname = u"cython"
             self.cython_module_names.add(modname)
-        elif node.as_name and node.as_name in self.cython_module_names:
-            self.cython_module_names.remove(node.as_name)
+        return node
+    
+    def visit_FromCImportStatNode(self, node):
+        if node.module_name == u"cython":
+            newimp = []
+            for pos, name, as_name, kind in node.imported_names:
+                if name in Options.option_types:
+                    self.option_names[as_name] = name
+                    if kind is not None:
+                        self.context.nonfatal_error(PostParseError(pos,
+                            "Compiler option imports must be plain imports"))
+                    return None
+                else:
+                    newimp.append((pos, name, as_name, kind))
+            node.imported_names = newimpo
         return node
 
     def visit_Node(self, node):
@@ -307,11 +321,17 @@ class ResolveOptions(CythonTransform):
         # If node is the contents of an option (in a with statement or
         # decorator), returns (optionname, value).
         # Otherwise, returns None
-        if (isinstance(node, SimpleCallNode) and
-              isinstance(node.function, AttributeNode) and
-              isinstance(node.function.obj, NameNode) and
-              node.function.obj.name in self.cython_module_names):
-            optname = node.function.attribute
+        optname = None
+        if isinstance(node, SimpleCallNode):
+            if (isinstance(node.function, AttributeNode) and
+                  isinstance(node.function.obj, NameNode) and
+                  node.function.obj.name in self.cython_module_names):
+                optname = node.function.attribute
+            elif (isinstance(node.function, NameNode) and
+                  node.function.name in self.option_names):
+                optname = self.option_names[node.function.name]
+
+        if optname:
             optiontype = Options.option_types.get(optname)
             if optiontype:
                 args = node.args
@@ -322,12 +342,8 @@ class ResolveOptions(CythonTransform):
                     return (optname, args[0].value)
                 else:
                     assert False
-            else:
-                return None
-            options.append((dec.function.attribute, dec.args, dec.function.pos))
-            return False
-        else:
-            return None
+
+        return None
 
     def visit_with_options(self, node, options):
         oldoptions = self.options
index 8f7dac7c2294caa2767730f052eec748f576f825..c638cb19682b85401269e8d72451f2e2ac577ad5 100644 (file)
@@ -19,3 +19,10 @@ def h(object[int, 2] buf):
     print buf[3, 2]
     with cy.boundscheck(True):
         print buf[3,2]
+
+from cython cimport boundscheck as bc
+
+def i(object[int] buf):
+    with bc(True):
+        print buf[3]
+