Skip to content

etas: keep filter structs alive on PyPy and remove all old filters in set_filters - #2171

Merged
zariiii9003 merged 1 commit into
hardbyte:mainfrom
zariiii9003:fix-etas-pypy-filters
Nov 29, 2026
Merged

zariiii9003 merged 1 commit into
hardbyte:mainfrom
zariiii9003:fix-etas-pypy-filters

Conversation

@zariiii9003

Copy link
Copy Markdown
Collaborator

Summary of Changes

Two bugs in EtasBus._apply_filters:

  • PyPy: the filter array held pointers to loop-local OCI_CANRxFilterEx structs. Assigning .contents keeps the struct alive on CPython but not on PyPy, so after garbage collection the array pointed to freed memory and BOA received corrupted filters.
  • set_filters: the previously installed filters were removed with a fixed count of 1. Per the BOA OCI header (ocicanio.h, OCI_RemoveCANFrameFilterEx), count is the number of entries in the filter array, so only the first old filter was removed and the others stayed active.
 _apply_filters(filters)
   if self._oci_filters
-    OCI_RemoveCANFrameFilterEx(queue, self._oci_filters, 1)
+    OCI_RemoveCANFrameFilterEx(queue, self._oci_filters, len(self._oci_filters))
   for i, filter_ in enumerate(filters)
     f = OCI_CANRxFilterEx(...)
-    self._oci_filters[i].contents = f
+    self._oci_filters[i] = ctypes.pointer(f)

Related Issues / Pull Requests

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe):

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

Additional Notes

Evidence

PyPy filter structs, test/test_etas.py on PyPy 3.12 with a gc.collect() forced before the fake library reads the filters:

  • Before: 2 failed (test_constructor_filters_are_installed reads garbage such as (758445430, 2376409665, 0, 0); test_set_filters_replaces_constructor_filters raises ValueError). The same failures occurred without the forced GC on the macos-latest, pypy312 CI job.
  • After: 3 passed.

set_filters remove count, test_set_filters_replaces_constructor_filters now starts with two constructor filters:

bus = Bus(can_filters=[0x123/0x7FF, 0x124/0x7FF])
bus.set_filters([0x456/0x7FF])
assert installed == [0x456/0x7FF]
  • Before: fails, [(0x124, 0x7FF, 0, 4), (0x456, 0x7FF, 0, 4)] != [(0x456, 0x7FF, 0, 4)]
  • After: passes

🤖 Generated with AI

@zariiii9003
zariiii9003 force-pushed the fix-etas-pypy-filters branch from 9a5c64d to 5510532 Compare November 29, 2026 23:21
@zariiii9003
zariiii9003 merged commit 63838e6 into hardbyte:main Nov 29, 2026
26 of 27 checks passed
@zariiii9003
zariiii9003 deleted the fix-etas-pypy-filters branch November 29, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant