[Lldb-commits] [PATCH] D15162: Have result formatter send bytes instead of strings

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 2 14:28:20 PST 2015


zturner created this revision.
zturner added a reviewer: tfiala.
zturner added a subscriber: lldb-commits.

http://reviews.llvm.org/D15162

Files:
  packages/Python/lldbsuite/test/dotest_channels.py
  packages/Python/lldbsuite/test/test_results.py

Index: packages/Python/lldbsuite/test/test_results.py
===================================================================
--- packages/Python/lldbsuite/test/test_results.py
+++ packages/Python/lldbsuite/test/test_results.py
@@ -1027,10 +1027,11 @@
         # Tack on the pid.
         test_event["pid"] = self.pid
 
-        # Send it as {serialized_length_of_serialized_bytes}#{serialized_bytes}
-        pickled_message = cPickle.dumps(test_event)
-        self.out_file.send("{}#".format(len(pickled_message)))
-        self.out_file.send(pickled_message)
+        # Send it as {serialized_length_of_serialized_bytes}{serialized_bytes}
+        import struct
+        msg = cPickle.dumps(test_event)
+        packet = struct.pack("!I%ds" % len(msg), len(msg), msg)
+        self.out_file.send(packet)
 
 
 class DumpFormatter(ResultsFormatter):
Index: packages/Python/lldbsuite/test/dotest_channels.py
===================================================================
--- packages/Python/lldbsuite/test/dotest_channels.py
+++ packages/Python/lldbsuite/test/dotest_channels.py
@@ -44,7 +44,7 @@
     def __init__(self, file_object, async_map, forwarding_func):
         asyncore.dispatcher.__init__(self, sock=file_object, map=async_map)
 
-        self.header_contents = ''
+        self.header_contents = b""
         self.packet_bytes_remaining = 0
         self.reading_header = True
         self.ibuffer = b''
@@ -69,17 +69,21 @@
         if not data or (len(data) == 0):
             return None
 
-        for index in range(len(data)):
-            byte = data[index]
-            if byte != '#':
-                # Header byte.
-                self.header_contents += byte
-            else:
-                # End of header.
-                self.packet_bytes_remaining = int(self.header_contents)
-                self.header_contents = ''
-                self.reading_header = False
-                return data[(index+1):]
+        full_header_len = 4
+
+        assert(len(self.header_contents) < full_header_len)
+
+        bytes_avail = len(data)
+        bytes_needed = full_header_len - len(self.header_contents)
+        header_bytes_avail = min(bytes_needed, bytes_avail)
+        self.header_contents += data[:header_bytes_avail]
+        if len(self.header_contents) == full_header_len:
+            import struct
+            # End of header.
+            self.packet_bytes_remaining = struct.unpack("!I", self.header_contents)[0]
+            self.header_contents = b""
+            self.reading_header = False
+            return data[header_bytes_avail:]
 
         # If we made it here, we've exhausted the data and
         # we're still parsing header content.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15162.41678.patch
Type: text/x-patch
Size: 2697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20151202/dfc674b8/attachment.bin>


More information about the lldb-commits mailing list