Skip to content

ZeroIntensity/pointers.py

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
October 15, 2022 10:47
January 14, 2023 16:33
src
January 14, 2023 16:42
January 14, 2023 16:34
January 14, 2023 16:33
September 22, 2022 18:01
January 3, 2023 06:37
December 21, 2022 21:36
February 14, 2023 18:21
January 14, 2023 16:33
September 16, 2022 17:35
February 14, 2023 18:21
September 16, 2022 17:35
February 14, 2023 18:21
October 11, 2022 18:06

pointers.py

Tests

Bringing the hell of pointers to Python

Why would you ever need this

Examples

from pointers import _

text: str = "hello world"
ptr = _&text  # creates a new pointer object
ptr <<= "world hello"
print(text)  # world hello
from pointers import c_malloc as malloc, c_free as free, strcpy, printf

ptr = malloc(3)
strcpy(ptr, "hi")
printf("%s\n", ptr)
free(ptr)

Features

  • Fully type safe
  • Pythonic pointer API
  • Bindings for the entire C standard library
  • Segfaults

Why does this exist?

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?

Installation

Linux/macOS

python3 -m pip install -U pointers.py

Windows

py -3 -m pip install -U pointers.py