Created
February 18, 2020 13:16
-
-
Save lemonad/a62a3ff5d5f50f7a18bbdbc08246c591 to your computer and use it in GitHub Desktop.
Ob_size is set negative for negative integers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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