Disallow deletion of C global variables
authorVitja Makarov <vitja.makarov@gmail.com>
Sat, 25 May 2013 08:28:24 +0000 (12:28 +0400)
committerVitja Makarov <vitja.makarov@gmail.com>
Sun, 26 May 2013 07:47:32 +0000 (11:47 +0400)
Cython/Compiler/Nodes.py
tests/errors/e_del.pyx

index 7df70b0..fc72b89 100644 (file)
@@ -4848,7 +4848,8 @@ class DelStatNode(StatNode):
             arg = self.args[i] = arg.analyse_target_expression(env, None)
             if arg.type.is_pyobject or (arg.is_name and
                                         arg.type.is_memoryviewslice):
-                pass
+                if arg.is_name and arg.entry.is_cglobal:
+                    error(arg.pos, "Deletion of global C variable")
             elif arg.type.is_ptr and arg.type.base_type.is_cpp_class:
                 self.cpp_check(env)
             elif arg.type.is_cpp_class:
index 45910d8..64171b1 100644 (file)
@@ -19,6 +19,9 @@ def outer(a):
     del a
     return inner()
 
+cdef object g
+del g
+
 
 _ERRORS = u"""
 10:9: Cannot assign to or delete this
@@ -26,4 +29,5 @@ _ERRORS = u"""
 13:9: Deletion of non-Python, non-C++ object
 14:9: Deletion of non-Python, non-C++ object
 19:9: can not delete variable 'a' referenced in nested scope
+23:5: Deletion of global C variable
 """