[gnome-code-assistance/wip/completion_python: 1/2] c: add helper file-like object named UnsavedFile
- From: Igor Gnatenko <ignatenko src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-code-assistance/wip/completion_python: 1/2] c: add helper file-like object named UnsavedFile
- Date: Mon, 12 Jan 2015 13:32:11 +0000 (UTC)
commit c8aa1c48a9d66faa2b487f2f210778f1841c586f
Author: Christian Hergert <christian hergert me>
Date: Mon Jan 12 02:00:24 2015 -0800
c: add helper file-like object named UnsavedFile
This helps avoid the situation where a read() is done after the file
has been closed when ensuring a TU is up to date.
backends/c/service.py | 28 ++++++++++++++++++++++++++--
1 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/backends/c/service.py b/backends/c/service.py
index 11401fc..82f0bd3 100644
--- a/backends/c/service.py
+++ b/backends/c/service.py
@@ -24,6 +24,25 @@ import glob, os, subprocess
_did_libclang_config = False
_global_sysinclude = None
+class UnsavedFile(object):
+ def __init__(self, *args, **kwargs):
+ self._file = open(*args, **kwargs)
+
+ def close(self, do_close=False):
+ if do_close:
+ self._file.close()
+ else:
+ self._file.seek(0)
+
+ def read(self, *args, **kwargs):
+ return self._file.read(*args, **kwargs)
+
+ def tell(self):
+ return self._file.tell()
+
+ def seek(self, *args, **kwargs):
+ return self._file.seek(*args, **kwargs)
+
def config_libclang():
global _did_libclang_config
global _global_sysinclude
@@ -168,11 +187,16 @@ class Service(transport.Service, transport.Project,
def complete(self, doc, options):
if doc.data_path != doc.path:
- unsaved = [(doc.path, open(doc.data_path, 'rb'))]
+ unsaved = [(doc.path, UnsavedFile(doc.data_path, 'rb'))]
else:
unsaved = []
- self._complete(doc, [doc], unsaved, options)
+ ret = self._complete(doc, [doc], unsaved, options)
+
+ for (_,f) in unsaved:
+ f.close(do_close=True)
+
+ return ret
def _included_docs(self, doc, docmap):
includes = doc.tu.get_includes()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]