Reference
NULL
Unique object representing a NULL address.
May be used with object pointers or passed to bindings.
Source code in src/pointers/util.py
36 37 38 39 40 |
|
handle(func)
Handle segment violation errors when called.
Source code in src/pointers/util.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
raw_type(ct)
Set a raw ctypes type for a struct.
Source code in src/pointers/util.py
50 51 52 |
|
stop_handler()
Shutoff the SIGSEGV handler.
Source code in src/pointers/util.py
55 56 57 |
|
struct_cast(ptr)
Cast a Struct
or StructPointer
to a Python object.
Source code in src/pointers/util.py
91 92 93 94 |
|
BaseAllocatedPointer
Bases: BasePointer[T]
, Sized
, ABC
Source code in src/pointers/base_pointers.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
|
assigned: bool
property
writable
Whether the allocated memory has been assigned a value.
ensure_valid()
Ensure the memory has not been freed.
Source code in src/pointers/base_pointers.py
448 449 450 451 452 453 |
|
free()
abstractmethod
Free the memory.
Source code in src/pointers/base_pointers.py
443 444 445 446 |
|
BaseCPointer
Bases: Movable[T, 'BaseCPointer[T]']
, IterDereferencable[T]
, Sized
, ABC
Source code in src/pointers/base_pointers.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
make_ct_pointer()
Turn the pointer into a ctypes pointer.
Source code in src/pointers/base_pointers.py
335 336 337 338 339 340 341 |
|
move(data, *, unsafe=False)
Move data to the target address.
Source code in src/pointers/base_pointers.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
BaseObjectPointer
Bases: IterDereferencable[T]
, BasePointer[T]
, ABC
Abstract class for a pointer to a Python object.
Source code in src/pointers/base_pointers.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
|
__init__(address, increment_ref=False)
Parameters: |
|
---|
Source code in src/pointers/base_pointers.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
assign(target)
Point to a new address.
Parameters: |
|
---|
Source code in src/pointers/base_pointers.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
make_from(obj)
abstractmethod
classmethod
Create a new instance of the pointer.
Parameters: |
|
---|
Returns: |
|
---|
Example
ptr = Pointer.make_from(1)
Source code in src/pointers/base_pointers.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
set_attr(key, value)
Force setting an attribute on the object the pointer is looking at.
Source code in src/pointers/base_pointers.py
201 202 203 204 205 206 207 208 |
|
BasePointer
Bases: Dereferencable[T]
, Movable[T, 'BasePointer[T]']
, BasicPointer
, ABC
, Generic[T]
Base class representing a pointer.
Source code in src/pointers/base_pointers.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
BasicPointer
Bases: ABC
Base class representing a pointer with no operations.
Source code in src/pointers/base_pointers.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
address: Optional[int]
abstractmethod
property
Address that the pointer is looking at.
ensure()
Ensure that the pointer is not null.
Raises: |
|
---|
Returns: |
|
---|
Example
ptr = to_ptr(NULL)
address = ptr.ensure() # NullPointerError
ptr >>= 1
address = ptr.ensure() # works just fine
Source code in src/pointers/base_pointers.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
Dereferencable
Bases: ABC
, Generic[T]
Abstract class for an object that may be dereferenced.
Source code in src/pointers/base_pointers.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
dereference()
abstractmethod
Dereference the pointer.
Returns: |
|
---|
Source code in src/pointers/base_pointers.py
105 106 107 108 109 110 111 |
|
IterDereferencable
Bases: Dereferencable[T]
, Generic[T]
Abstract class for an object that may be dereferenced via * (__iter__
)
Source code in src/pointers/base_pointers.py
118 119 120 121 122 123 124 |
|
Movable
Bases: ABC
, Generic[T, A]
Source code in src/pointers/base_pointers.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
move(data, *, unsafe=False)
abstractmethod
Move/copy a value into the memory at the pointers address.
Source code in src/pointers/base_pointers.py
83 84 85 86 87 88 89 90 91 |
|
Sized
Bases: BasicPointer
, ABC
Base class for a pointer that has a size attribute.
Source code in src/pointers/base_pointers.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
size: int
abstractmethod
property
Size of the target value.
make_ct_pointer()
Convert the address to a ctypes pointer.
Returns: |
|
---|
Source code in src/pointers/base_pointers.py
154 155 156 157 158 159 160 161 162 163 164 165 |
|
CArrayPointer
Bases: _CDeref[List[T]]
, BaseCPointer[List[T]]
Class representing a pointer to a C array.
Source code in src/pointers/c_pointer.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
dereference()
Dereference the pointer.
Source code in src/pointers/c_pointer.py
227 228 229 230 231 |
|
TypedCPointer
Bases: _CDeref[T]
, BaseCPointer[T]
Class representing a pointer with a known type.
Source code in src/pointers/c_pointer.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
__iter__()
Dereference the pointer.
Source code in src/pointers/c_pointer.py
192 193 194 |
|
dereference()
Dereference the pointer.
Source code in src/pointers/c_pointer.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
VoidPointer
Bases: BaseCPointer[Any]
Class representing a void pointer to a C object.
Source code in src/pointers/c_pointer.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
cast(ptr, data_type)
Cast a void pointer to a typed pointer.
Source code in src/pointers/c_pointer.py
241 242 243 244 245 246 247 248 249 250 251 252 |
|
to_c_ptr(data)
Convert a python type to a pointer to a C type.
Source code in src/pointers/c_pointer.py
261 262 263 264 265 266 267 268 269 |
|
to_struct_ptr(struct)
Convert a struct to a pointer.
Source code in src/pointers/c_pointer.py
272 273 274 275 276 |
|
to_voidp(ptr)
Cast a typed pointer to a void pointer.
Source code in src/pointers/c_pointer.py
255 256 257 258 |
|
decay(func)
Automatically convert values to pointers when called.
Example
@decay
def my_function(a: str, b: Pointer[str]):
print(a, *c)
my_function('a', 'b')
Source code in src/pointers/decay.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
decay_annotated(func)
Example
@decay_annotated
def my_function(a: str, b: Annotated[str, Pointer]):
print(a, *c)
my_function('a', 'b')
Source code in src/pointers/decay.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
decay_wrapped(_)
Example
def my_function_wrapper(a: str, b: str, c: str) -> None:
...
@decay_wrapped(my_function_wrapper)
def my_function(a: str, b: str, c: Pointer[str]):
print(a, b, *c)
print(a, b, ~c)
my_function('a', 'b', 'c')
Source code in src/pointers/decay.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
Struct
Abstract class representing a struct.
Source code in src/pointers/structure.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
struct: ctypes.Structure
property
Raw internal Structure object.
from_existing(struct)
classmethod
Build a new struct from an existing ctypes structure.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/pointers/structure.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
StructPointer
Bases: Pointer[T]
Class representing a pointer to a struct.
Source code in src/pointers/structure.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
AllocatedPointer
Bases: IterDereferencable[T]
, BaseAllocatedPointer[T]
Pointer to allocated memory.
Source code in src/pointers/malloc.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
__init__(address, size, assigned=False, parent=None)
Parameters: |
|
---|
Source code in src/pointers/malloc.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
free(target)
Equivalent to target.free()
Parameters: |
|
---|
Example
ptr = malloc(1)
free(ptr) # is the same as `ptr.free()`
Source code in src/pointers/malloc.py
133 134 135 136 137 138 139 140 141 142 143 144 |
|
malloc(size)
Allocate memory of a given size.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Example
ptr = malloc(1)
Source code in src/pointers/malloc.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
realloc(target, size)
Resize a memory block created by malloc.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Example
ptr = malloc(1)
realloc(ptr, 2)
Source code in src/pointers/malloc.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
AllocatedArrayPointer
Bases: BaseAllocatedPointer[T]
Pointer to an allocated array.
Source code in src/pointers/calloc.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
chunks: int
property
Number of allocated chunks.
current_index: int
property
Current chunk index.
calloc(num, size)
Allocate a number of blocks with a given size.
Source code in src/pointers/calloc.py
125 126 127 128 129 130 131 132 |
|
AllocationError
Bases: Exception
Raised when a memory allocation fails.
Source code in src/pointers/exceptions.py
14 15 |
|
DereferenceError
Bases: Exception
Raised when dereferencing an address fails.
Source code in src/pointers/exceptions.py
18 19 |
|
FreedMemoryError
Bases: Exception
Raised when trying to perform an operation on freed memory.
Source code in src/pointers/exceptions.py
22 23 |
|
InvalidBindingParameter
Bases: Exception
Raised when an invalid type is passed to a binding.
Source code in src/pointers/exceptions.py
30 31 |
|
InvalidSizeError
Bases: Exception
Raised when trying to move an object of the wrong size to an allocation.
Source code in src/pointers/exceptions.py
26 27 |
|
InvalidVersionError
Bases: Exception
Python version is not high enough.
Source code in src/pointers/exceptions.py
38 39 |
|
NullPointerError
Bases: Exception
Raised when a pointer is null.
Source code in src/pointers/exceptions.py
34 35 |
|
SegmentViolation
Bases: Exception
SIGSEGV was sent to Python.
Source code in src/pointers/exceptions.py
42 43 |
|
VariableLifetimeError
Bases: Exception
Variable is no longer available.
Source code in src/pointers/exceptions.py
46 47 |
|
attempt_decode(data)
Attempt to decode a string of bytes.
Source code in src/pointers/_utils.py
74 75 76 77 78 79 |
|
deref(address)
Get the value at the target address.
Source code in src/pointers/_utils.py
169 170 171 |
|
force_set_attr(typ, key, value)
Force setting an attribute on the target type.
Source code in src/pointers/_utils.py
158 159 160 161 162 163 164 165 166 |
|
get_mapped(typ)
Get the C mapped value of the given type.
Source code in src/pointers/_utils.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
get_py(data)
Map the specified C type to a Python type.
Source code in src/pointers/_utils.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
is_mappable(typ)
Whether the specified type is mappable to C.
Source code in src/pointers/_utils.py
121 122 123 124 125 126 127 |
|
make_py(data)
Convert the target C value to a Python object.
Source code in src/pointers/_utils.py
147 148 149 150 151 152 153 154 155 |
|
map_type(data)
Map the specified data to a C type.
Source code in src/pointers/_utils.py
82 83 84 85 86 87 88 89 |
|
move_to_mem(ptr, stream, *, unsafe=False, target='memory allocation')
Move data to a C pointer.
Source code in src/pointers/_utils.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|