-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdictinfo32.py
More file actions
55 lines (40 loc) · 1.26 KB
/
Copy pathdictinfo32.py
File metadata and controls
55 lines (40 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from ctypes import Structure, c_ulong, POINTER, cast, py_object, c_long
from common import get_object_field_or_null, EMPTY, DUMMY
class PyDictEntry(Structure):
_fields_ = [
('me_hash', c_long),
('me_key', py_object),
('me_value', py_object),
]
class PyDictObject(Structure):
_fields_ = [
('ob_refcnt', c_ulong),
('ob_type', c_ulong),
('ma_fill', c_ulong),
('ma_used', c_ulong),
('ma_mask', c_ulong),
('ma_table', POINTER(PyDictEntry)),
]
def dictobject(d):
return cast(id(d), POINTER(PyDictObject)).contents
d = {0: 0}
del d[0]
dummy_internal = dictobject(d).ma_table[0].me_key
del d
def dump_py_dict(d):
do = dictobject(d)
keys = []
hashes = []
values = []
size = do.ma_mask + 1
for i in range(size):
key = get_object_field_or_null(do.ma_table[i], 'me_key')
keys.append(key if key is not dummy_internal else DUMMY)
for i, key in enumerate(keys):
if key is EMPTY:
hashes.append(EMPTY)
values.append(EMPTY)
else:
hashes.append(do.ma_table[i].me_hash)
values.append(get_object_field_or_null(do.ma_table[i], 'me_value'))
return hashes, keys, values, do.ma_fill, do.ma_used