Mercurial > cpython-lru_cache-weakref
annotate Objects/frameobject.c @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | db88a67e38ee |
| children | e38335d4df91 |
| rev | line source |
|---|---|
| 86 | 1 /* Frame object implementation */ |
| 2 | |
| 5350 | 3 #include "Python.h" |
| 86 | 4 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
32463
diff
changeset
|
5 #include "code.h" |
| 86 | 6 #include "frameobject.h" |
| 7 #include "opcode.h" | |
| 8 #include "structmember.h" | |
| 9 | |
|
26709
89317d93f639
Undefine MIN and MAX before defining
Neal Norwitz <nnorwitz@gmail.com>
parents:
26686
diff
changeset
|
10 #undef MIN |
|
89317d93f639
Undefine MIN and MAX before defining
Neal Norwitz <nnorwitz@gmail.com>
parents:
26686
diff
changeset
|
11 #undef MAX |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
12 #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
|
13 #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
|
14 |
| 5350 | 15 #define OFF(x) offsetof(PyFrameObject, x) |
| 86 | 16 |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19588
diff
changeset
|
17 static PyMemberDef frame_memberlist[] = { |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
18 {"f_back", T_OBJECT, OFF(f_back), RO}, |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
19 {"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
|
20 {"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
|
21 {"f_globals", T_OBJECT, OFF(f_globals), RO}, |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
22 {"f_lasti", T_INT, OFF(f_lasti), RO}, |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
23 {"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
|
24 {"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
|
25 {"f_exc_traceback", T_OBJECT, OFF(f_exc_traceback)}, |
| 86 | 26 {NULL} /* Sentinel */ |
| 27 }; | |
| 28 | |
| 5350 | 29 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
30 frame_getlocals(PyFrameObject *f, void *closure) |
| 86 | 31 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
32 PyFrame_FastToLocals(f); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
33 Py_INCREF(f->f_locals); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
34 return f->f_locals; |
| 86 | 35 } |
| 36 | |
| 24844 | 37 static PyObject * |
| 38 frame_getlineno(PyFrameObject *f, void *closure) | |
| 39 { | |
| 40 int lineno; | |
| 41 | |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
42 if (f->f_trace) |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
43 lineno = f->f_lineno; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
44 else |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
45 lineno = PyCode_Addr2Line(f->f_code, f->f_lasti); |
| 24844 | 46 |
| 47 return PyInt_FromLong(lineno); | |
| 48 } | |
| 49 | |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
50 /* Setter for f_lineno - you can set f_lineno from within a trace function in |
| 40971 | 51 * order to jump to a given line of code, subject to some restrictions. Most |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
52 * 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
|
53 * 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
|
54 * 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
|
55 * that limit jumping: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
56 * |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
57 * 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
|
58 * 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
|
59 * 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
|
60 * 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
|
61 * 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
|
62 * 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
|
63 * iterator needs to be on the stack. |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
64 */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
65 static int |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
66 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
|
67 { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
68 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
|
69 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
|
70 int new_iblock = 0; /* The new value of f_iblock */ |
|
41458
0d1e415ec36c
Fix a bug when using the __lltrace__ opcode tracer, and a problem sith signed chars in frameobject.c which can occur with opcodes > 127
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
40971
diff
changeset
|
71 unsigned char *code = NULL; /* The bytecode for the frame... */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
72 Py_ssize_t code_len = 0; /* ...and its length */ |
|
54494
52295ebcca31
Merged revisions 73114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
53243
diff
changeset
|
73 unsigned char *lnotab = NULL; /* Iterating over co_lnotab */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
74 Py_ssize_t lnotab_len = 0; /* (ditto) */ |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
75 int offset = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
76 int line = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
77 int addr = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
78 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
|
79 int max_addr = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
80 int delta_iblock = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
81 int min_delta_iblock = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
82 int min_iblock = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
83 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
|
84 int new_lasti_setup_addr = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
85 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
|
86 int in_finally[CO_MAXBLOCKS]; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
87 int blockstack_top = 0; /* (ditto) */ |
|
41458
0d1e415ec36c
Fix a bug when using the __lltrace__ opcode tracer, and a problem sith signed chars in frameobject.c which can occur with opcodes > 127
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
40971
diff
changeset
|
88 unsigned char setup_op = 0; /* (ditto) */ |
|
54506
db88a67e38ee
Merged revisions 73129 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54495
diff
changeset
|
89 char *tmp; |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
90 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
91 /* f_lineno must be an integer. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
92 if (!PyInt_Check(p_new_lineno)) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
93 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
94 "lineno must be an integer"); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
95 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
96 } |
|
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 /* 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
|
99 * _getframe or similar hackery. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
100 if (!f->f_trace) |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
101 { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
102 PyErr_Format(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
103 "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
|
104 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
105 } |
|
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 /* 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
|
108 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
|
109 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
|
110 PyErr_Format(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
111 "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
|
112 new_lineno); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
113 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
114 } |
|
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 /* 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
|
117 * first code-owning line after it. */ |
|
54495
a563bcf1a62d
#4547 again: fix a typo that causes compilation warnings
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54494
diff
changeset
|
118 PyString_AsStringAndSize(f->f_code->co_lnotab, |
|
54506
db88a67e38ee
Merged revisions 73129 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54495
diff
changeset
|
119 &tmp, &lnotab_len); |
|
db88a67e38ee
Merged revisions 73129 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54495
diff
changeset
|
120 lnotab = (unsigned char *) tmp; |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
121 addr = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
122 line = f->f_code->co_firstlineno; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
123 new_lasti = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
124 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
|
125 addr += lnotab[offset]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
126 line += lnotab[offset+1]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
127 if (line >= new_lineno) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
128 new_lasti = addr; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
129 new_lineno = line; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
130 break; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
134 /* 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
|
135 if (new_lasti == -1) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
136 PyErr_Format(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
137 "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
|
138 new_lineno); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
139 return -1; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
142 /* We're now ready to look at the bytecode. */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
143 PyString_AsStringAndSize(f->f_code->co_code, (char **)&code, &code_len); |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
144 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
|
145 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
|
146 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
147 /* 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
|
148 * 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
|
149 * 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
|
150 * 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
|
151 * 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
|
152 * 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
|
153 * '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
|
154 * 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
|
155 * 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
|
156 * restriction (but with a different error message). */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
157 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
|
158 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
159 "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
|
160 return -1; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
163 /* 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
|
164 * block leaves something on the stack for the END_FINALLY to clean |
| 40971 | 165 * up. So we walk the bytecode, maintaining a simulated blockstack. |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
166 * 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
|
167 * 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
|
168 * 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
|
169 * 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
|
170 * 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
|
171 * 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
|
172 f_lasti_setup_addr = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
173 new_lasti_setup_addr = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
174 memset(blockstack, '\0', sizeof(blockstack)); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
175 memset(in_finally, '\0', sizeof(in_finally)); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
176 blockstack_top = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
177 for (addr = 0; addr < code_len; addr++) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
178 unsigned char op = code[addr]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
179 switch (op) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
180 case SETUP_LOOP: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
181 case SETUP_EXCEPT: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
182 case SETUP_FINALLY: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
183 blockstack[blockstack_top++] = addr; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
184 in_finally[blockstack_top-1] = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
185 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
186 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
187 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
|
188 assert(blockstack_top > 0); |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
189 setup_op = code[blockstack[blockstack_top-1]]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
190 if (setup_op == SETUP_FINALLY) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
191 in_finally[blockstack_top-1] = 1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
192 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
193 else { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
194 blockstack_top--; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
195 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
196 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
197 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
198 case END_FINALLY: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
199 /* 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
|
200 * 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
|
201 * '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
|
202 * 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 } |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
208 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
209 break; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
212 /* 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
|
213 * 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
|
214 * of the SETUP_FINALLY. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
215 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
|
216 int i = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
217 int setup_addr = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
218 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
|
219 if (in_finally[i]) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
220 setup_addr = blockstack[i]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
221 break; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
225 if (setup_addr != -1) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
226 if (addr == new_lasti) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
227 new_lasti_setup_addr = setup_addr; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
230 if (addr == f->f_lasti) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
231 f_lasti_setup_addr = setup_addr; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
236 if (op >= HAVE_ARGUMENT) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
237 addr += 2; |
|
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 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
240 |
|
26717
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
241 /* 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
|
242 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
|
243 |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
244 /* 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
|
245 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
|
246 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
247 "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
|
248 return -1; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
252 /* 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
|
253 * 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
|
254 * 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
|
255 * 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
|
256 * 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
|
257 * 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
|
258 * 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
|
259 * 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
|
260 delta_iblock = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
261 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
|
262 unsigned char op = code[addr]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
263 switch (op) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
264 case SETUP_LOOP: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
265 case SETUP_EXCEPT: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
266 case SETUP_FINALLY: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
267 delta_iblock++; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
268 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
269 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
270 case POP_BLOCK: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
271 delta_iblock--; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
272 break; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
275 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
|
276 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
277 if (op >= HAVE_ARGUMENT) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
278 addr += 2; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
282 /* 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
|
283 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
|
284 if (new_lasti > f->f_lasti) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
285 /* Forwards jump. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
286 new_iblock = f->f_iblock + delta_iblock; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
287 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
288 else { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
289 /* Backwards jump. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
290 new_iblock = f->f_iblock - delta_iblock; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
293 /* Are we jumping into a block? */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
294 if (new_iblock > min_iblock) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
295 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
296 "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
|
297 return -1; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
300 /* 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
|
301 while (f->f_iblock > new_iblock) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
302 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
|
303 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
|
304 PyObject *v = (*--f->f_stacktop); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
305 Py_DECREF(v); |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
309 /* 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
|
310 f->f_lineno = new_lineno; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
311 f->f_lasti = new_lasti; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
312 return 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
313 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
314 |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
315 static PyObject * |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
316 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
|
317 { |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
318 PyObject* trace = f->f_trace; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
319 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
320 if (trace == NULL) |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
321 trace = Py_None; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
322 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
323 Py_INCREF(trace); |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
324 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
325 return trace; |
|
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 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
328 static int |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
329 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
|
330 { |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
331 /* 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
|
332 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
333 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
|
334 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
335 Py_XINCREF(v); |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
336 f->f_trace = v; |
|
37727
62c9038a578a
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
37724
diff
changeset
|
337 |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
338 if (v != NULL) |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
339 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
|
340 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
341 Py_XDECREF(old_value); |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
342 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
343 return 0; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
344 } |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
345 |
|
38766
79983cf634c0
Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38739
diff
changeset
|
346 static PyObject * |
|
79983cf634c0
Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38739
diff
changeset
|
347 frame_getrestricted(PyFrameObject *f, void *closure) |
|
79983cf634c0
Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38739
diff
changeset
|
348 { |
|
79983cf634c0
Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38739
diff
changeset
|
349 return PyBool_FromLong(PyFrame_IsRestricted(f)); |
|
79983cf634c0
Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38739
diff
changeset
|
350 } |
|
79983cf634c0
Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38739
diff
changeset
|
351 |
|
20015
ca7af2a5d915
Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents:
20012
diff
changeset
|
352 static PyGetSetDef frame_getsetlist[] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
353 {"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
|
354 {"f_lineno", (getter)frame_getlineno, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
355 (setter)frame_setlineno, NULL}, |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
356 {"f_trace", (getter)frame_gettrace, (setter)frame_settrace, NULL}, |
|
38766
79983cf634c0
Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents:
38739
diff
changeset
|
357 {"f_restricted",(getter)frame_getrestricted,NULL, NULL}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
358 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
359 }; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
360 |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
361 /* Stack frames are allocated and deallocated at a considerable rate. |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
362 In an attempt to improve the speed of function calls, we: |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
363 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
364 1. Hold a single "zombie" frame on each code object. This retains |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
365 the allocated and initialised frame object from an invocation of |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
366 the code object. The zombie is reanimated the next time we need a |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
367 frame object for that code object. Doing this saves the malloc/ |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
368 realloc required when using a free_list frame that isn't the |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
369 correct size. It also saves some field initialisation. |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
370 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
371 In zombie mode, no field of PyFrameObject holds a reference, but |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
372 the following fields are still valid: |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
373 |
|
38254
bf5fb6e7527c
fix broken merge
Richard Jones <richard@commonground.com.au>
parents:
38253
diff
changeset
|
374 * ob_type, ob_size, f_code, f_valuestack; |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
375 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
376 * f_locals, f_trace, |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
377 f_exc_type, f_exc_value, f_exc_traceback are NULL; |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
378 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
379 * f_localsplus does not require re-allocation and |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
380 the local variables in f_localsplus are NULL. |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
381 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
382 2. We also maintain a separate free list of stack frames (just like |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
383 integers are allocated in a special way -- see intobject.c). When |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
384 a stack frame is on the free list, only the following members have |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
385 a meaning: |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
386 ob_type == &Frametype |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
387 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
|
388 f_stacksize size of value stack |
| 40971 | 389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 |
|
45191
920a7633ae08
Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
399 Later, PyFrame_MAXFREELIST was added to bound the # of frames saved on |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
400 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
|
401 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
|
402 */ |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
403 |
| 5350 | 404 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
|
405 static int numfree = 0; /* number of frames currently in free_list */ |
|
45191
920a7633ae08
Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
406 /* max value for numfree */ |
|
920a7633ae08
Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
407 #define PyFrame_MAXFREELIST 200 |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
408 |
| 86 | 409 static void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
410 frame_dealloc(PyFrameObject *f) |
| 86 | 411 { |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
412 PyObject **p, **valuestack; |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
413 PyCodeObject *co; |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
414 |
| 40971 | 415 PyObject_GC_UnTrack(f); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
416 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
|
417 /* Kill all local variables */ |
| 40971 | 418 valuestack = f->f_valuestack; |
| 419 for (p = f->f_localsplus; p < valuestack; p++) | |
| 420 Py_CLEAR(*p); | |
|
5097
57b7a03a3252
Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents:
5045
diff
changeset
|
421 |
|
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
|
422 /* 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
|
423 if (f->f_stacktop != NULL) { |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
424 for (p = valuestack; p < f->f_stacktop; p++) |
|
18237
f02605b8fdc1
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
425 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
|
426 } |
|
37727
62c9038a578a
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
37724
diff
changeset
|
427 |
| 5350 | 428 Py_XDECREF(f->f_back); |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
429 Py_DECREF(f->f_builtins); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
430 Py_DECREF(f->f_globals); |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
431 Py_CLEAR(f->f_locals); |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
432 Py_CLEAR(f->f_trace); |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
433 Py_CLEAR(f->f_exc_type); |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
434 Py_CLEAR(f->f_exc_value); |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
435 Py_CLEAR(f->f_exc_traceback); |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
436 |
| 40971 | 437 co = f->f_code; |
| 438 if (co->co_zombieframe == NULL) | |
| 439 co->co_zombieframe = f; | |
|
45191
920a7633ae08
Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
440 else if (numfree < PyFrame_MAXFREELIST) { |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
441 ++numfree; |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
442 f->f_back = free_list; |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
443 free_list = f; |
| 40971 | 444 } |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
445 else |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
446 PyObject_GC_Del(f); |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
447 |
| 40971 | 448 Py_DECREF(co); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
449 Py_TRASHCAN_SAFE_END(f) |
| 86 | 450 } |
| 451 | |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
452 static int |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
453 frame_traverse(PyFrameObject *f, visitproc visit, void *arg) |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
454 { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
455 PyObject **fastlocals, **p; |
|
37728
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
456 int i, slots; |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
457 |
|
37728
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
458 Py_VISIT(f->f_back); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
459 Py_VISIT(f->f_code); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
460 Py_VISIT(f->f_builtins); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
461 Py_VISIT(f->f_globals); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
462 Py_VISIT(f->f_locals); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
463 Py_VISIT(f->f_trace); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
464 Py_VISIT(f->f_exc_type); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
465 Py_VISIT(f->f_exc_value); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
466 Py_VISIT(f->f_exc_traceback); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
467 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
468 /* locals */ |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
469 slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + PyTuple_GET_SIZE(f->f_code->co_freevars); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
470 fastlocals = f->f_localsplus; |
|
37728
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
471 for (i = slots; --i >= 0; ++fastlocals) |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
472 Py_VISIT(*fastlocals); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
473 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
474 /* stack */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
475 if (f->f_stacktop != NULL) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
476 for (p = f->f_valuestack; p < f->f_stacktop; p++) |
|
37728
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
477 Py_VISIT(*p); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
478 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
479 return 0; |
|
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 static void |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
483 frame_clear(PyFrameObject *f) |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
484 { |
|
37724
31929da0b05a
Fix SF#1470508: crash in generator cycle finalization. There were two
Phillip J. Eby <pje@telecommunity.com>
parents:
37086
diff
changeset
|
485 PyObject **fastlocals, **p, **oldtop; |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
486 int i, slots; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
487 |
|
37729
c6df5e795423
frame_clear(): Explain why it's important to make the frame
Tim Peters <tim.peters@gmail.com>
parents:
37728
diff
changeset
|
488 /* Before anything else, make sure that this frame is clearly marked |
| 40971 | 489 * as being defunct! Else, e.g., a generator reachable from this |
| 490 * frame may also point to this frame, believe itself to still be | |
| 491 * active, and try cleaning up this frame again. | |
| 492 */ | |
|
37724
31929da0b05a
Fix SF#1470508: crash in generator cycle finalization. There were two
Phillip J. Eby <pje@telecommunity.com>
parents:
37086
diff
changeset
|
493 oldtop = f->f_stacktop; |
| 40971 | 494 f->f_stacktop = NULL; |
|
37724
31929da0b05a
Fix SF#1470508: crash in generator cycle finalization. There were two
Phillip J. Eby <pje@telecommunity.com>
parents:
37086
diff
changeset
|
495 |
|
37729
c6df5e795423
frame_clear(): Explain why it's important to make the frame
Tim Peters <tim.peters@gmail.com>
parents:
37728
diff
changeset
|
496 Py_CLEAR(f->f_exc_type); |
|
c6df5e795423
frame_clear(): Explain why it's important to make the frame
Tim Peters <tim.peters@gmail.com>
parents:
37728
diff
changeset
|
497 Py_CLEAR(f->f_exc_value); |
|
c6df5e795423
frame_clear(): Explain why it's important to make the frame
Tim Peters <tim.peters@gmail.com>
parents:
37728
diff
changeset
|
498 Py_CLEAR(f->f_exc_traceback); |
|
c6df5e795423
frame_clear(): Explain why it's important to make the frame
Tim Peters <tim.peters@gmail.com>
parents:
37728
diff
changeset
|
499 Py_CLEAR(f->f_trace); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
500 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
501 /* locals */ |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
502 slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + PyTuple_GET_SIZE(f->f_code->co_freevars); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
503 fastlocals = f->f_localsplus; |
|
37729
c6df5e795423
frame_clear(): Explain why it's important to make the frame
Tim Peters <tim.peters@gmail.com>
parents:
37728
diff
changeset
|
504 for (i = slots; --i >= 0; ++fastlocals) |
|
37724
31929da0b05a
Fix SF#1470508: crash in generator cycle finalization. There were two
Phillip J. Eby <pje@telecommunity.com>
parents:
37086
diff
changeset
|
505 Py_CLEAR(*fastlocals); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
506 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
507 /* stack */ |
|
37724
31929da0b05a
Fix SF#1470508: crash in generator cycle finalization. There were two
Phillip J. Eby <pje@telecommunity.com>
parents:
37086
diff
changeset
|
508 if (oldtop != NULL) { |
|
37729
c6df5e795423
frame_clear(): Explain why it's important to make the frame
Tim Peters <tim.peters@gmail.com>
parents:
37728
diff
changeset
|
509 for (p = f->f_valuestack; p < oldtop; p++) |
|
37724
31929da0b05a
Fix SF#1470508: crash in generator cycle finalization. There were two
Phillip J. Eby <pje@telecommunity.com>
parents:
37086
diff
changeset
|
510 Py_CLEAR(*p); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
511 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
512 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
513 |
|
47922
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
514 static PyObject * |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
515 frame_sizeof(PyFrameObject *f) |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
516 { |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
517 Py_ssize_t res, extras, ncells, nfrees; |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
518 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
519 ncells = PyTuple_GET_SIZE(f->f_code->co_cellvars); |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
520 nfrees = PyTuple_GET_SIZE(f->f_code->co_freevars); |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
521 extras = f->f_code->co_stacksize + f->f_code->co_nlocals + |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
522 ncells + nfrees; |
|
49379
068d9b614e7b
Merged revisions 66739 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
48044
diff
changeset
|
523 /* subtract one as it is already included in PyFrameObject */ |
|
47922
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
524 res = sizeof(PyFrameObject) + (extras-1) * sizeof(PyObject *); |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
525 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
526 return PyInt_FromSsize_t(res); |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
527 } |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
528 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
529 PyDoc_STRVAR(sizeof__doc__, |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
530 "F.__sizeof__() -> size of F in memory, in bytes"); |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
531 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
532 static PyMethodDef frame_methods[] = { |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
533 {"__sizeof__", (PyCFunction)frame_sizeof, METH_NOARGS, |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
534 sizeof__doc__}, |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
535 {NULL, NULL} /* sentinel */ |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
536 }; |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
537 |
| 5350 | 538 PyTypeObject PyFrame_Type = { |
|
42333
6620a510e9a9
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents:
41486
diff
changeset
|
539 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 86 | 540 "frame", |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
541 sizeof(PyFrameObject), |
|
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
542 sizeof(PyObject *), |
| 40971 | 543 (destructor)frame_dealloc, /* tp_dealloc */ |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
544 0, /* tp_print */ |
| 40971 | 545 0, /* tp_getattr */ |
| 546 0, /* tp_setattr */ | |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
547 0, /* tp_compare */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
548 0, /* tp_repr */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
549 0, /* tp_as_number */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
550 0, /* tp_as_sequence */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
551 0, /* tp_as_mapping */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
552 0, /* tp_hash */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
553 0, /* tp_call */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
554 0, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
555 PyObject_GenericGetAttr, /* tp_getattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
556 PyObject_GenericSetAttr, /* tp_setattro */ |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
557 0, /* tp_as_buffer */ |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
558 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
| 40971 | 559 0, /* tp_doc */ |
| 560 (traverseproc)frame_traverse, /* tp_traverse */ | |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
561 (inquiry)frame_clear, /* tp_clear */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
562 0, /* tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
563 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
564 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
565 0, /* tp_iternext */ |
|
47922
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
566 frame_methods, /* tp_methods */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
567 frame_memberlist, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
568 frame_getsetlist, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
569 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
570 0, /* tp_dict */ |
| 86 | 571 }; |
| 572 | |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
573 static PyObject *builtin_object; |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
574 |
|
26923
dbfc3ef7d003
Since the *_Init() are private, prefix with _, suggested by Skip
Neal Norwitz <nnorwitz@gmail.com>
parents:
26889
diff
changeset
|
575 int _PyFrame_Init() |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
576 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
577 builtin_object = PyString_InternFromString("__builtins__"); |
|
52221
fb80b281e05a
Merged revisions 70463 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
578 if (builtin_object == NULL) |
|
fb80b281e05a
Merged revisions 70463 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
579 return 0; |
|
fb80b281e05a
Merged revisions 70463 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
580 return 1; |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
581 } |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
582 |
| 5350 | 583 PyFrameObject * |
|
37727
62c9038a578a
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
37724
diff
changeset
|
584 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
|
585 PyObject *locals) |
| 86 | 586 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
587 PyFrameObject *back = tstate->frame; |
| 5350 | 588 PyFrameObject *f; |
| 589 PyObject *builtins; | |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
590 Py_ssize_t i; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
591 |
|
24895
c8d9592c9e74
Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents:
24844
diff
changeset
|
592 #ifdef Py_DEBUG |
|
c8d9592c9e74
Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents:
24844
diff
changeset
|
593 if (code == NULL || globals == NULL || !PyDict_Check(globals) || |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
594 (locals != NULL && !PyMapping_Check(locals))) { |
| 5350 | 595 PyErr_BadInternalCall(); |
| 86 | 596 return NULL; |
| 597 } | |
|
24895
c8d9592c9e74
Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents:
24844
diff
changeset
|
598 #endif |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
599 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
|
600 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
|
601 if (builtins) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
602 if (PyModule_Check(builtins)) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
603 builtins = PyModule_GetDict(builtins); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
604 assert(!builtins || PyDict_Check(builtins)); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
605 } |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
606 else if (!PyDict_Check(builtins)) |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
607 builtins = NULL; |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
608 } |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
609 if (builtins == NULL) { |
| 40971 | 610 /* No builtins! Make up a minimal one |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
611 Give them 'None', at least. */ |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
612 builtins = PyDict_New(); |
|
37727
62c9038a578a
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
37724
diff
changeset
|
613 if (builtins == NULL || |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
614 PyDict_SetItemString( |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
615 builtins, "None", Py_None) < 0) |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
616 return NULL; |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
617 } |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
618 else |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
619 Py_INCREF(builtins); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
620 |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
621 } |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
622 else { |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
623 /* 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
|
624 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
|
625 builtins = back->f_builtins; |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
626 assert(builtins != NULL && PyDict_Check(builtins)); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
627 Py_INCREF(builtins); |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
628 } |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
629 if (code->co_zombieframe != NULL) { |
| 40971 | 630 f = code->co_zombieframe; |
| 631 code->co_zombieframe = NULL; | |
| 632 _Py_NewReference((PyObject *)f); | |
| 633 assert(f->f_code == code); | |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
634 } |
| 40971 | 635 else { |
| 636 Py_ssize_t extras, ncells, nfrees; | |
| 637 ncells = PyTuple_GET_SIZE(code->co_cellvars); | |
| 638 nfrees = PyTuple_GET_SIZE(code->co_freevars); | |
| 639 extras = code->co_stacksize + code->co_nlocals + ncells + | |
| 640 nfrees; | |
| 641 if (free_list == NULL) { | |
| 642 f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, | |
| 643 extras); | |
| 644 if (f == NULL) { | |
| 645 Py_DECREF(builtins); | |
| 646 return NULL; | |
| 647 } | |
| 648 } | |
| 649 else { | |
| 650 assert(numfree > 0); | |
| 651 --numfree; | |
| 652 f = free_list; | |
| 653 free_list = free_list->f_back; | |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42333
diff
changeset
|
654 if (Py_SIZE(f) < extras) { |
| 40971 | 655 f = PyObject_GC_Resize(PyFrameObject, f, extras); |
| 656 if (f == NULL) { | |
| 657 Py_DECREF(builtins); | |
| 658 return NULL; | |
| 659 } | |
| 660 } | |
| 661 _Py_NewReference((PyObject *)f); | |
| 662 } | |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
663 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
664 f->f_code = code; |
|
38254
bf5fb6e7527c
fix broken merge
Richard Jones <richard@commonground.com.au>
parents:
38253
diff
changeset
|
665 extras = code->co_nlocals + ncells + nfrees; |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
666 f->f_valuestack = f->f_localsplus + extras; |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
667 for (i=0; i<extras; i++) |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
668 f->f_localsplus[i] = NULL; |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
669 f->f_locals = NULL; |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
670 f->f_trace = NULL; |
| 40971 | 671 f->f_exc_type = f->f_exc_value = f->f_exc_traceback = NULL; |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
672 } |
|
39128
af4a3a0d47cc
Move the initialization of some pointers earlier. The problem is
Neal Norwitz <nnorwitz@gmail.com>
parents:
38766
diff
changeset
|
673 f->f_stacktop = f->f_valuestack; |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
674 f->f_builtins = builtins; |
| 5350 | 675 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
|
676 f->f_back = back; |
| 5350 | 677 Py_INCREF(code); |
| 678 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
|
679 f->f_globals = globals; |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
680 /* Most functions have CO_NEWLOCALS and CO_OPTIMIZED set. */ |
|
37727
62c9038a578a
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
37724
diff
changeset
|
681 if ((code->co_flags & (CO_NEWLOCALS | CO_OPTIMIZED)) == |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
682 (CO_NEWLOCALS | CO_OPTIMIZED)) |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
683 ; /* f_locals = NULL; will be set by PyFrame_FastToLocals() */ |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
684 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
|
685 locals = PyDict_New(); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
686 if (locals == NULL) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
687 Py_DECREF(f); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
688 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
|
689 } |
| 40971 | 690 f->f_locals = locals; |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
691 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
692 else { |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
693 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
|
694 locals = globals; |
| 5350 | 695 Py_INCREF(locals); |
| 40971 | 696 f->f_locals = locals; |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
697 } |
|
5921
800a5217e67e
Avoid function calls to access the current thread state and builtins
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
698 f->f_tstate = tstate; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
699 |
| 24844 | 700 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
|
701 f->f_lineno = code->co_firstlineno; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
702 f->f_iblock = 0; |
|
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
703 |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
704 _PyObject_GC_TRACK(f); |
| 86 | 705 return f; |
| 706 } | |
| 707 | |
| 708 /* Block management */ | |
| 709 | |
| 710 void | |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
711 PyFrame_BlockSetup(PyFrameObject *f, int type, int handler, int level) |
| 86 | 712 { |
| 5350 | 713 PyTryBlock *b; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
714 if (f->f_iblock >= CO_MAXBLOCKS) |
| 5350 | 715 Py_FatalError("XXX block stack overflow"); |
| 86 | 716 b = &f->f_blockstack[f->f_iblock++]; |
| 717 b->b_type = type; | |
| 718 b->b_level = level; | |
| 719 b->b_handler = handler; | |
| 720 } | |
| 721 | |
| 5350 | 722 PyTryBlock * |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
723 PyFrame_BlockPop(PyFrameObject *f) |
| 86 | 724 { |
| 5350 | 725 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
|
726 if (f->f_iblock <= 0) |
| 5350 | 727 Py_FatalError("XXX block stack underflow"); |
| 86 | 728 b = &f->f_blockstack[--f->f_iblock]; |
| 729 return b; | |
| 730 } | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
731 |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
732 /* Convert between "fast" version of locals and dictionary version. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
733 |
| 40971 | 734 map and values are input arguments. map is a tuple of strings. |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
735 values is an array of PyObject*. At index i, map[i] is the name of |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
736 the variable with value values[i]. The function copies the first |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
737 nmap variable from map/values into dict. If values[i] is NULL, |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
738 the variable is deleted from dict. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
739 |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
740 If deref is true, then the values being copied are cell variables |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
741 and the value is extracted from the cell variable before being put |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
742 in dict. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
743 |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
744 Exceptions raised while modifying the dict are silently ignored, |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
745 because there is no good way to report them. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
746 */ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
747 |
|
17518
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
17104
diff
changeset
|
748 static void |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
749 map_to_dict(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values, |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
750 int deref) |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
751 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
752 Py_ssize_t j; |
| 40971 | 753 assert(PyTuple_Check(map)); |
| 754 assert(PyDict_Check(dict)); | |
| 755 assert(PyTuple_Size(map) >= nmap); | |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
756 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
|
757 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
|
758 PyObject *value = values[j]; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
759 assert(PyString_Check(key)); |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
760 if (deref) { |
| 40971 | 761 assert(PyCell_Check(value)); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
762 value = PyCell_GET(value); |
| 40971 | 763 } |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
764 if (value == NULL) { |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
765 if (PyObject_DelItem(dict, key) != 0) |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
766 PyErr_Clear(); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
767 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
768 else { |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
769 if (PyObject_SetItem(dict, key, value) != 0) |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
770 PyErr_Clear(); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
771 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
772 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
773 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
774 |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
775 /* Copy values from the "locals" dict into the fast locals. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
776 |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
777 dict is an input argument containing string keys representing |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
778 variables names and arbitrary PyObject* as values. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
779 |
| 40971 | 780 map and values are input arguments. map is a tuple of strings. |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
781 values is an array of PyObject*. At index i, map[i] is the name of |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
782 the variable with value values[i]. The function copies the first |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
783 nmap variable from map/values into dict. If values[i] is NULL, |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
784 the variable is deleted from dict. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
785 |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
786 If deref is true, then the values being copied are cell variables |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
787 and the value is extracted from the cell variable before being put |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
788 in dict. If clear is true, then variables in map but not in dict |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
789 are set to NULL in map; if clear is false, variables missing in |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
790 dict are ignored. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
791 |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
792 Exceptions raised while modifying the dict are silently ignored, |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
793 because there is no good way to report them. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
794 */ |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
795 |
|
17519
f9dfd587c142
Make one more private symbol static.
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
796 static void |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
797 dict_to_map(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values, |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
798 int deref, int clear) |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
799 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
800 Py_ssize_t j; |
| 40971 | 801 assert(PyTuple_Check(map)); |
| 802 assert(PyDict_Check(dict)); | |
| 803 assert(PyTuple_Size(map) >= nmap); | |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
804 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
|
805 PyObject *key = PyTuple_GET_ITEM(map, j); |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
806 PyObject *value = PyObject_GetItem(dict, key); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
807 assert(PyString_Check(key)); |
| 40971 | 808 /* We only care about NULLs if clear is true. */ |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
809 if (value == NULL) { |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
810 PyErr_Clear(); |
| 40971 | 811 if (!clear) |
| 812 continue; | |
| 813 } | |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
814 if (deref) { |
| 40971 | 815 assert(PyCell_Check(values[j])); |
| 816 if (PyCell_GET(values[j]) != value) { | |
| 817 if (PyCell_Set(values[j], value) < 0) | |
| 818 PyErr_Clear(); | |
| 819 } | |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
820 } else if (values[j] != value) { |
| 40971 | 821 Py_XINCREF(value); |
| 822 Py_XDECREF(values[j]); | |
| 823 values[j] = value; | |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
824 } |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
825 Py_XDECREF(value); |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
826 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
827 } |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
828 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
829 void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
830 PyFrame_FastToLocals(PyFrameObject *f) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
831 { |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
832 /* Merge fast locals into f->f_locals */ |
| 5350 | 833 PyObject *locals, *map; |
| 834 PyObject **fast; | |
| 835 PyObject *error_type, *error_value, *error_traceback; | |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
836 PyCodeObject *co; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
837 Py_ssize_t j; |
| 40971 | 838 int ncells, nfreevars; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
839 if (f == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
840 return; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
841 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
|
842 if (locals == NULL) { |
| 5350 | 843 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
|
844 if (locals == NULL) { |
| 5350 | 845 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
|
846 return; |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
847 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
848 } |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
849 co = f->f_code; |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
850 map = co->co_varnames; |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
851 if (!PyTuple_Check(map)) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
852 return; |
| 5350 | 853 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
|
854 fast = f->f_localsplus; |
|
37086
3b7b295cca90
Use macro versions instead of function versions when we already know the type.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
855 j = PyTuple_GET_SIZE(map); |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
856 if (j > co->co_nlocals) |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
857 j = co->co_nlocals; |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
858 if (co->co_nlocals) |
| 30741 | 859 map_to_dict(map, j, locals, fast, 0); |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
860 ncells = PyTuple_GET_SIZE(co->co_cellvars); |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
861 nfreevars = PyTuple_GET_SIZE(co->co_freevars); |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
862 if (ncells || nfreevars) { |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
863 map_to_dict(co->co_cellvars, ncells, |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
864 locals, fast + co->co_nlocals, 1); |
| 40971 | 865 /* If the namespace is unoptimized, then one of the |
| 866 following cases applies: | |
| 867 1. It does not contain free variables, because it | |
| 868 uses import * or is a top-level namespace. | |
| 869 2. It is a class namespace. | |
| 870 We don't want to accidentally copy free variables | |
| 871 into the locals dict used by the class. | |
| 872 */ | |
| 873 if (co->co_flags & CO_OPTIMIZED) { | |
| 874 map_to_dict(co->co_freevars, nfreevars, | |
| 875 locals, fast + co->co_nlocals + ncells, 1); | |
| 876 } | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
877 } |
| 5350 | 878 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
|
879 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
880 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
881 void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
882 PyFrame_LocalsToFast(PyFrameObject *f, int clear) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
883 { |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
884 /* Merge f->f_locals into fast locals */ |
| 5350 | 885 PyObject *locals, *map; |
| 886 PyObject **fast; | |
| 887 PyObject *error_type, *error_value, *error_traceback; | |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
888 PyCodeObject *co; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
889 Py_ssize_t j; |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
890 int ncells, nfreevars; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
891 if (f == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
892 return; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
893 locals = f->f_locals; |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
894 co = f->f_code; |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
895 map = co->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
|
896 if (locals == NULL) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
897 return; |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
898 if (!PyTuple_Check(map)) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
899 return; |
| 5350 | 900 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
|
901 fast = f->f_localsplus; |
|
37086
3b7b295cca90
Use macro versions instead of function versions when we already know the type.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
902 j = PyTuple_GET_SIZE(map); |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
903 if (j > co->co_nlocals) |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
904 j = co->co_nlocals; |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
905 if (co->co_nlocals) |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
906 dict_to_map(co->co_varnames, j, locals, fast, 0, clear); |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
907 ncells = PyTuple_GET_SIZE(co->co_cellvars); |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
908 nfreevars = PyTuple_GET_SIZE(co->co_freevars); |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
909 if (ncells || nfreevars) { |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
910 dict_to_map(co->co_cellvars, ncells, |
|
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
911 locals, fast + co->co_nlocals, 1, clear); |
|
48044
b836bf25f176
Issue2378: pdb would delete free variables when stepping into a class statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47922
diff
changeset
|
912 /* Same test as in PyFrame_FastToLocals() above. */ |
|
b836bf25f176
Issue2378: pdb would delete free variables when stepping into a class statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47922
diff
changeset
|
913 if (co->co_flags & CO_OPTIMIZED) { |
|
b836bf25f176
Issue2378: pdb would delete free variables when stepping into a class statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47922
diff
changeset
|
914 dict_to_map(co->co_freevars, nfreevars, |
|
b836bf25f176
Issue2378: pdb would delete free variables when stepping into a class statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47922
diff
changeset
|
915 locals, fast + co->co_nlocals + ncells, 1, |
|
b836bf25f176
Issue2378: pdb would delete free variables when stepping into a class statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47922
diff
changeset
|
916 clear); |
|
b836bf25f176
Issue2378: pdb would delete free variables when stepping into a class statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47922
diff
changeset
|
917 } |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
918 } |
| 5350 | 919 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
|
920 } |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
921 |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
922 /* Clear out the free list */ |
|
45341
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
923 int |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
924 PyFrame_ClearFreeList(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
|
925 { |
|
45341
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
926 int freelist_size = numfree; |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
927 |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
928 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
|
929 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
|
930 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
|
931 PyObject_GC_Del(f); |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
932 --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
|
933 } |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
934 assert(numfree == 0); |
|
45341
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
935 return freelist_size; |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
936 } |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
937 |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
938 void |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
939 PyFrame_Fini(void) |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
940 { |
|
65ae68c7aca3
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents:
45191
diff
changeset
|
941 (void)PyFrame_ClearFreeList(); |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
942 Py_XDECREF(builtin_object); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
943 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
|
944 } |
