Why would you ever need this
from pointers import to_ptr, Pointer, decay
a: str = '123'
b: str = 'abc'
@decay
def move(ptr_a: Pointer[str], ptr_b: Pointer[str]):
ptr_a <<= ptr_b
move(a, b)
print(a, b) # abc abc
from pointers import fopen, fprintf, fclose
file = fopen("/dev/null", "w")
fprintf(file, "hello world")
fclose(file)
from pointers import binds, Struct
import ctypes
dll = ctypes.CDLL("libc.so.6")
class DivStruct(Struct):
quot: int
rem: int
class div_t(ctypes.Structure):
_fields_ = [
("quot", ctypes.c_int),
("rem", ctypes.c_int),
]
dll.div.restype = div_t
@binds(dll.div, struct=DivStruct)
def div(numer: int, denom: int) -> DivStruct:
...
print((div(10, 10).quot))
from pointers import malloc, free
memory = malloc(52)
memory <<= "abc"
print(*memory) # abc
free(memory)
print(*memory) # FreedMemoryError
The main purpose of pointers.py is to simply break the rules of Python, but has some other use cases:
- Can help C/C++ developers get adjusted to Python
- Provides a nice learning environment for programmers learning how pointers work
- Makes it very easy to manipulate memory in Python
- Why not?
python3 -m pip install -U pointers.py
py -3 -m pip install -U pointers.py
$ git clone https://github.com/ZeroIntensity/pointers.py && cd pointers.py
$ pip install -U mkdocs
$ mkdocs serve