MCPcopy Index your code
hub / github.com/ZeroIntensity/pointers.py / TypedCPointer

Class TypedCPointer

src/pointers/c_pointer.py:122–197  ·  view source on GitHub ↗

Class representing a pointer with a known type.

Source from the content-addressed store, hash-verified

120
121
122class TypedCPointer(_CDeref[T], BaseCPointer[T]):
123 """Class representing a pointer with a known type."""
124
125 def __init__(
126 self,
127 address: int,
128 data_type: Type[T],
129 size: int,
130 void_p: bool = True,
131 decref: bool = True,
132 alt: bool = False,
133 ) -> None:
134 self._void_p = void_p
135 super().__init__(address, size)
136 self._type = data_type
137 self._decref = decref
138 self.alt = alt
139
140 @property
141 def size(self) -> int:
142 return self._size
143
144 @property
145 def decref(self) -> bool:
146 return self._decref
147
148 @property
149 def type(self):
150 return self._type
151
152 @property
153 def address(self) -> Optional[int]:
154 return self._address
155
156 @property # type: ignore
157 @handle
158 def _as_parameter_(self) -> ctypes._CData:
159 ctype = get_mapped(self.type)
160
161 if (ctype is ctypes.c_char_p) and (self.alt):
162 deref = ctype(self.ensure())
163 return deref
164 else:
165 deref = ctype.from_address(self.ensure())
166
167 value = deref.value # type: ignore
168
169 if isinstance(value, (TypedCPointer, VoidPointer)):
170 return ctypes.pointer(value._as_parameter_) # type: ignore
171
172 return ctypes.pointer(deref)
173
174 @handle
175 def dereference(self) -> T:
176 """Dereference the pointer."""
177 ctype = get_mapped(self.type)
178
179 if (ctype is ctypes.c_char_p) and (self.alt):

Callers 4

castFunction · 0.85
to_c_ptrFunction · 0.85
__getattribute__Method · 0.85
_decode_typeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected