From 3ad06eeada5166af914678d404a0ab75f3930ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20H=C3=B6glinger?= Date: Wed, 14 May 2025 20:36:49 +0200 Subject: [PATCH] set_record.py: Fixed input stream for Windows, omit null characters in string receive This commit fixes two bugs, the first when recording on Windows where the user is unable to stop the capture cleanly and one regarding the VCD output being malformed due to null characters in strings. Reading from the stdin buffer is generally better behaved on both platforms, while not as performant. The user can now cancel the capture by terminating the source program or issuing a keyboard interrupt. The issue with string capture having trailing null characters is fixed, which in the best case confuses GTKwave, or in the worst case segfaults it. --- set_record.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/set_record.py b/set_record.py index 66773df..1b2163f 100644 --- a/set_record.py +++ b/set_record.py @@ -261,7 +261,6 @@ class Filter: if tagcode not in self.TAGCODE_LUT: self.packets_dropped += 1 - print("LUT ERR", tagcode) return tag = self.TAGCODE_LUT[tagcode] @@ -413,11 +412,13 @@ class VcdSink: timestamp = self.timestamp # unpack for i in range(0,4): - char = chr(value >> (i*8) & 0xFF) - self.strings[tag][1] += char + char = value >> (i*8) & 0xFF + if char != 0: + self.strings[tag][1] += chr(char) # sub of 1 indicates end of string if sub == 1: try: + string = self.strings[tag][1] #print(f"### {timestamp:012X} : {self.varnames[tag]} <= \"{self.strings[tag][1]}\"", flush=True) self.writer.change(self.strings[tag][0], timestamp, self.strings[tag][1]) except ValueError: @@ -515,8 +516,8 @@ def main(): print(" === BEGIN NOISE ===") try: - while True: - for b in sys.stdin.buffer.read(1): + for bstr in sys.stdin.buffer: + for b in bstr: packet_filter.process(b) except KeyboardInterrupt: pass