Python's Include/cpython/longinterpr.h has this declaration: typedef struct _PyLongValue { uintptr_t lv_tag; /* Number of digits, sign and flags */ digit ob_digit[1]; } _PyLongValue; struct _longobject { P
(self, visited)
| 905 | _typename = 'PyLongObject' |
| 906 | |
| 907 | def proxyval(self, visited): |
| 908 | ''' |
| 909 | Python's Include/cpython/longinterpr.h has this declaration: |
| 910 | |
| 911 | typedef struct _PyLongValue { |
| 912 | uintptr_t lv_tag; /* Number of digits, sign and flags */ |
| 913 | digit ob_digit[1]; |
| 914 | } _PyLongValue; |
| 915 | |
| 916 | struct _longobject { |
| 917 | PyObject_HEAD |
| 918 | _PyLongValue long_value; |
| 919 | }; |
| 920 | |
| 921 | with this description: |
| 922 | The absolute value of a number is equal to |
| 923 | SUM(for i=0 through ndigits-1) ob_digit[i] * 2**(PyLong_SHIFT*i) |
| 924 | The sign of the value is stored in the lower 2 bits of lv_tag. |
| 925 | - 0: Positive |
| 926 | - 1: Zero |
| 927 | - 2: Negative |
| 928 | The third lowest bit of lv_tag is set to 1 for the small ints and 0 otherwise. |
| 929 | |
| 930 | where SHIFT can be either: |
| 931 | #define PyLong_SHIFT 30 |
| 932 | #define PyLong_SHIFT 15 |
| 933 | ''' |
| 934 | long_value = self.field('long_value') |
| 935 | lv_tag = int(long_value['lv_tag']) |
| 936 | size = lv_tag >> 3 |
| 937 | if size == 0: |
| 938 | return 0 |
| 939 | |
| 940 | ob_digit = long_value['ob_digit'] |
| 941 | |
| 942 | if gdb.lookup_type('digit').sizeof == 2: |
| 943 | SHIFT = 15 |
| 944 | else: |
| 945 | SHIFT = 30 |
| 946 | |
| 947 | digits = [int(ob_digit[i]) * 2**(SHIFT*i) |
| 948 | for i in safe_range(size)] |
| 949 | result = sum(digits) |
| 950 | if (lv_tag & 3) == 2: |
| 951 | result = -result |
| 952 | return result |
| 953 | |
| 954 | def write_repr(self, out, visited): |
| 955 | # Write this out as a Python int literal |
no test coverage detected