Mercurial > cpython-lru_cache-weakref
annotate Parser/node.c @ 58664:993f703a61ba
Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines
Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done
partially before. Also add a comment describing how this might have to work
with different versions of the interpreter.
........
r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line
Fixed typo
........
r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line
#7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such.
........
r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line
Add note about usage of STRINGLIB_EMPTY.
........
r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line
Fix internal reference.
........
r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines
data descriptors do not override the class dictionary if __get__ is not defined
Adjust documentation and add a test to verify this behavior.
See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for
discussion.
........
r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines
Do not compile stubs for the sha2 series hashes in the openssl hashlib
module when the openssl version is too old to support them. That
leads both compiled code bloat and to unittests attempting to test
implementations that don't exist for comparison purposes on such
platforms.
........
r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line
Add two more test_strtod test values.
........
r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line
#7762: fix refcount annotation of PyUnicode_Tailmatch().
........
r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line
#7725: fix referencing issue.
........
r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line
mention from_float() in error message
........
r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line
#7802: fix invalid example (heh).
........
r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines
Fix-up ftplib documentation:
move exception descriptions to toplevel, not inside a class
remove attribution in "versionadded"
spell and grammar check docstring of FTP_TLS
........
r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line
Minor modification to unittest documentation.
........
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Wed, 03 Feb 2010 02:35:45 +0000 |
| parents | ac854cde3135 |
| children | fd25030223b0 |
| rev | line source |
|---|---|
|
14391
1fd64b3af760
Move down the INT_MAX logic, because HAVE_LIMITS_H was always undefined
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14375
diff
changeset
|
1 /* Parse tree node implementation */ |
|
1fd64b3af760
Move down the INT_MAX logic, because HAVE_LIMITS_H was always undefined
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14375
diff
changeset
|
2 |
|
14871
fb6b51033c3b
More limits.h stuff in node.c.
Tim Peters <tim.peters@gmail.com>
parents:
14391
diff
changeset
|
3 #include "Python.h" |
|
14391
1fd64b3af760
Move down the INT_MAX logic, because HAVE_LIMITS_H was always undefined
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14375
diff
changeset
|
4 #include "node.h" |
|
1fd64b3af760
Move down the INT_MAX logic, because HAVE_LIMITS_H was always undefined
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents:
14375
diff
changeset
|
5 #include "errcode.h" |
| 145 | 6 |
| 6 | 7 node * |
| 13659 | 8 PyNode_New(int type) |
| 6 | 9 { |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24241
diff
changeset
|
10 node *n = (node *) PyObject_MALLOC(1 * sizeof(node)); |
| 6 | 11 if (n == NULL) |
| 12 return NULL; | |
| 13 n->n_type = type; | |
| 14 n->n_str = NULL; | |
| 86 | 15 n->n_lineno = 0; |
| 6 | 16 n->n_nchildren = 0; |
| 17 n->n_child = NULL; | |
| 18 return n; | |
| 19 } | |
| 20 | |
|
24141
40bda3e090f6
PyNode_AddChild() and fancy_roundup(): Be paranoid about int overflow.
Tim Peters <tim.peters@gmail.com>
parents:
24128
diff
changeset
|
21 /* See comments at XXXROUNDUP below. Returns -1 on overflow. */ |
|
24128
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
22 static int |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
23 fancy_roundup(int n) |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
24 { |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
25 /* Round up to the closest power of 2 >= n. */ |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
26 int result = 256; |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
27 assert(n > 128); |
|
24141
40bda3e090f6
PyNode_AddChild() and fancy_roundup(): Be paranoid about int overflow.
Tim Peters <tim.peters@gmail.com>
parents:
24128
diff
changeset
|
28 while (result < n) { |
|
24128
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
29 result <<= 1; |
|
24141
40bda3e090f6
PyNode_AddChild() and fancy_roundup(): Be paranoid about int overflow.
Tim Peters <tim.peters@gmail.com>
parents:
24128
diff
changeset
|
30 if (result <= 0) |
|
40bda3e090f6
PyNode_AddChild() and fancy_roundup(): Be paranoid about int overflow.
Tim Peters <tim.peters@gmail.com>
parents:
24128
diff
changeset
|
31 return -1; |
|
40bda3e090f6
PyNode_AddChild() and fancy_roundup(): Be paranoid about int overflow.
Tim Peters <tim.peters@gmail.com>
parents:
24128
diff
changeset
|
32 } |
|
24128
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
33 return result; |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
34 } |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
35 |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
36 /* A gimmick to make massive numbers of reallocs quicker. The result is |
|
24241
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
37 * a number >= the input. In PyNode_AddChild, it's used like so, when |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
38 * we're about to add child number current_size + 1: |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
39 * |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
40 * if XXXROUNDUP(current_size) < XXXROUNDUP(current_size + 1): |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
41 * allocate space for XXXROUNDUP(current_size + 1) total children |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
42 * else: |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
43 * we already have enough space |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
44 * |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
45 * Since a node starts out empty, we must have |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
46 * |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
47 * XXXROUNDUP(0) < XXXROUNDUP(1) |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
48 * |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
49 * so that we allocate space for the first child. One-child nodes are very |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
50 * common (presumably that would change if we used a more abstract form |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
51 * of syntax tree), so to avoid wasting memory it's desirable that |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
52 * XXXROUNDUP(1) == 1. That in turn forces XXXROUNDUP(0) == 0. |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
53 * |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
54 * Else for 2 <= n <= 128, we round up to the closest multiple of 4. Why 4? |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
55 * Rounding up to a multiple of an exact power of 2 is very efficient, and |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
56 * most nodes with more than one child have <= 4 kids. |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
57 * |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
58 * Else we call fancy_roundup() to grow proportionately to n. We've got an |
|
24128
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
59 * extreme case then (like test_longexp.py), and on many platforms doing |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
60 * anything less than proportional growth leads to exorbitant runtime |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
61 * (e.g., MacPython), or extreme fragmentation of user address space (e.g., |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
62 * Win98). |
|
24241
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
63 * |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
64 * In a run of compileall across the 2.3a0 Lib directory, Andrew MacIntyre |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36786
diff
changeset
|
65 * reported that, with this scheme, 89% of PyObject_REALLOC calls in |
|
24241
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
66 * PyNode_AddChild passed 1 for the size, and 9% passed 4. So this usually |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
67 * wastes very little memory, but is very effective at sidestepping |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
68 * platform-realloc disasters on vulnerable platforms. |
|
24241
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
69 * |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
70 * Note that this would be straightforward if a node stored its current |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
71 * capacity. The code is tricky to avoid that. |
|
24128
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
72 */ |
|
24241
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
73 #define XXXROUNDUP(n) ((n) <= 1 ? (n) : \ |
|
fc27ffe2036a
XXXROUNDUP(): Turns out this fixed Andrew MacIntyre's memory-mgmt
Tim Peters <tim.peters@gmail.com>
parents:
24141
diff
changeset
|
74 (n) <= 128 ? (((n) + 3) & ~3) : \ |
|
24128
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
75 fancy_roundup(n)) |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
76 |
| 6 | 77 |
|
12970
63436719d12e
Add new parser error code, E_OVERFLOW. This error is returned when
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
5379
diff
changeset
|
78 int |
|
36786
57322cb2ca11
Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
79 PyNode_AddChild(register node *n1, int type, char *str, int lineno, int col_offset) |
| 6 | 80 { |
|
24128
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
81 const int nch = n1->n_nchildren; |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
82 int current_capacity; |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
83 int required_capacity; |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
84 node *n; |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
85 |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
13659
diff
changeset
|
86 if (nch == INT_MAX || nch < 0) |
|
12970
63436719d12e
Add new parser error code, E_OVERFLOW. This error is returned when
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
5379
diff
changeset
|
87 return E_OVERFLOW; |
|
24128
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
88 |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
89 current_capacity = XXXROUNDUP(nch); |
|
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
90 required_capacity = XXXROUNDUP(nch + 1); |
|
24141
40bda3e090f6
PyNode_AddChild() and fancy_roundup(): Be paranoid about int overflow.
Tim Peters <tim.peters@gmail.com>
parents:
24128
diff
changeset
|
91 if (current_capacity < 0 || required_capacity < 0) |
|
40bda3e090f6
PyNode_AddChild() and fancy_roundup(): Be paranoid about int overflow.
Tim Peters <tim.peters@gmail.com>
parents:
24128
diff
changeset
|
92 return E_OVERFLOW; |
|
24128
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
93 if (current_capacity < required_capacity) { |
|
48330
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
38673
diff
changeset
|
94 if (required_capacity > PY_SIZE_MAX / sizeof(node)) { |
|
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
38673
diff
changeset
|
95 return E_NOMEM; |
|
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
38673
diff
changeset
|
96 } |
| 6 | 97 n = n1->n_child; |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24241
diff
changeset
|
98 n = (node *) PyObject_REALLOC(n, |
|
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24241
diff
changeset
|
99 required_capacity * sizeof(node)); |
| 6 | 100 if (n == NULL) |
|
12970
63436719d12e
Add new parser error code, E_OVERFLOW. This error is returned when
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
5379
diff
changeset
|
101 return E_NOMEM; |
| 6 | 102 n1->n_child = n; |
| 103 } | |
|
24128
76e9a14fb7c5
PyNode_AddChild(): Do aggressive over-allocation when the number of
Tim Peters <tim.peters@gmail.com>
parents:
14871
diff
changeset
|
104 |
| 6 | 105 n = &n1->n_child[n1->n_nchildren++]; |
| 106 n->n_type = type; | |
| 107 n->n_str = str; | |
| 86 | 108 n->n_lineno = lineno; |
|
36786
57322cb2ca11
Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents:
24529
diff
changeset
|
109 n->n_col_offset = col_offset; |
| 6 | 110 n->n_nchildren = 0; |
| 111 n->n_child = NULL; | |
|
12970
63436719d12e
Add new parser error code, E_OVERFLOW. This error is returned when
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
5379
diff
changeset
|
112 return 0; |
| 6 | 113 } |
|
76
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
114 |
| 86 | 115 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
116 static void freechildren(node *); |
| 86 | 117 |
| 118 | |
| 119 void | |
| 13659 | 120 PyNode_Free(node *n) |
| 86 | 121 { |
| 122 if (n != NULL) { | |
| 123 freechildren(n); | |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24241
diff
changeset
|
124 PyObject_FREE(n); |
| 86 | 125 } |
| 126 } | |
| 127 | |
|
76
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
128 static void |
| 13659 | 129 freechildren(node *n) |
|
76
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
130 { |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
131 int i; |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
132 for (i = NCH(n); --i >= 0; ) |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
133 freechildren(CHILD(n, i)); |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
134 if (n->n_child != NULL) |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24241
diff
changeset
|
135 PyObject_FREE(n->n_child); |
|
76
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
136 if (STR(n) != NULL) |
|
24529
3444005b6527
SF patch #578297:
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
24241
diff
changeset
|
137 PyObject_FREE(STR(n)); |
|
76
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
138 } |
