Skip to content

Instantly share code, notes, and snippets.

@rbtcollins
Last active February 8, 2018 02:42
Show Gist options
  • Save rbtcollins/cf7d562158849ad3356f to your computer and use it in GitHub Desktop.
Save rbtcollins/cf7d562158849ad3356f to your computer and use it in GitHub Desktop.
Getting at the mystery object
from ctypes import *
pythonapi.PyDict_SetItemString.argtypes=[c_void_p, c_char_p, c_void_p]
class PyObject(Structure):
_fields_ = [("refcnt", c_size_t),
("typeid", c_void_p)]
pythonapi.PyThreadState_GetDict.restype = POINTER(PyObject)
pythonapi.PyDict_SetItemString(c_void_p(id(locals())), b"threaddict", pythonapi.PyThreadState_GetDict())
repr([1])
print(threaddict)
# Output
# {'Py_Repr': [{...}, [...]]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment