Skip to content

Commit

Permalink
fix: tangy-close-all-buffers no longer segfaults
Browse files Browse the repository at this point in the history
fix issue relating to reference counts of buffers, __del__ now checks to
see if the buffer still exists first
  • Loading branch information
Peter-Barrow committed Aug 29, 2024
1 parent 7fc6fa5 commit 49ffd3b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "tangy"
version = "0.8.1"
version = "0.8.2"
description = "Timetag analysing library"
authors = [
{name = "Peter Thomas Barrow", email = "peter.barrow.93@gmail.com"}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
print("CIBUILDWHEEL ", os.environ.get("CIBUILDWHEEL", '0'))
if os.environ.get("CIBUILDWHEEL", '0') == 1:
local = False
# local = False
local = False

cython_dir = os.path.join("tangy_src")

Expand Down
22 changes: 19 additions & 3 deletions tangy_src/_tangy.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,23 @@ def __init__(self, name: str, resolution: float = 0.1,
return

def __del__(self):
result: _tangy.tbResult = _tangy.tangy_buffer_deinit(self._ptr_buf)
c_name: cython.p_char = self._name
flag: u8 = 0
result: _tangy.tbResult = _tangy.shmem_exists(c_name,
cython.address(flag))
if exists == 0:
buffer_list_update()
return

result = _tangy.tangy_buffer_deinit(self._ptr_buf)
if result.Ok is False:
raise MemoryError(
"Failed to free memory for buffer and/or records vector")
buffer_list_update()

def close(self):
self.__del__()

def __len__(self):
""" Length of buffer
Expand Down Expand Up @@ -1752,8 +1763,13 @@ def buffer_list_delete_all():
buffer_list = buffer_list_update()

for name in buffer_list.keys():
buffer = TangyBuffer(name, 1.0)
buffer.__del__()

format = TangyBufferType.Standard
if buffer_list[name]["format"] == "Clocked":
format = TangyBufferType.Clocked

buffer = TangyBuffer(name, format=format)
buffer.reference_count = 0

buffer_list_update()

Expand Down

0 comments on commit 49ffd3b

Please sign in to comment.