From: Stefan Behnel Date: Fri, 12 Nov 2010 07:19:23 +0000 (+0100) Subject: timely close Cython source file when generating C source comments X-Git-Tag: 0.14.alpha0~181 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0f5d7221238c42e2a41c97cdd40482568e5251d9;p=cython.git timely close Cython source file when generating C source comments --- diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 1066e9fe..fde29429 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -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