aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/serialhdl.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2020-09-16 23:49:38 -0400
committerKevin O'Connor <kevin@koconnor.net>2020-09-16 23:53:45 -0400
commita3fa11ffd454d6efec414646213eccd3a8525165 (patch)
tree48a1f58082a51f359d6a31395433a87545a16fff /klippy/serialhdl.py
parent3dc0522870fc901089f2844c86b045e8807a22e8 (diff)
downloadkutter-a3fa11ffd454d6efec414646213eccd3a8525165.tar.gz
kutter-a3fa11ffd454d6efec414646213eccd3a8525165.tar.xz
kutter-a3fa11ffd454d6efec414646213eccd3a8525165.zip
serialhdl: Setup for serialqueue_free to be automatically called
Use ffi_main.gc() to automatically free the C serialqueue object. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/serialhdl.py')
-rw-r--r--klippy/serialhdl.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py
index f410e30a..e3c612e7 100644
--- a/klippy/serialhdl.py
+++ b/klippy/serialhdl.py
@@ -98,8 +98,9 @@ class SerialReader:
continue
if self.baud:
stk500v2_leave(self.ser, self.reactor)
- self.serialqueue = self.ffi_lib.serialqueue_alloc(
- self.ser.fileno(), 0)
+ self.serialqueue = self.ffi_main.gc(
+ self.ffi_lib.serialqueue_alloc(self.ser.fileno(), 0),
+ self.ffi_lib.serialqueue_free)
self.background_thread = threading.Thread(target=self._bg_thread)
self.background_thread.start()
# Obtain and load the data dictionary from the firmware
@@ -126,7 +127,9 @@ class SerialReader:
def connect_file(self, debugoutput, dictionary, pace=False):
self.ser = debugoutput
self.msgparser.process_identify(dictionary, decompress=False)
- self.serialqueue = self.ffi_lib.serialqueue_alloc(self.ser.fileno(), 1)
+ self.serialqueue = self.ffi_main.gc(
+ self.ffi_lib.serialqueue_alloc(self.ser.fileno(), 1),
+ self.ffi_lib.serialqueue_free)
def set_clock_est(self, freq, last_time, last_clock):
self.ffi_lib.serialqueue_set_clock_est(
self.serialqueue, freq, last_time, last_clock)
@@ -135,7 +138,6 @@ class SerialReader:
self.ffi_lib.serialqueue_exit(self.serialqueue)
if self.background_thread is not None:
self.background_thread.join()
- self.ffi_lib.serialqueue_free(self.serialqueue)
self.background_thread = self.serialqueue = None
if self.ser is not None:
self.ser.close()
@@ -194,10 +196,10 @@ class SerialReader:
self.stats(self.reactor.monotonic()),))
sdata = self.ffi_main.new('struct pull_queue_message[1024]')
rdata = self.ffi_main.new('struct pull_queue_message[1024]')
- scount = self.ffi_lib.serialqueue_extract_old(
- self.serialqueue, 1, sdata, len(sdata))
- rcount = self.ffi_lib.serialqueue_extract_old(
- self.serialqueue, 0, rdata, len(rdata))
+ scount = self.ffi_lib.serialqueue_extract_old(self.serialqueue, 1,
+ sdata, len(sdata))
+ rcount = self.ffi_lib.serialqueue_extract_old(self.serialqueue, 0,
+ rdata, len(rdata))
out.append("Dumping send queue %d messages" % (scount,))
for i in range(scount):
msg = sdata[i]