[Lldb-commits] [PATCH] D28356: Consolidate file handle usage in Editline.cpp

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 6 01:38:31 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL291220: Consolidate file handle usage in Editline.cpp (authored by labath).

Changed prior to commit:
  https://reviews.llvm.org/D28356?vs=83237&id=83351#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28356

Files:
  lldb/trunk/include/lldb/Host/Editline.h
  lldb/trunk/source/Host/common/Editline.cpp


Index: lldb/trunk/source/Host/common/Editline.cpp
===================================================================
--- lldb/trunk/source/Host/common/Editline.cpp
+++ lldb/trunk/source/Host/common/Editline.cpp
@@ -526,17 +526,8 @@
     }
 
     if (read_count) {
-#if LLDB_EDITLINE_USE_WCHAR
-      // After the initial interruptible read, this is guaranteed not to block
-      ungetc(ch, m_input_file);
-      *c = fgetwc(m_input_file);
-      if (*c != WEOF)
-        return 1;
-#else
-      *c = ch;
-      if (ch != (char)EOF)
+      if (CompleteCharacter(ch, *c))
         return 1;
-#endif
     } else {
       switch (status) {
       case lldb::eConnectionStatusSuccess: // Success
@@ -1367,3 +1358,39 @@
     MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
   }
 }
+
+bool Editline::CompleteCharacter(char ch, EditLineCharType &out) {
+#if !LLDB_EDITLINE_USE_WCHAR
+  if (ch == (char)EOF)
+    return false;
+
+  out = ch;
+  return true;
+#else
+  std::codecvt_utf8<wchar_t> cvt;
+  llvm::SmallString<4> input;
+  for (;;) {
+    const char *from_next;
+    wchar_t *to_next;
+    std::mbstate_t state = std::mbstate_t();
+    input.push_back(ch);
+    switch (cvt.in(state, input.begin(), input.end(), from_next, &out, &out + 1,
+                   to_next)) {
+    case std::codecvt_base::ok:
+      return out != WEOF;
+
+    case std::codecvt_base::error:
+    case std::codecvt_base::noconv:
+      return false;
+
+    case std::codecvt_base::partial:
+      lldb::ConnectionStatus status;
+      size_t read_count = m_input_connection.Read(
+          &ch, 1, std::chrono::seconds(0), status, nullptr);
+      if (read_count == 0)
+        return false;
+      break;
+    }
+  }
+#endif
+}
Index: lldb/trunk/include/lldb/Host/Editline.h
===================================================================
--- lldb/trunk/include/lldb/Host/Editline.h
+++ lldb/trunk/include/lldb/Host/Editline.h
@@ -322,6 +322,8 @@
   /// single or multi-line editing.
   void ConfigureEditor(bool multiline);
 
+  bool CompleteCharacter(char ch, EditLineCharType &out);
+
 private:
 #if LLDB_EDITLINE_USE_WCHAR
   std::wstring_convert<std::codecvt_utf8<wchar_t>> m_utf8conv;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28356.83351.patch
Type: text/x-patch
Size: 2199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170106/6113b736/attachment.bin>


More information about the lldb-commits mailing list