Mercurial > cpython-lru_cache-weakref
annotate Parser/listnode.c @ 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 | fd25030223b0 |
| children |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* List a node on a file */ |
| 3 | |
| 86 | 4 #include "pgenheaders.h" |
| 6 | 5 #include "token.h" |
| 6 #include "node.h" | |
| 7 | |
| 86 | 8 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
9 static void list1node(FILE *, node *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
10 static void listnode(FILE *, node *); |
| 86 | 11 |
| 12 void | |
| 13659 | 13 PyNode_ListTree(node *n) |
| 86 | 14 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
15 listnode(stdout, n); |
| 86 | 16 } |
| 17 | |
| 6 | 18 static int level, atbol; |
| 19 | |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
20 static void |
| 13659 | 21 listnode(FILE *fp, node *n) |
| 86 | 22 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
23 level = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
24 atbol = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
25 list1node(fp, n); |
| 86 | 26 } |
| 27 | |
| 6 | 28 static void |
| 13659 | 29 list1node(FILE *fp, node *n) |
| 6 | 30 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
31 if (n == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
32 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
33 if (ISNONTERMINAL(TYPE(n))) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
34 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
35 for (i = 0; i < NCH(n); i++) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
36 list1node(fp, CHILD(n, i)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
37 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
38 else if (ISTERMINAL(TYPE(n))) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
39 switch (TYPE(n)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
40 case INDENT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
41 ++level; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
42 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
43 case DEDENT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
44 --level; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
45 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
46 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
47 if (atbol) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
48 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
49 for (i = 0; i < level; ++i) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
50 fprintf(fp, "\t"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
51 atbol = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
52 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
53 if (TYPE(n) == NEWLINE) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
54 if (STR(n) != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
55 fprintf(fp, "%s", STR(n)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
56 fprintf(fp, "\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
57 atbol = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
58 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
59 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
60 fprintf(fp, "%s ", STR(n)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
61 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
62 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
63 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
64 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
14375
diff
changeset
|
65 fprintf(fp, "? "); |
| 6 | 66 } |
