|
1 | 1 | import ctypes |
| 2 | +import gc |
2 | 3 | import sys |
3 | 4 | import weakref |
4 | 5 | from abc import ABC, abstractmethod |
5 | 6 | from contextlib import suppress |
6 | | -from typing import ( |
7 | | - Any, Generic, Iterator, Optional, Tuple, Type, TypeVar, Union |
8 | | -) |
9 | | - |
10 | | -from typing_extensions import final |
| 7 | +from typing import (Any, Generic, Iterator, Optional, Tuple, Type, TypeVar, |
| 8 | + Union) |
11 | 9 |
|
12 | 10 | from _pointers import add_ref, remove_ref |
| 11 | +from typing_extensions import final |
13 | 12 |
|
14 | 13 | from ._utils import deref, force_set_attr, move_to_mem |
15 | 14 | from .exceptions import DereferenceError, FreedMemoryError, NullPointerError |
@@ -390,6 +389,11 @@ def move( |
390 | 389 | from .object_pointer import to_ptr |
391 | 390 |
|
392 | 391 | data_ptr = data if isinstance(data, BasePointer) else to_ptr(data) |
| 392 | + |
| 393 | + if (sys.version_info.minor >= 11) and (gc.is_tracked(~data_ptr)): |
| 394 | + remove_ref(data) |
| 395 | + raise RuntimeError("allocation on tracked types is not supported on 3.11+") |
| 396 | + |
393 | 397 |
|
394 | 398 | ptr, byte_stream = self._make_stream_and_ptr( |
395 | 399 | sys.getsizeof(~data_ptr), |
@@ -430,10 +434,9 @@ def _make_stream_and_ptr( |
430 | 434 | size: int, |
431 | 435 | address: int, |
432 | 436 | ) -> Tuple["ctypes._PointerLike", bytes]: |
433 | | - |
434 | 437 | if self.freed: |
435 | 438 | raise FreedMemoryError("memory has been freed") |
436 | | - |
| 439 | + |
437 | 440 | bytes_a = (ctypes.c_ubyte * size).from_address(address) # fmt: off |
438 | 441 | return self.make_ct_pointer(), bytes(bytes_a) |
439 | 442 |
|
|
0 commit comments