Skip to content

Instantly share code, notes, and snippets.

@lemonad
Created February 18, 2020 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemonad/a62a3ff5d5f50f7a18bbdbc08246c591 to your computer and use it in GitHub Desktop.
Save lemonad/a62a3ff5d5f50f7a18bbdbc08246c591 to your computer and use it in GitHub Desktop.
Ob_size is set negative for negative integers
import ctypes
class IntStruct(ctypes.Structure):
_fields_ = [("ob_refcnt", ctypes.c_long),
("ob_type", ctypes.c_void_p),
("ob_size", ctypes.c_ulong),
("ob_digit", ctypes.c_long)]
def __repr__(self):
return ("IntStruct(ob_digit={self.ob_digit}, "
"refcount={self.ob_refcnt})").format(self=self)
print(IntStruct.from_address(id(42)).ob_size)
print(IntStruct.from_address(id(-42)).ob_size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment