timely close Cython source file when generating C source comments
authorStefan Behnel <scoder@users.berlios.de>
Fri, 12 Nov 2010 07:19:23 +0000 (08:19 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 12 Nov 2010 07:19:23 +0000 (08:19 +0100)
Cython/Compiler/Code.py

index 1066e9fe4a4bc1d223428c2f62006c1ab226b6ea..fde29429fe52b8de536168801f5e1df8029ab6b0 100644 (file)
@@ -759,16 +759,22 @@ class GlobalState(object):
         try:
             return self.input_file_contents[source_desc]
         except KeyError:
+            pass
+        source_file = source_desc.get_lines(encoding='ASCII',
+                                            error_handling='ignore')
+        try:
             F = [u' * ' + line.rstrip().replace(
                     u'*/', u'*[inserted by cython to avoid comment closer]/'
                     ).replace(
                     u'/*', u'/[inserted by cython to avoid comment start]*'
                     )
-                 for line in source_desc.get_lines(encoding='ASCII',
-                                                   error_handling='ignore')]
-            if len(F) == 0: F.append(u'')
-            self.input_file_contents[source_desc] = F
-            return F
+                 for line in source_file]
+        finally:
+            if hasattr(source_file, 'close'):
+                source_file.close()
+        if not F: F.append(u'')
+        self.input_file_contents[source_desc] = F
+        return F
 
     #
     # Utility code state