summaryrefslogtreecommitdiff
path: root/giscanner/scannermain.py
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2020-11-07 08:54:50 +0100
committerChristoph Reiter <reiter.christoph@gmail.com>2020-11-07 09:35:02 +0100
commitdd378ee46082862f711629d40ed33f944d1e3259 (patch)
tree4cf8e3f30f534cf4bc481d5eb1bb8977fe940d1f /giscanner/scannermain.py
parent5f966b0b8d61e2abf003439b2f93a9bd19be798c (diff)
downloadgobject-introspection-dd378ee46082862f711629d40ed33f944d1e3259.tar.gz
Always close files
This means flushing changes and closing the fd. Otherwise this is done by the GC eventually.. Detected using PYTHONTRACEMALLOC=1 PYTHONDEVMODE=1
Diffstat (limited to 'giscanner/scannermain.py')
-rw-r--r--giscanner/scannermain.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index f80b2cfe..957ba0b7 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -472,6 +472,10 @@ def write_output(data, options):
"""Write encoded XML 'data' to the filename specified in 'options'."""
if options.output == "-":
output = sys.stdout
+ try:
+ output.write(data)
+ except IOError as e:
+ _error("while writing output: %s" % (e.strerror, ))
elif options.reparse_validate_gir:
main_f, main_f_name = tempfile.mkstemp(suffix='.gir')
@@ -500,14 +504,10 @@ def write_output(data, options):
return 0
else:
try:
- output = open(options.output, 'wb')
+ with open(options.output, 'wb') as output:
+ output.write(data)
except IOError as e:
- _error("opening output for writing: %s" % (e.strerror, ))
-
- try:
- output.write(data)
- except IOError as e:
- _error("while writing output: %s" % (e.strerror, ))
+ _error("opening/writing output: %s" % (e.strerror, ))
def get_source_root_dirs(options, filenames):