Mercurial > cpython-lru_cache-weakref
annotate Objects/frameobject.c @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | 537bfce2b730 |
| children | f874243ee39b 53f9069fc650 |
| rev | line source |
|---|---|
| 145 | 1 |
| 86 | 2 /* Frame object implementation */ |
| 3 | |
| 5350 | 4 #include "Python.h" |
| 86 | 5 |
| 6 #include "compile.h" | |
| 7 #include "frameobject.h" | |
| 8 #include "opcode.h" | |
| 9 #include "structmember.h" | |
| 10 | |
|
26709
89317d93f639
Undefine MIN and MAX before defining
Neal Norwitz <nnorwitz@gmail.com>
parents:
26686
diff
changeset
|
11 #undef MIN |
|
89317d93f639
Undefine MIN and MAX before defining
Neal Norwitz <nnorwitz@gmail.com>
parents:
26686
diff
changeset
|
12 #undef MAX |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
13 #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
14 #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
15 |
| 5350 | 16 #define OFF(x) offsetof(PyFrameObject, x) |
| 86 | 17 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19588
diff
changeset
|
18 static PyMemberDef frame_memberlist[] = { |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
19 {"f_back", T_OBJECT, OFF(f_back), RO}, |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
20 {"f_code", T_OBJECT, OFF(f_code), RO}, |
|
2104
7493c6805dc6
add builtins handling and restricted flag
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
21 {"f_builtins", T_OBJECT, OFF(f_builtins),RO}, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
22 {"f_globals", T_OBJECT, OFF(f_globals), RO}, |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
23 {"f_lasti", T_INT, OFF(f_lasti), RO}, |
|
2104
7493c6805dc6
add builtins handling and restricted flag
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
24 {"f_restricted",T_INT, OFF(f_restricted),RO}, |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
25 {"f_exc_type", T_OBJECT, OFF(f_exc_type)}, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
26 {"f_exc_value", T_OBJECT, OFF(f_exc_value)}, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
27 {"f_exc_traceback", T_OBJECT, OFF(f_exc_traceback)}, |
| 86 | 28 {NULL} /* Sentinel */ |
| 29 }; | |
| 30 | |
| 5350 | 31 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
32 frame_getlocals(PyFrameObject *f, void *closure) |
| 86 | 33 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
34 PyFrame_FastToLocals(f); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
35 Py_INCREF(f->f_locals); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
36 return f->f_locals; |
| 86 | 37 } |
| 38 | |
| 24844 | 39 static PyObject * |
| 40 frame_getlineno(PyFrameObject *f, void *closure) | |
| 41 { | |
| 42 int lineno; | |
| 43 | |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
44 if (f->f_trace) |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
45 lineno = f->f_lineno; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
46 else |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
47 lineno = PyCode_Addr2Line(f->f_code, f->f_lasti); |
| 24844 | 48 |
| 49 return PyInt_FromLong(lineno); | |
| 50 } | |
| 51 | |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
52 /* Setter for f_lineno - you can set f_lineno from within a trace function in |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
53 * order to jump to a given line of code, subject to some restrictions. Most |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
54 * lines are OK to jump to because they don't make any assumptions about the |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
55 * state of the stack (obvious because you could remove the line and the code |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
56 * would still work without any stack errors), but there are some constructs |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
57 * that limit jumping: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
58 * |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
59 * o Lines with an 'except' statement on them can't be jumped to, because |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
60 * they expect an exception to be on the top of the stack. |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
61 * o Lines that live in a 'finally' block can't be jumped from or to, since |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
62 * the END_FINALLY expects to clean up the stack after the 'try' block. |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
63 * o 'try'/'for'/'while' blocks can't be jumped into because the blockstack |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
64 * needs to be set up before their code runs, and for 'for' loops the |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
65 * iterator needs to be on the stack. |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
66 */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
67 static int |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
68 frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno) |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
69 { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
70 int new_lineno = 0; /* The new value of f_lineno */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
71 int new_lasti = 0; /* The new value of f_lasti */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
72 int new_iblock = 0; /* The new value of f_iblock */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
73 char *code = NULL; /* The bytecode for the frame... */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
74 int code_len = 0; /* ...and its length */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
75 char *lnotab = NULL; /* Iterating over co_lnotab */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
76 int lnotab_len = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
77 int offset = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
78 int line = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
79 int addr = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
80 int min_addr = 0; /* Scanning the SETUPs and POPs */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
81 int max_addr = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
82 int delta_iblock = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
83 int min_delta_iblock = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
84 int min_iblock = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
85 int f_lasti_setup_addr = 0; /* Policing no-jump-into-finally */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
86 int new_lasti_setup_addr = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
87 int blockstack[CO_MAXBLOCKS]; /* Walking the 'finally' blocks */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
88 int in_finally[CO_MAXBLOCKS]; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
89 int blockstack_top = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
90 int setup_op = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
91 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
92 /* f_lineno must be an integer. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
93 if (!PyInt_Check(p_new_lineno)) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
94 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
95 "lineno must be an integer"); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
96 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
97 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
98 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
99 /* You can only do this from within a trace function, not via |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
100 * _getframe or similar hackery. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
101 if (!f->f_trace) |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
102 { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
103 PyErr_Format(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
104 "f_lineno can only be set by a trace function"); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
105 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
106 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
107 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
108 /* Fail if the line comes before the start of the code block. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
109 new_lineno = (int) PyInt_AsLong(p_new_lineno); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
110 if (new_lineno < f->f_code->co_firstlineno) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
111 PyErr_Format(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
112 "line %d comes before the current code block", |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
113 new_lineno); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
114 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
115 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
116 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
117 /* Find the bytecode offset for the start of the given line, or the |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
118 * first code-owning line after it. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
119 PyString_AsStringAndSize(f->f_code->co_lnotab, &lnotab, &lnotab_len); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
120 addr = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
121 line = f->f_code->co_firstlineno; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
122 new_lasti = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
123 for (offset = 0; offset < lnotab_len; offset += 2) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
124 addr += lnotab[offset]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
125 line += lnotab[offset+1]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
126 if (line >= new_lineno) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
127 new_lasti = addr; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
128 new_lineno = line; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
129 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
130 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
131 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
132 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
133 /* If we didn't reach the requested line, return an error. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
134 if (new_lasti == -1) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
135 PyErr_Format(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
136 "line %d comes after the current code block", |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
137 new_lineno); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
138 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
139 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
140 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
141 /* We're now ready to look at the bytecode. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
142 PyString_AsStringAndSize(f->f_code->co_code, &code, &code_len); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
143 min_addr = MIN(new_lasti, f->f_lasti); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
144 max_addr = MAX(new_lasti, f->f_lasti); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
145 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
146 /* You can't jump onto a line with an 'except' statement on it - |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
147 * they expect to have an exception on the top of the stack, which |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
148 * won't be true if you jump to them. They always start with code |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
149 * that either pops the exception using POP_TOP (plain 'except:' |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
150 * lines do this) or duplicates the exception on the stack using |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
151 * DUP_TOP (if there's an exception type specified). See compile.c, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
152 * 'com_try_except' for the full details. There aren't any other |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
153 * cases (AFAIK) where a line's code can start with DUP_TOP or |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
154 * POP_TOP, but if any ever appear, they'll be subject to the same |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
155 * restriction (but with a different error message). */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
156 if (code[new_lasti] == DUP_TOP || code[new_lasti] == POP_TOP) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
157 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
158 "can't jump to 'except' line as there's no exception"); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
159 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
160 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
161 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
162 /* You can't jump into or out of a 'finally' block because the 'try' |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
163 * block leaves something on the stack for the END_FINALLY to clean |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
164 * up. So we walk the bytecode, maintaining a simulated blockstack. |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
165 * When we reach the old or new address and it's in a 'finally' block |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
166 * we note the address of the corresponding SETUP_FINALLY. The jump |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
167 * is only legal if neither address is in a 'finally' block or |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
168 * they're both in the same one. 'blockstack' is a stack of the |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
169 * bytecode addresses of the SETUP_X opcodes, and 'in_finally' tracks |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
170 * whether we're in a 'finally' block at each blockstack level. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
171 f_lasti_setup_addr = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
172 new_lasti_setup_addr = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
173 memset(blockstack, '\0', sizeof(blockstack)); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
174 memset(in_finally, '\0', sizeof(in_finally)); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
175 blockstack_top = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
176 for (addr = 0; addr < code_len; addr++) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
177 unsigned char op = code[addr]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
178 switch (op) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
179 case SETUP_LOOP: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
180 case SETUP_EXCEPT: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
181 case SETUP_FINALLY: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
182 blockstack[blockstack_top++] = addr; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
183 in_finally[blockstack_top-1] = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
184 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
185 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
186 case POP_BLOCK: |
|
26717
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
187 assert(blockstack_top > 0); |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
188 setup_op = code[blockstack[blockstack_top-1]]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
189 if (setup_op == SETUP_FINALLY) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
190 in_finally[blockstack_top-1] = 1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
191 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
192 else { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
193 blockstack_top--; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
194 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
195 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
196 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
197 case END_FINALLY: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
198 /* Ignore END_FINALLYs for SETUP_EXCEPTs - they exist |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
199 * in the bytecode but don't correspond to an actual |
|
26717
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
200 * 'finally' block. (If blockstack_top is 0, we must |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
201 * be seeing such an END_FINALLY.) */ |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
202 if (blockstack_top > 0) { |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
203 setup_op = code[blockstack[blockstack_top-1]]; |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
204 if (setup_op == SETUP_FINALLY) { |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
205 blockstack_top--; |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
206 } |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
207 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
208 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
209 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
210 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
211 /* For the addresses we're interested in, see whether they're |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
212 * within a 'finally' block and if so, remember the address |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
213 * of the SETUP_FINALLY. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
214 if (addr == new_lasti || addr == f->f_lasti) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
215 int i = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
216 int setup_addr = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
217 for (i = blockstack_top-1; i >= 0; i--) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
218 if (in_finally[i]) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
219 setup_addr = blockstack[i]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
220 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
221 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
222 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
223 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
224 if (setup_addr != -1) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
225 if (addr == new_lasti) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
226 new_lasti_setup_addr = setup_addr; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
227 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
228 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
229 if (addr == f->f_lasti) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
230 f_lasti_setup_addr = setup_addr; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
231 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
232 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
233 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
234 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
235 if (op >= HAVE_ARGUMENT) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
236 addr += 2; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
237 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
238 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
239 |
|
26717
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
240 /* Verify that the blockstack tracking code didn't get lost. */ |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
241 assert(blockstack_top == 0); |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
242 |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
243 /* After all that, are we jumping into / out of a 'finally' block? */ |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
244 if (new_lasti_setup_addr != f_lasti_setup_addr) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
245 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
246 "can't jump into or out of a 'finally' block"); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
247 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
248 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
249 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
250 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
251 /* Police block-jumping (you can't jump into the middle of a block) |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
252 * and ensure that the blockstack finishes up in a sensible state (by |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
253 * popping any blocks we're jumping out of). We look at all the |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
254 * blockstack operations between the current position and the new |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
255 * one, and keep track of how many blocks we drop out of on the way. |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
256 * By also keeping track of the lowest blockstack position we see, we |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
257 * can tell whether the jump goes into any blocks without coming out |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
258 * again - in that case we raise an exception below. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
259 delta_iblock = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
260 for (addr = min_addr; addr < max_addr; addr++) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
261 unsigned char op = code[addr]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
262 switch (op) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
263 case SETUP_LOOP: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
264 case SETUP_EXCEPT: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
265 case SETUP_FINALLY: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
266 delta_iblock++; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
267 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
268 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
269 case POP_BLOCK: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
270 delta_iblock--; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
271 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
272 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
273 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
274 min_delta_iblock = MIN(min_delta_iblock, delta_iblock); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
275 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
276 if (op >= HAVE_ARGUMENT) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
277 addr += 2; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
278 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
279 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
280 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
281 /* Derive the absolute iblock values from the deltas. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
282 min_iblock = f->f_iblock + min_delta_iblock; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
283 if (new_lasti > f->f_lasti) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
284 /* Forwards jump. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
285 new_iblock = f->f_iblock + delta_iblock; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
286 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
287 else { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
288 /* Backwards jump. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
289 new_iblock = f->f_iblock - delta_iblock; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
290 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
291 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
292 /* Are we jumping into a block? */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
293 if (new_iblock > min_iblock) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
294 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
295 "can't jump into the middle of a block"); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
296 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
297 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
298 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
299 /* Pop any blocks that we're jumping out of. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
300 while (f->f_iblock > new_iblock) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
301 PyTryBlock *b = &f->f_blockstack[--f->f_iblock]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
302 while ((f->f_stacktop - f->f_valuestack) > b->b_level) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
303 PyObject *v = (*--f->f_stacktop); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
304 Py_DECREF(v); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
305 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
306 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
307 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
308 /* Finally set the new f_lineno and f_lasti and return OK. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
309 f->f_lineno = new_lineno; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
310 f->f_lasti = new_lasti; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
311 return 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
312 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
313 |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
314 static PyObject * |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
315 frame_gettrace(PyFrameObject *f, void *closure) |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
316 { |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
317 PyObject* trace = f->f_trace; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
318 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
319 if (trace == NULL) |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
320 trace = Py_None; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
321 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
322 Py_INCREF(trace); |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
323 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
324 return trace; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
325 } |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
326 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
327 static int |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
328 frame_settrace(PyFrameObject *f, PyObject* v, void *closure) |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
329 { |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
330 /* We rely on f_lineno being accurate when f_trace is set. */ |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
331 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
332 PyObject* old_value = f->f_trace; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
333 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
334 Py_XINCREF(v); |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
335 f->f_trace = v; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
336 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
337 if (v != NULL) |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
338 f->f_lineno = PyCode_Addr2Line(f->f_code, f->f_lasti); |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
339 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
340 Py_XDECREF(old_value); |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
341 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
342 return 0; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
343 } |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
344 |
|
20015
ca7af2a5d915
Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents:
20012
diff
changeset
|
345 static PyGetSetDef frame_getsetlist[] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
346 {"f_locals", (getter)frame_getlocals, NULL, NULL}, |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
347 {"f_lineno", (getter)frame_getlineno, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
348 (setter)frame_setlineno, NULL}, |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
349 {"f_trace", (getter)frame_gettrace, (setter)frame_settrace, NULL}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
350 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
351 }; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
352 |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
353 /* Stack frames are allocated and deallocated at a considerable rate. |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
354 In an attempt to improve the speed of function calls, we maintain a |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
355 separate free list of stack frames (just like integers are |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
356 allocated in a special way -- see intobject.c). When a stack frame |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
357 is on the free list, only the following members have a meaning: |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
358 ob_type == &Frametype |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
359 f_back next item on free list, or NULL |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
360 f_nlocals number of locals |
|
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
361 f_stacksize size of value stack |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
362 ob_size size of localsplus |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
363 Note that the value and block stacks are preserved -- this can save |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
364 another malloc() call or two (and two free() calls as well!). |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
365 Also note that, unlike for integers, each frame object is a |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
366 malloc'ed object in its own right -- it is only the actual calls to |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
367 malloc() that we are trying to save here, not the administration. |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
368 After all, while a typical program may make millions of calls, a |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
369 call depth of more than 20 or 30 is probably already exceptional |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
370 unless the program contains run-away recursion. I hope. |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
371 |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
372 Later, MAXFREELIST was added to bound the # of frames saved on |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
373 free_list. Else programs creating lots of cyclic trash involving |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
374 frames could provoke free_list into growing without bound. |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
375 */ |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
376 |
| 5350 | 377 static PyFrameObject *free_list = NULL; |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
378 static int numfree = 0; /* number of frames currently in free_list */ |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
379 #define MAXFREELIST 200 /* max value for numfree */ |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
380 |
| 86 | 381 static void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
382 frame_dealloc(PyFrameObject *f) |
| 86 | 383 { |
|
17034
ba81d79dc3a3
Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16355
diff
changeset
|
384 int i, slots; |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
385 PyObject **fastlocals; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17701
diff
changeset
|
386 PyObject **p; |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
387 |
| 22626 | 388 PyObject_GC_UnTrack(f); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
389 Py_TRASHCAN_SAFE_BEGIN(f) |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
390 /* Kill all local variables */ |
|
17034
ba81d79dc3a3
Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16355
diff
changeset
|
391 slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
392 fastlocals = f->f_localsplus; |
|
17034
ba81d79dc3a3
Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16355
diff
changeset
|
393 for (i = slots; --i >= 0; ++fastlocals) { |
| 5350 | 394 Py_XDECREF(*fastlocals); |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
395 } |
|
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
396 |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17701
diff
changeset
|
397 /* Free stack */ |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
398 if (f->f_stacktop != NULL) { |
|
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
399 for (p = f->f_valuestack; p < f->f_stacktop; p++) |
|
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
400 Py_XDECREF(*p); |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17701
diff
changeset
|
401 } |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
402 |
| 5350 | 403 Py_XDECREF(f->f_back); |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
404 Py_DECREF(f->f_code); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
405 Py_DECREF(f->f_builtins); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
406 Py_DECREF(f->f_globals); |
| 5350 | 407 Py_XDECREF(f->f_locals); |
| 408 Py_XDECREF(f->f_trace); | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
409 Py_XDECREF(f->f_exc_type); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
410 Py_XDECREF(f->f_exc_value); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
411 Py_XDECREF(f->f_exc_traceback); |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
412 if (numfree < MAXFREELIST) { |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
413 ++numfree; |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
414 f->f_back = free_list; |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
415 free_list = f; |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
416 } |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
417 else |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
418 PyObject_GC_Del(f); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
419 Py_TRASHCAN_SAFE_END(f) |
| 86 | 420 } |
| 421 | |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
422 static int |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
423 frame_traverse(PyFrameObject *f, visitproc visit, void *arg) |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
424 { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
425 PyObject **fastlocals, **p; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
426 int i, err, slots; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
427 #define VISIT(o) if (o) {if ((err = visit((PyObject *)(o), arg))) return err;} |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
428 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
429 VISIT(f->f_back); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
430 VISIT(f->f_code); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
431 VISIT(f->f_builtins); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
432 VISIT(f->f_globals); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
433 VISIT(f->f_locals); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
434 VISIT(f->f_trace); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
435 VISIT(f->f_exc_type); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
436 VISIT(f->f_exc_value); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
437 VISIT(f->f_exc_traceback); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
438 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
439 /* locals */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
440 slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
441 fastlocals = f->f_localsplus; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
442 for (i = slots; --i >= 0; ++fastlocals) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
443 VISIT(*fastlocals); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
444 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
445 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
446 /* stack */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
447 if (f->f_stacktop != NULL) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
448 for (p = f->f_valuestack; p < f->f_stacktop; p++) |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
449 VISIT(*p); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
450 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
451 return 0; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
452 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
453 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
454 static void |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
455 frame_clear(PyFrameObject *f) |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
456 { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
457 PyObject **fastlocals, **p; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
458 int i, slots; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
459 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
460 Py_XDECREF(f->f_exc_type); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
461 f->f_exc_type = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
462 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
463 Py_XDECREF(f->f_exc_value); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
464 f->f_exc_value = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
465 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
466 Py_XDECREF(f->f_exc_traceback); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
467 f->f_exc_traceback = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
468 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
469 Py_XDECREF(f->f_trace); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
470 f->f_trace = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
471 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
472 /* locals */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
473 slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
474 fastlocals = f->f_localsplus; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
475 for (i = slots; --i >= 0; ++fastlocals) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
476 if (*fastlocals != NULL) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
477 Py_XDECREF(*fastlocals); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
478 *fastlocals = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
479 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
480 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
481 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
482 /* stack */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
483 if (f->f_stacktop != NULL) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
484 for (p = f->f_valuestack; p < f->f_stacktop; p++) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
485 Py_XDECREF(*p); |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
486 *p = NULL; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
487 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
488 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
489 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
490 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
491 |
| 5350 | 492 PyTypeObject PyFrame_Type = { |
| 493 PyObject_HEAD_INIT(&PyType_Type) | |
| 86 | 494 0, |
| 495 "frame", | |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
496 sizeof(PyFrameObject), |
|
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
497 sizeof(PyObject *), |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
498 (destructor)frame_dealloc, /* tp_dealloc */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
499 0, /* tp_print */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
500 0, /* tp_getattr */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
501 0, /* tp_setattr */ |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
502 0, /* tp_compare */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
503 0, /* tp_repr */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
504 0, /* tp_as_number */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
505 0, /* tp_as_sequence */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
506 0, /* tp_as_mapping */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
507 0, /* tp_hash */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
508 0, /* tp_call */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
509 0, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
510 PyObject_GenericGetAttr, /* tp_getattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
511 PyObject_GenericSetAttr, /* tp_setattro */ |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
512 0, /* tp_as_buffer */ |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
513 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
514 0, /* tp_doc */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
515 (traverseproc)frame_traverse, /* tp_traverse */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
516 (inquiry)frame_clear, /* tp_clear */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
517 0, /* tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
518 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
519 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
520 0, /* tp_iternext */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
521 0, /* tp_methods */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
522 frame_memberlist, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
523 frame_getsetlist, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
524 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
525 0, /* tp_dict */ |
| 86 | 526 }; |
| 527 | |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
528 static PyObject *builtin_object; |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
529 |
|
26923
dbfc3ef7d003
Since the *_Init() are private, prefix with _, suggested by Skip
Neal Norwitz <nnorwitz@gmail.com>
parents:
26889
diff
changeset
|
530 int _PyFrame_Init() |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
531 { |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
532 builtin_object = PyString_InternFromString("__builtins__"); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
533 return (builtin_object != NULL); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
534 } |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
535 |
| 5350 | 536 PyFrameObject * |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
537 PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals, |
|
17034
ba81d79dc3a3
Variety of small INC/DECREF patches that fix reported memory leaks
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16355
diff
changeset
|
538 PyObject *locals) |
| 86 | 539 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
540 PyFrameObject *back = tstate->frame; |
| 5350 | 541 PyFrameObject *f; |
| 542 PyObject *builtins; | |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
543 int extras, ncells, nfrees; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
544 |
|
24895
c8d9592c9e74
Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents:
24844
diff
changeset
|
545 #ifdef Py_DEBUG |
|
c8d9592c9e74
Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents:
24844
diff
changeset
|
546 if (code == NULL || globals == NULL || !PyDict_Check(globals) || |
| 5350 | 547 (locals != NULL && !PyDict_Check(locals))) { |
| 548 PyErr_BadInternalCall(); | |
| 86 | 549 return NULL; |
| 550 } | |
|
24895
c8d9592c9e74
Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents:
24844
diff
changeset
|
551 #endif |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
552 ncells = PyTuple_GET_SIZE(code->co_cellvars); |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
553 nfrees = PyTuple_GET_SIZE(code->co_freevars); |
|
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
554 extras = code->co_stacksize + code->co_nlocals + ncells + nfrees; |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
555 if (back == NULL || back->f_globals != globals) { |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
556 builtins = PyDict_GetItem(globals, builtin_object); |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
557 if (builtins) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
558 if (PyModule_Check(builtins)) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
559 builtins = PyModule_GetDict(builtins); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
560 assert(!builtins || PyDict_Check(builtins)); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
561 } |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
562 else if (!PyDict_Check(builtins)) |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
563 builtins = NULL; |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
564 } |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
565 if (builtins == NULL) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
566 /* No builtins! Make up a minimal one |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
567 Give them 'None', at least. */ |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
568 builtins = PyDict_New(); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
569 if (builtins == NULL || |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
570 PyDict_SetItemString( |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
571 builtins, "None", Py_None) < 0) |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
572 return NULL; |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
573 } |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
574 else |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
575 Py_INCREF(builtins); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
576 |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
577 } |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
578 else { |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
579 /* If we share the globals, we share the builtins. |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
580 Save a lookup and a call. */ |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
581 builtins = back->f_builtins; |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
582 assert(builtins != NULL && PyDict_Check(builtins)); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
583 Py_INCREF(builtins); |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
584 } |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
585 if (free_list == NULL) { |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
586 f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
587 if (f == NULL) |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
588 return NULL; |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
589 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
590 else { |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
591 assert(numfree > 0); |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
592 --numfree; |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
593 f = free_list; |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
594 free_list = free_list->f_back; |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
595 if (f->ob_size < extras) { |
|
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
596 f = PyObject_GC_Resize(PyFrameObject, f, extras); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
597 if (f == NULL) |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
598 return NULL; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
599 } |
|
19588
2fe08918fac6
Squash new compiler wng in debug build.
Tim Peters <tim.peters@gmail.com>
parents:
19579
diff
changeset
|
600 _Py_NewReference((PyObject *)f); |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
601 } |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
602 f->f_builtins = builtins; |
| 5350 | 603 Py_XINCREF(back); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
604 f->f_back = back; |
| 5350 | 605 Py_INCREF(code); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
606 f->f_code = code; |
| 5350 | 607 Py_INCREF(globals); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
608 f->f_globals = globals; |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
609 /* Most functions have CO_NEWLOCALS and CO_OPTIMIZED set. */ |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
610 if ((code->co_flags & (CO_NEWLOCALS | CO_OPTIMIZED)) == |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
611 (CO_NEWLOCALS | CO_OPTIMIZED)) |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
612 locals = NULL; /* PyFrame_Fast2Locals() will set. */ |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
613 else if (code->co_flags & CO_NEWLOCALS) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
614 locals = PyDict_New(); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
615 if (locals == NULL) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
616 Py_DECREF(f); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
617 return NULL; |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
618 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
619 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
620 else { |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
621 if (locals == NULL) |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
622 locals = globals; |
| 5350 | 623 Py_INCREF(locals); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
624 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
625 f->f_locals = locals; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
626 f->f_trace = NULL; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
627 f->f_exc_type = f->f_exc_value = f->f_exc_traceback = NULL; |
|
5921
800a5217e67e
Avoid function calls to access the current thread state and builtins
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
628 f->f_tstate = tstate; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
629 |
| 24844 | 630 f->f_lasti = -1; |
|
5045
b1d82697c0b2
When a recycled frame has more local+stack slots than needed,
Guido van Rossum <guido@python.org>
parents:
5015
diff
changeset
|
631 f->f_lineno = code->co_firstlineno; |
|
5921
800a5217e67e
Avoid function calls to access the current thread state and builtins
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
632 f->f_restricted = (builtins != tstate->interp->builtins); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
633 f->f_iblock = 0; |
|
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
634 f->f_nlocals = code->co_nlocals; |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
635 f->f_stacksize = code->co_stacksize; |
|
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
636 f->f_ncells = ncells; |
|
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
637 f->f_nfreevars = nfrees; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
638 |
|
24462
a1bddf6a32ca
Tim found that once test_longexp has run, test_sort takes very much
Guido van Rossum <guido@python.org>
parents:
23186
diff
changeset
|
639 extras = f->f_nlocals + ncells + nfrees; |
|
a1bddf6a32ca
Tim found that once test_longexp has run, test_sort takes very much
Guido van Rossum <guido@python.org>
parents:
23186
diff
changeset
|
640 memset(f->f_localsplus, 0, extras * sizeof(f->f_localsplus[0])); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
641 |
|
24462
a1bddf6a32ca
Tim found that once test_longexp has run, test_sort takes very much
Guido van Rossum <guido@python.org>
parents:
23186
diff
changeset
|
642 f->f_valuestack = f->f_localsplus + extras; |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
643 f->f_stacktop = f->f_valuestack; |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
644 _PyObject_GC_TRACK(f); |
| 86 | 645 return f; |
| 646 } | |
| 647 | |
| 648 /* Block management */ | |
| 649 | |
| 650 void | |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
651 PyFrame_BlockSetup(PyFrameObject *f, int type, int handler, int level) |
| 86 | 652 { |
| 5350 | 653 PyTryBlock *b; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
654 if (f->f_iblock >= CO_MAXBLOCKS) |
| 5350 | 655 Py_FatalError("XXX block stack overflow"); |
| 86 | 656 b = &f->f_blockstack[f->f_iblock++]; |
| 657 b->b_type = type; | |
| 658 b->b_level = level; | |
| 659 b->b_handler = handler; | |
| 660 } | |
| 661 | |
| 5350 | 662 PyTryBlock * |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
663 PyFrame_BlockPop(PyFrameObject *f) |
| 86 | 664 { |
| 5350 | 665 PyTryBlock *b; |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
666 if (f->f_iblock <= 0) |
| 5350 | 667 Py_FatalError("XXX block stack underflow"); |
| 86 | 668 b = &f->f_blockstack[--f->f_iblock]; |
| 669 return b; | |
| 670 } | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
671 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
672 /* Convert between "fast" version of locals and dictionary version */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
673 |
|
17518
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
17104
diff
changeset
|
674 static void |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
675 map_to_dict(PyObject *map, int nmap, PyObject *dict, PyObject **values, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
676 int deref) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
677 { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
678 int j; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
679 for (j = nmap; --j >= 0; ) { |
|
21255
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
680 PyObject *key = PyTuple_GET_ITEM(map, j); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
681 PyObject *value = values[j]; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
682 if (deref) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
683 value = PyCell_GET(value); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
684 if (value == NULL) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
685 if (PyDict_DelItem(dict, key) != 0) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
686 PyErr_Clear(); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
687 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
688 else { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
689 if (PyDict_SetItem(dict, key, value) != 0) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
690 PyErr_Clear(); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
691 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
692 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
693 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
694 |
|
17519
f9dfd587c142
Make one more private symbol static.
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
695 static void |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
696 dict_to_map(PyObject *map, int nmap, PyObject *dict, PyObject **values, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
697 int deref, int clear) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
698 { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
699 int j; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
700 for (j = nmap; --j >= 0; ) { |
|
21255
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
701 PyObject *key = PyTuple_GET_ITEM(map, j); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
702 PyObject *value = PyDict_GetItem(dict, key); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
703 if (deref) { |
|
17701
ded41be84da4
SF patch 419176 from MvL; fixed bug 418977
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17519
diff
changeset
|
704 if (value || clear) { |
|
21255
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
705 if (PyCell_GET(values[j]) != value) { |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
706 if (PyCell_Set(values[j], value) < 0) |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
707 PyErr_Clear(); |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
708 } |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
709 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
710 } else if (value != NULL || clear) { |
|
21255
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
711 if (values[j] != value) { |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
712 Py_XINCREF(value); |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
713 Py_XDECREF(values[j]); |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
714 values[j] = value; |
|
14507671c02c
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20015
diff
changeset
|
715 } |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
716 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
717 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
718 } |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
719 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
720 void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
721 PyFrame_FastToLocals(PyFrameObject *f) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
722 { |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
723 /* Merge fast locals into f->f_locals */ |
| 5350 | 724 PyObject *locals, *map; |
| 725 PyObject **fast; | |
| 726 PyObject *error_type, *error_value, *error_traceback; | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
727 int j; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
728 if (f == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
729 return; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
730 locals = f->f_locals; |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
731 if (locals == NULL) { |
| 5350 | 732 locals = f->f_locals = PyDict_New(); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
733 if (locals == NULL) { |
| 5350 | 734 PyErr_Clear(); /* Can't report it :-( */ |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
735 return; |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
736 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
737 } |
|
2856
a7af970a94a4
better policy regarding NULL locals
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
738 map = f->f_code->co_varnames; |
| 5350 | 739 if (!PyDict_Check(locals) || !PyTuple_Check(map)) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
740 return; |
| 5350 | 741 PyErr_Fetch(&error_type, &error_value, &error_traceback); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
742 fast = f->f_localsplus; |
| 5350 | 743 j = PyTuple_Size(map); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
744 if (j > f->f_nlocals) |
|
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
745 j = f->f_nlocals; |
|
23186
b4352f5a3452
Fix SF bug #505315: Make free and cell vars show up consistently in locals().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23018
diff
changeset
|
746 if (f->f_nlocals) |
|
b4352f5a3452
Fix SF bug #505315: Make free and cell vars show up consistently in locals().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23018
diff
changeset
|
747 map_to_dict(map, j, locals, fast, 0); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
748 if (f->f_ncells || f->f_nfreevars) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
749 if (!(PyTuple_Check(f->f_code->co_cellvars) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
750 && PyTuple_Check(f->f_code->co_freevars))) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
751 Py_DECREF(locals); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
752 return; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
753 } |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
754 map_to_dict(f->f_code->co_cellvars, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
755 PyTuple_GET_SIZE(f->f_code->co_cellvars), |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
756 locals, fast + f->f_nlocals, 1); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
757 map_to_dict(f->f_code->co_freevars, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
758 PyTuple_GET_SIZE(f->f_code->co_freevars), |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
759 locals, fast + f->f_nlocals + f->f_ncells, 1); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
760 } |
| 5350 | 761 PyErr_Restore(error_type, error_value, error_traceback); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
762 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
763 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
764 void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
765 PyFrame_LocalsToFast(PyFrameObject *f, int clear) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
766 { |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
767 /* Merge f->f_locals into fast locals */ |
| 5350 | 768 PyObject *locals, *map; |
| 769 PyObject **fast; | |
| 770 PyObject *error_type, *error_value, *error_traceback; | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
771 int j; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
772 if (f == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
773 return; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
774 locals = f->f_locals; |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
775 map = f->f_code->co_varnames; |
|
23186
b4352f5a3452
Fix SF bug #505315: Make free and cell vars show up consistently in locals().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23018
diff
changeset
|
776 if (locals == NULL) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
777 return; |
| 5350 | 778 if (!PyDict_Check(locals) || !PyTuple_Check(map)) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
779 return; |
| 5350 | 780 PyErr_Fetch(&error_type, &error_value, &error_traceback); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
781 fast = f->f_localsplus; |
| 5350 | 782 j = PyTuple_Size(map); |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
783 if (j > f->f_nlocals) |
|
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
784 j = f->f_nlocals; |
|
23186
b4352f5a3452
Fix SF bug #505315: Make free and cell vars show up consistently in locals().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23018
diff
changeset
|
785 if (f->f_nlocals) |
|
b4352f5a3452
Fix SF bug #505315: Make free and cell vars show up consistently in locals().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23018
diff
changeset
|
786 dict_to_map(f->f_code->co_varnames, j, locals, fast, 0, clear); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
787 if (f->f_ncells || f->f_nfreevars) { |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
788 if (!(PyTuple_Check(f->f_code->co_cellvars) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
789 && PyTuple_Check(f->f_code->co_freevars))) |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
790 return; |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
791 dict_to_map(f->f_code->co_cellvars, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
792 PyTuple_GET_SIZE(f->f_code->co_cellvars), |
|
17701
ded41be84da4
SF patch 419176 from MvL; fixed bug 418977
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17519
diff
changeset
|
793 locals, fast + f->f_nlocals, 1, clear); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
794 dict_to_map(f->f_code->co_freevars, |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
795 PyTuple_GET_SIZE(f->f_code->co_freevars), |
|
23186
b4352f5a3452
Fix SF bug #505315: Make free and cell vars show up consistently in locals().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23018
diff
changeset
|
796 locals, fast + f->f_nlocals + f->f_ncells, 1, |
|
b4352f5a3452
Fix SF bug #505315: Make free and cell vars show up consistently in locals().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23018
diff
changeset
|
797 clear); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
798 } |
| 5350 | 799 PyErr_Restore(error_type, error_value, error_traceback); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
800 } |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
801 |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
802 /* Clear out the free list */ |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
803 |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
804 void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
805 PyFrame_Fini(void) |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
806 { |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
807 while (free_list != NULL) { |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
808 PyFrameObject *f = free_list; |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
809 free_list = free_list->f_back; |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
810 PyObject_GC_Del(f); |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
811 --numfree; |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
812 } |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
813 assert(numfree == 0); |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
814 Py_XDECREF(builtin_object); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
815 builtin_object = NULL; |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
816 } |
