Skip to content

Commit

Permalink
Added helper function to return either _ptr attribute or ffi.NULL
Browse files Browse the repository at this point in the history
This helper function checks if the input is None and returns ffi.NULL,
otherwise the _ptr attribute.

Closes #160.
  • Loading branch information
heuer committed Mar 17, 2024
1 parent 644e414 commit cacc029
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions wlroots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ def str_or_none(member: ffi.CData) -> str | None:
if member:
return ffi.string(member).decode(errors="backslashreplace")
return None


def ptr_or_null(obj: Ptr | None) -> ffi.CData:
"""
Helper function to check if the object is None, returning ffi.NULL,
otherwise the _ptr attribute of the object
"""
return obj._ptr if obj is not None else ffi.NULL

0 comments on commit cacc029

Please sign in to comment.