能在Python使用指针了,它实际上是使用 ctypes 来做真正的 C 风格的内存解引用。它不仅仅是一个包装类,它确实存储了地址和类型信息。 代码案例:
from pointers import Pointer, to_ptr
class test_class:
pass
def some_function(ptr: Pointer[test_class]):
print(repr(ptr)) # <pointer to test_class object at [address]>"
some_function(to_ptr(test_class()))