Tutorials: Pointers in Python

Thursday - May 16th, 2024 9 a.m.-12:30 p.m. in Room 310/311

Presented by:

Description

Remember pointers from C/C++? Why don’t we add them to Python? Make any Python object mutable by manipulating it directly in memory through the pointer as you would do in C/C++. Why do this? Well, pointers have no use in Python, but the point is not implementation itself, but all the internal parts of Python programming language that you will touch while implementing it. What you will learn:

  • How to add new piece of syntax to Python. We will implement & and * (address of and dereference) operators just like in C/C++.
  • How to add custom builtin object. Adding new syntax has to do something, right? In our case it will operate on new pointer builtin object.
  • Internal layout of Python objects.
  • How to make our pointer object behave well. Everything in Python is an object and every object internally has to make sure it’s lifecycle does not cause any issues and your program works in a predictable way.
  • How to do something with new object. Having new syntax and object is cool, but it has to interact with other objects somehow. Remember double underscore methods like __add__ and __eq__? We will see how they are implemented internally and our object will have them.
  • How Python objects are garbage collected. Our pointer object will cover all ways Python objects can be garbage collected and all tricky parts of this process. These involve reference counting and tracing garbage collector for cyclic objects.
  • And many more.

Optional: to minimise chances of inconsistencies, it is recommended to have Docker installed