Skip to content

Commit 5f85b7a

Browse files
committed
Implement StreamIterator._free (closes #9)
1 parent 459a38a commit 5f85b7a

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

rust_fst/common.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ def __init__(self, stream_ptr, next_fn, free_fn, autom_ptr=None,
1717
self._ctx = ctx_ptr
1818

1919
def _free(self):
20-
# TODO: We could safely free the structures before the GC does,
21-
# but unfortunately removing GC-callbacks is only supported
22-
# in cffi >= 1.7, which is not yet released.
23-
24-
# self._free_fn(self._ptr)
25-
# # Clear GC hook to prevent double-free
26-
# ffi.gc(self._ptr, None)
27-
# if self._autom_ptr:
28-
# self._autom_free_fn(self._autom_ptr)
29-
# ffi.gc(self._autom_ptr, None)
30-
pass
20+
self._free_fn(self._ptr)
21+
# Clear GC hook to prevent double-free
22+
ffi.gc(self._ptr, None)
23+
self._ptr = None
24+
if self._autom_ptr:
25+
self._autom_free_fn(self._autom_ptr)
26+
ffi.gc(self._autom_ptr, None)
27+
self._autom_ptr = None
3128

3229
def __iter__(self):
3330
return self

0 commit comments

Comments
 (0)