Skip to content

Commit

Permalink
Merge pull request #161 from heuer/issue_160
Browse files Browse the repository at this point in the history
Added helper function to return either _ptr attribute or ffi.NULL
  • Loading branch information
flacjacket authored Mar 18, 2024
2 parents 80b45bb + cacc029 commit c149904
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 c149904

Please sign in to comment.