]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/test/crashers/gc_inspection.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / test / crashers / gc_inspection.py
CommitLineData
4710c53d 1"""\r
2gc.get_referrers() can be used to see objects before they are fully built.\r
3\r
4Note that this is only an example. There are many ways to crash Python\r
5by using gc.get_referrers(), as well as many extension modules (even\r
6when they are using perfectly documented patterns to build objects).\r
7\r
8Identifying and removing all places that expose to the GC a\r
9partially-built object is a long-term project. A patch was proposed on\r
10SF specifically for this example but I consider fixing just this single\r
11example a bit pointless (#1517042).\r
12\r
13A fix would include a whole-scale code review, possibly with an API\r
14change to decouple object creation and GC registration, and according\r
15fixes to the documentation for extension module writers. It's unlikely\r
16to happen, though. So this is currently classified as\r
17"gc.get_referrers() is dangerous, use only for debugging".\r
18"""\r
19\r
20import gc\r
21\r
22\r
23def g():\r
24 marker = object()\r
25 yield marker\r
26 # now the marker is in the tuple being constructed\r
27 [tup] = [x for x in gc.get_referrers(marker) if type(x) is tuple]\r
28 print tup\r
29 print tup[1]\r
30\r
31\r
32tuple(g())\r