MCPcopy Create free account
hub / github.com/ZeroIntensity/pointers.py / ensure

Method ensure

src/pointers/base_pointers.py:60–79  ·  view source on GitHub ↗

Ensure that the pointer is not null. Raises: NullPointerError: Address of pointer is `None` Returns: Address of the pointer. Example: ```py ptr = to_ptr(NULL) address = ptr.ensure() # NullPointerError

(self)

Source from the content-addressed store, hash-verified

58
59 @final
60 def ensure(self) -> int:
61 """Ensure that the pointer is not null.
62
63 Raises:
64 NullPointerError: Address of pointer is `None`
65
66 Returns:
67 Address of the pointer.
68
69 Example:
70 ```py
71 ptr = to_ptr(NULL)
72 address = ptr.ensure() # NullPointerError
73 ptr >>= 1
74 address = ptr.ensure() # works just fine
75 ```"""
76
77 if not self.address:
78 raise NullPointerError("pointer is NULL")
79 return self.address
80
81
82class Movable(ABC, Generic[T, A]):

Callers 6

make_ct_pointerMethod · 0.45
dereferenceMethod · 0.45
moveMethod · 0.45
make_ct_pointerMethod · 0.45
moveMethod · 0.45
dereferenceMethod · 0.45

Calls 1

NullPointerErrorClass · 0.85

Tested by

no test coverage detected