Jake Lishman 11/12/2022

Mutating Python tuples by C FFI abuse

Read Original

This technical article details a method to bypass Python's tuple immutability by using the ctypes module and CPython's C-level object structure. It explains the PyObject memory layout, accesses the internal `ob_item` array via pointer manipulation, and provides a Python function that manually adjusts reference counts to swap tuple elements.

Mutating Python tuples by C FFI abuse

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week