From 1e3911ed39840b6ed899bbd408bb67b540a49db6 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 30 Jul 2015 10:33:54 +0300 Subject: [PATCH] Use try..finally in compiler.targets.Target.link. --- artiq/compiler/targets/__init__.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/artiq/compiler/targets/__init__.py b/artiq/compiler/targets/__init__.py index 141a7433f..e0715674b 100644 --- a/artiq/compiler/targets/__init__.py +++ b/artiq/compiler/targets/__init__.py @@ -8,7 +8,7 @@ llvm.initialize_all_asmprinters() class Target: """ A description of the target environment where the binaries - generaed by the ARTIQ compiler will be deployed. + generated by the ARTIQ compiler will be deployed. :var triple: (string) LLVM target triple, e.g. ``"or1k"`` @@ -36,21 +36,20 @@ class Target: f.flush() return f - output_file = make_tempfile() - cmdline = [self.triple + "-ld", "-shared", "--eh-frame-hdr", "-init", init_fn] + \ - [make_tempfile(obj).name for obj in objects] + \ - ["-o", output_file.name] - linker = subprocess.Popen(cmdline, stderr=subprocess.PIPE) - stdout, stderr = linker.communicate() - if linker.returncode != 0: - raise Exception("Linker invocation failed: " + stderr.decode('utf-8')) + try: + output_file = make_tempfile() + cmdline = [self.triple + "-ld", "-shared", "--eh-frame-hdr", "-init", init_fn] + \ + [make_tempfile(obj).name for obj in objects] + \ + ["-o", output_file.name] + linker = subprocess.Popen(cmdline, stderr=subprocess.PIPE) + stdout, stderr = linker.communicate() + if linker.returncode != 0: + raise Exception("Linker invocation failed: " + stderr.decode('utf-8')) - output = output_file.read() - - for f in files: - f.close() - - return output + return output_file.read() + finally: + for f in files: + f.close() def compile(self, module): """Compile the module to a relocatable object for this target."""