Skip to content

Commit

Permalink
Merge pull request #37 from m-col/listener
Browse files Browse the repository at this point in the history
wl_list_remove leave wl_listener links invalid, not ffi.NULL
  • Loading branch information
flacjacket authored Feb 21, 2022
2 parents 471e874 + 1a2c149 commit c538079
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pywayland/server/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def add_destroy_listener(self, listener: Listener) -> None:
:param listener: The listener object
:type listener: :class:`~pywayland.server.Listener`
"""
assert self._ptr is not None
assert self._ptr is not None and listener._ptr is not None
lib.wl_client_add_destroy_listener(self._ptr, listener._ptr)

@ensure_valid
Expand Down
8 changes: 5 additions & 3 deletions pywayland/server/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ def __init__(self, function: Callable) -> None:
self.container = ffi.new("struct wl_listener_container *") # type: ignore[assignment]
self.container.handle = self._handle

self._ptr = ffi.addressof(self.container.destroy_listener)
self._ptr: ffi.ListenerCData | None = ffi.addressof(
self.container.destroy_listener
)
self._ptr.notify = lib.notify_func
self._notify = function
self._signal = None

def remove(self) -> None:
"""Remove the listener"""
if self._ptr.link != ffi.NULL:
if self._ptr and self._ptr.link != ffi.NULL:
lib.wl_list_remove(ffi.addressof(self._ptr.link))
self.link = None
self._ptr = None


class Signal:
Expand Down

0 comments on commit c538079

Please sign in to comment.