Debian Codegraph @

pypy/module/_rawffi/tracker.py

raw symbols SCIP
1 """ The file that keeps track about freed/kept-alive objects allocated
2 by _rawffi. Used for debugging ctypes
3 """
4 from pypy.interpreter.error import oefmt
5
6
7 class Tracker(object):
8 DO_TRACING = False # make sure this stays False by default!
9
10 def __init__(self):
11 self.alloced = {}
12
13 def trace_allocation(self, address, obj):
14 self.alloced[address] = None
15
16 def trace_free(self, address):
17 if address in self.alloced:
18 del self.alloced[address]
19
20 # single, global, static object to keep all tracker info
21 tracker = Tracker()
22
23 def num_of_allocated_objects(space):
24 if not tracker.DO_TRACING:
25 raise oefmt(space.w_RuntimeError,
26 "DO_TRACING not enabled in this PyPy")
27 return space.newint(len(tracker.alloced))
28
29 def print_alloced_objects(space):
30 xxx
31 # eventually inspect and print what's left from applevel