Mercurial > cpython-lru_cache-weakref
view Objects/typeslots.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | f3553d5083f8 |
| children |
line wrap: on
line source
#!/usr/bin/python # Usage: typeslots.py < Include/typeslots.h > typeslots.inc import sys, re print("/* Generated by typeslots.py */") res = {} for line in sys.stdin: m = re.match("#define Py_([a-z_]+) ([0-9]+)", line) if not m: continue member = m.group(1) if member.startswith("tp_"): member = "ht_type."+member elif member.startswith("nb_"): member = "as_number."+member elif member.startswith("mp_"): member = "as_mapping."+member elif member.startswith("sq_"): member = "as_sequence."+member elif member.startswith("bf_"): member = "as_buffer."+member res[int(m.group(2))] = member M = max(res.keys())+1 for i in range(1,M): if i in res: print("offsetof(PyHeapTypeObject, %s)," % res[i]) else: print("0,")
