Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mavutil: correct processing of zero-length logs #966

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions mavutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,12 +1477,14 @@ def __init__(self, filename, progress_callback=None):
self.f.seek(0, 2)
self.data_len = self.f.tell()
self.f.seek(0)
if platform.system() == "Windows":
self.data_map = mmap.mmap(self.f.fileno(), self.data_len, None, mmap.ACCESS_READ)
else:
self.data_map = mmap.mmap(self.f.fileno(), self.data_len, mmap.MAP_PRIVATE, mmap.PROT_READ)
self._rewind()
self.init_arrays(progress_callback)
self.data_map = None
if self.data_len != 0:
if platform.system() == "Windows":
self.data_map = mmap.mmap(self.f.fileno(), self.data_len, None, mmap.ACCESS_READ)
else:
self.data_map = mmap.mmap(self.f.fileno(), self.data_len, mmap.MAP_PRIVATE, mmap.PROT_READ)
self._rewind()
self.init_arrays(progress_callback)
self._flightmodes = None

def _rewind(self):
Expand All @@ -1498,7 +1500,8 @@ def rewind(self):

def close(self):
super(mavmmaplog, self).close()
self.data_map.close()
if self.data_map is not None:
self.data_map.close()

def init_arrays(self, progress_callback=None):
'''initialise arrays for fast recv_match()'''
Expand Down Expand Up @@ -1618,6 +1621,8 @@ def init_arrays(self, progress_callback=None):

def skip_to_type(self, type):
'''skip fwd to next msg matching given type set'''
if self.data_map is None:
return
if self.type_nums is None:
# always add some key msg types so we can track flightmode, params etc
type = type.copy()
Expand Down
Loading