Mercurial > cpython-lru_cache-weakref
annotate Objects/frameobject.c @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 8c8504715b8a |
| children | fd25030223b0 |
| 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}, |
| 86 | 23 {NULL} /* Sentinel */ |
| 24 }; | |
| 25 | |
|
50259
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
26 #define WARN_GET_SET(NAME) \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
27 static PyObject * frame_get_ ## NAME(PyFrameObject *f) { \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
28 if (PyErr_WarnPy3k(#NAME " has been removed in 3.x", 2) < 0) \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
29 return NULL; \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
30 if (f->NAME) { \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
31 Py_INCREF(f->NAME); \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
32 return f->NAME; \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
33 } \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
34 Py_RETURN_NONE; \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
35 } \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
36 static int frame_set_ ## NAME(PyFrameObject *f, PyObject *new) { \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
37 if (PyErr_WarnPy3k(#NAME " has been removed in 3.x", 2) < 0) \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
38 return -1; \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
39 if (f->NAME) { \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
40 Py_CLEAR(f->NAME); \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
41 } \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
42 if (new == Py_None) \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
43 new = NULL; \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
44 Py_XINCREF(new); \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
45 f->NAME = new; \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
46 return 0; \ |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
47 } |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
48 |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
49 |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
50 WARN_GET_SET(f_exc_traceback) |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
51 WARN_GET_SET(f_exc_type) |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
52 WARN_GET_SET(f_exc_value) |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
53 |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
54 |
| 5350 | 55 static PyObject * |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
56 frame_getlocals(PyFrameObject *f, void *closure) |
| 86 | 57 { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
58 PyFrame_FastToLocals(f); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
59 Py_INCREF(f->f_locals); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
60 return f->f_locals; |
| 86 | 61 } |
| 62 | |
|
53931
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
63 int |
|
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
64 PyFrame_GetLineNumber(PyFrameObject *f) |
|
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
65 { |
|
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
66 if (f->f_trace) |
|
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
67 return f->f_lineno; |
|
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
68 else |
|
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
69 return PyCode_Addr2Line(f->f_code, f->f_lasti); |
|
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
70 } |
|
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
71 |
| 24844 | 72 static PyObject * |
| 73 frame_getlineno(PyFrameObject *f, void *closure) | |
| 74 { | |
|
53931
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
75 return PyInt_FromLong(PyFrame_GetLineNumber(f)); |
| 24844 | 76 } |
| 77 | |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
78 /* Setter for f_lineno - you can set f_lineno from within a trace function in |
| 40971 | 79 * 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
|
80 * 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
|
81 * 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
|
82 * 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
|
83 * that limit jumping: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
84 * |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
85 * 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
|
86 * 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
|
87 * 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
|
88 * 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
|
89 * 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
|
90 * 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
|
91 * iterator needs to be on the stack. |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
92 */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
93 static int |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
94 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
|
95 { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 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
|
100 Py_ssize_t code_len = 0; /* ...and its length */ |
|
54490
c37ae562ef82
#4547: When debugging a very large function, it was not always
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54218
diff
changeset
|
101 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
|
102 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
|
103 int offset = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
104 int line = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
105 int addr = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
106 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
|
107 int max_addr = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
108 int delta_iblock = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
109 int min_delta_iblock = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
110 int min_iblock = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
111 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
|
112 int new_lasti_setup_addr = 0; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
113 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
|
114 int in_finally[CO_MAXBLOCKS]; /* (ditto) */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
115 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
|
116 unsigned char setup_op = 0; /* (ditto) */ |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
117 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
118 /* f_lineno must be an integer. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
119 if (!PyInt_Check(p_new_lineno)) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
120 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
121 "lineno must be an integer"); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
122 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
123 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
124 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
125 /* 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
|
126 * _getframe or similar hackery. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
127 if (!f->f_trace) |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
128 { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
129 PyErr_Format(PyExc_ValueError, |
|
54199
d8350d044cf2
While I was modifying test_trace, it threw an exception when I accidentally
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53931
diff
changeset
|
130 "f_lineno can only be set by a" |
|
d8350d044cf2
While I was modifying test_trace, it threw an exception when I accidentally
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53931
diff
changeset
|
131 " line trace function"); |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
132 return -1; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
135 /* 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
|
136 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
|
137 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
|
138 PyErr_Format(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
139 "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
|
140 new_lineno); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
141 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
142 } |
|
54218
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
143 else if (new_lineno == f->f_code->co_firstlineno) { |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
144 new_lasti = 0; |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
145 new_lineno = f->f_code->co_firstlineno; |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
146 } |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
147 else { |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
148 /* Find the bytecode offset for the start of the given |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
149 * line, or the first code-owning line after it. */ |
|
54505
8c8504715b8a
Fix compilation error with gcc 4.3.2
Antoine Pitrou <solipsis@pitrou.net>
parents:
54490
diff
changeset
|
150 char *tmp; |
|
54218
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
151 PyString_AsStringAndSize(f->f_code->co_lnotab, |
|
54505
8c8504715b8a
Fix compilation error with gcc 4.3.2
Antoine Pitrou <solipsis@pitrou.net>
parents:
54490
diff
changeset
|
152 &tmp, &lnotab_len); |
|
8c8504715b8a
Fix compilation error with gcc 4.3.2
Antoine Pitrou <solipsis@pitrou.net>
parents:
54490
diff
changeset
|
153 lnotab = (unsigned char *) tmp; |
|
54218
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
154 addr = 0; |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
155 line = f->f_code->co_firstlineno; |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
156 new_lasti = -1; |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
157 for (offset = 0; offset < lnotab_len; offset += 2) { |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
158 addr += lnotab[offset]; |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
159 line += lnotab[offset+1]; |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
160 if (line >= new_lineno) { |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
161 new_lasti = addr; |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
162 new_lineno = line; |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
163 break; |
|
4ceeefb8555e
Fix issue #1689458 by teaching frame_setlineno how to jump to the first line of
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
54199
diff
changeset
|
164 } |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
165 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
166 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
167 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
168 /* 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
|
169 if (new_lasti == -1) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
170 PyErr_Format(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
171 "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
|
172 new_lineno); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
173 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
174 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
175 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
176 /* 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
|
177 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
|
178 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
|
179 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
|
180 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
181 /* 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
|
182 * 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
|
183 * 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
|
184 * 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
|
185 * 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
|
186 * 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
|
187 * '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
|
188 * 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
|
189 * 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
|
190 * restriction (but with a different error message). */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
191 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
|
192 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
193 "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
|
194 return -1; |
|
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 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
197 /* 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
|
198 * block leaves something on the stack for the END_FINALLY to clean |
| 40971 | 199 * 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
|
200 * 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
|
201 * 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
|
202 * 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
|
203 * 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
|
204 * 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
|
205 * 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
|
206 f_lasti_setup_addr = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
207 new_lasti_setup_addr = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
208 memset(blockstack, '\0', sizeof(blockstack)); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
209 memset(in_finally, '\0', sizeof(in_finally)); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
210 blockstack_top = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
211 for (addr = 0; addr < code_len; addr++) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
212 unsigned char op = code[addr]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
213 switch (op) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
214 case SETUP_LOOP: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
215 case SETUP_EXCEPT: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
216 case SETUP_FINALLY: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
217 blockstack[blockstack_top++] = addr; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
218 in_finally[blockstack_top-1] = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
219 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
220 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
221 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
|
222 assert(blockstack_top > 0); |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
223 setup_op = code[blockstack[blockstack_top-1]]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
224 if (setup_op == SETUP_FINALLY) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
225 in_finally[blockstack_top-1] = 1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
226 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
227 else { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
228 blockstack_top--; |
|
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 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
231 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
232 case END_FINALLY: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
233 /* 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
|
234 * 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
|
235 * '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
|
236 * 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 } |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
242 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
243 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
244 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
245 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
246 /* 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
|
247 * 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
|
248 * of the SETUP_FINALLY. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
249 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
|
250 int i = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
251 int setup_addr = -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
252 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
|
253 if (in_finally[i]) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
254 setup_addr = blockstack[i]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
255 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
256 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
257 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
258 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
259 if (setup_addr != -1) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
260 if (addr == new_lasti) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
261 new_lasti_setup_addr = setup_addr; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
262 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
263 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
264 if (addr == f->f_lasti) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
265 f_lasti_setup_addr = setup_addr; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
266 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
267 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
268 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
269 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
270 if (op >= HAVE_ARGUMENT) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
271 addr += 2; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
272 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
273 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
274 |
|
26717
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
275 /* 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
|
276 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
|
277 |
|
f55f5e1e30bc
Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents:
26709
diff
changeset
|
278 /* 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
|
279 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
|
280 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
281 "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
|
282 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
283 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
284 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
285 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
286 /* 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
|
287 * 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
|
288 * 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
|
289 * 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
|
290 * 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
|
291 * 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
|
292 * 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
|
293 * 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
|
294 delta_iblock = 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
295 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
|
296 unsigned char op = code[addr]; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
297 switch (op) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
298 case SETUP_LOOP: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
299 case SETUP_EXCEPT: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
300 case SETUP_FINALLY: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
301 delta_iblock++; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
302 break; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
303 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
304 case POP_BLOCK: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
305 delta_iblock--; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
306 break; |
|
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 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
|
310 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
311 if (op >= HAVE_ARGUMENT) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
312 addr += 2; |
|
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 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
315 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
316 /* 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
|
317 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
|
318 if (new_lasti > f->f_lasti) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
319 /* Forwards jump. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
320 new_iblock = f->f_iblock + delta_iblock; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
321 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
322 else { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
323 /* Backwards jump. */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
324 new_iblock = f->f_iblock - delta_iblock; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
325 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
326 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
327 /* Are we jumping into a block? */ |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
328 if (new_iblock > min_iblock) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
329 PyErr_SetString(PyExc_ValueError, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
330 "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
|
331 return -1; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
332 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
333 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
334 /* 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
|
335 while (f->f_iblock > new_iblock) { |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
336 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
|
337 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
|
338 PyObject *v = (*--f->f_stacktop); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
339 Py_DECREF(v); |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
340 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
341 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
342 |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
343 /* 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
|
344 f->f_lineno = new_lineno; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
345 f->f_lasti = new_lasti; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
346 return 0; |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
347 } |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
348 |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
349 static PyObject * |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
350 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
|
351 { |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
352 PyObject* trace = f->f_trace; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
353 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
354 if (trace == NULL) |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
355 trace = Py_None; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
356 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
357 Py_INCREF(trace); |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
358 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
359 return trace; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
360 } |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
361 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
362 static int |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
363 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
|
364 { |
|
53931
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
365 PyObject* old_value; |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
366 |
|
53931
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
367 /* We rely on f_lineno being accurate when f_trace is set. */ |
|
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
368 f->f_lineno = PyFrame_GetLineNumber(f); |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
369 |
|
53931
9ef683d41c9b
Issue 5954, PyFrame_GetLineNumber:
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
53239
diff
changeset
|
370 old_value = f->f_trace; |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
371 Py_XINCREF(v); |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
372 f->f_trace = v; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
373 Py_XDECREF(old_value); |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
374 |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
375 return 0; |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
376 } |
|
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
377 |
|
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
|
378 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
|
379 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
|
380 { |
|
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
|
381 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
|
382 } |
|
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
|
383 |
|
20015
ca7af2a5d915
Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents:
20012
diff
changeset
|
384 static PyGetSetDef frame_getsetlist[] = { |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
385 {"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
|
386 {"f_lineno", (getter)frame_getlineno, |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
25207
diff
changeset
|
387 (setter)frame_setlineno, NULL}, |
|
25207
1e46da1e6522
A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents:
25074
diff
changeset
|
388 {"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
|
389 {"f_restricted",(getter)frame_getrestricted,NULL, NULL}, |
|
50259
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
390 {"f_exc_traceback", (getter)frame_get_f_exc_traceback, |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
391 (setter)frame_set_f_exc_traceback, NULL}, |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
392 {"f_exc_type", (getter)frame_get_f_exc_type, |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
393 (setter)frame_set_f_exc_type, NULL}, |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
394 {"f_exc_value", (getter)frame_get_f_exc_value, |
|
d79fdd8420f3
add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents:
49379
diff
changeset
|
395 (setter)frame_set_f_exc_value, NULL}, |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
396 {0} |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
397 }; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
398 |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
399 /* 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
|
400 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
|
401 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 correct size. It also saves some field initialisation. |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
408 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
409 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
|
410 the following fields are still valid: |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
411 |
|
38254
bf5fb6e7527c
fix broken merge
Richard Jones <richard@commonground.com.au>
parents:
38253
diff
changeset
|
412 * 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
|
413 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
414 * f_locals, f_trace, |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
415 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
|
416 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
417 * f_localsplus does not require re-allocation and |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
418 the local variables in f_localsplus are NULL. |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
419 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
420 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
|
421 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
|
422 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
|
423 a meaning: |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
424 ob_type == &Frametype |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
425 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
|
426 f_stacksize size of value stack |
| 40971 | 427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 |
|
45191
920a7633ae08
Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
437 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
|
438 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
|
439 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
|
440 */ |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
441 |
| 5350 | 442 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
|
443 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
|
444 /* 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
|
445 #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
|
446 |
| 86 | 447 static void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
448 frame_dealloc(PyFrameObject *f) |
| 86 | 449 { |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
450 PyObject **p, **valuestack; |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
451 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
|
452 |
| 40971 | 453 PyObject_GC_UnTrack(f); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
454 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
|
455 /* Kill all local variables */ |
| 40971 | 456 valuestack = f->f_valuestack; |
| 457 for (p = f->f_localsplus; p < valuestack; p++) | |
| 458 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
|
459 |
|
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
|
460 /* 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
|
461 if (f->f_stacktop != NULL) { |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
462 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
|
463 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
|
464 } |
|
37727
62c9038a578a
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
37724
diff
changeset
|
465 |
| 5350 | 466 Py_XDECREF(f->f_back); |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
467 Py_DECREF(f->f_builtins); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
468 Py_DECREF(f->f_globals); |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
469 Py_CLEAR(f->f_locals); |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
470 Py_CLEAR(f->f_trace); |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
471 Py_CLEAR(f->f_exc_type); |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
472 Py_CLEAR(f->f_exc_value); |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
473 Py_CLEAR(f->f_exc_traceback); |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
474 |
| 40971 | 475 co = f->f_code; |
| 476 if (co->co_zombieframe == NULL) | |
| 477 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
|
478 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
|
479 ++numfree; |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
480 f->f_back = free_list; |
|
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
481 free_list = f; |
| 40971 | 482 } |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
483 else |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
484 PyObject_GC_Del(f); |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
485 |
| 40971 | 486 Py_DECREF(co); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
487 Py_TRASHCAN_SAFE_END(f) |
| 86 | 488 } |
| 489 | |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
490 static int |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
491 frame_traverse(PyFrameObject *f, visitproc visit, void *arg) |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
492 { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
493 PyObject **fastlocals, **p; |
|
37728
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
494 int i, slots; |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
495 |
|
37728
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
496 Py_VISIT(f->f_back); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
497 Py_VISIT(f->f_code); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
498 Py_VISIT(f->f_builtins); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
499 Py_VISIT(f->f_globals); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
500 Py_VISIT(f->f_locals); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
501 Py_VISIT(f->f_trace); |
|
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
502 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
|
503 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
|
504 Py_VISIT(f->f_exc_traceback); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
505 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
506 /* 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
|
507 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
|
508 fastlocals = f->f_localsplus; |
|
37728
588f97b24bf9
frame_traverse(): Use the standard Py_VISIT macro.
Tim Peters <tim.peters@gmail.com>
parents:
37727
diff
changeset
|
509 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
|
510 Py_VISIT(*fastlocals); |
|
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 /* stack */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
513 if (f->f_stacktop != NULL) { |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
514 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
|
515 Py_VISIT(*p); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
516 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
517 return 0; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
518 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
519 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
520 static void |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
521 frame_clear(PyFrameObject *f) |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
522 { |
|
37724
31929da0b05a
Fix SF#1470508: crash in generator cycle finalization. There were two
Phillip J. Eby <pje@telecommunity.com>
parents:
37086
diff
changeset
|
523 PyObject **fastlocals, **p, **oldtop; |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
524 int i, slots; |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
525 |
|
37729
c6df5e795423
frame_clear(): Explain why it's important to make the frame
Tim Peters <tim.peters@gmail.com>
parents:
37728
diff
changeset
|
526 /* Before anything else, make sure that this frame is clearly marked |
| 40971 | 527 * as being defunct! Else, e.g., a generator reachable from this |
| 528 * frame may also point to this frame, believe itself to still be | |
| 529 * active, and try cleaning up this frame again. | |
| 530 */ | |
|
37724
31929da0b05a
Fix SF#1470508: crash in generator cycle finalization. There were two
Phillip J. Eby <pje@telecommunity.com>
parents:
37086
diff
changeset
|
531 oldtop = f->f_stacktop; |
| 40971 | 532 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
|
533 |
|
37729
c6df5e795423
frame_clear(): Explain why it's important to make the frame
Tim Peters <tim.peters@gmail.com>
parents:
37728
diff
changeset
|
534 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
|
535 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
|
536 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
|
537 Py_CLEAR(f->f_trace); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
538 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
539 /* 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
|
540 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
|
541 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
|
542 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
|
543 Py_CLEAR(*fastlocals); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
544 |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
545 /* stack */ |
|
37724
31929da0b05a
Fix SF#1470508: crash in generator cycle finalization. There were two
Phillip J. Eby <pje@telecommunity.com>
parents:
37086
diff
changeset
|
546 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
|
547 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
|
548 Py_CLEAR(*p); |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
549 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
550 } |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
551 |
|
47922
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
552 static PyObject * |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
553 frame_sizeof(PyFrameObject *f) |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
554 { |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
555 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
|
556 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
557 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
|
558 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
|
559 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
|
560 ncells + nfrees; |
|
49379
068d9b614e7b
Merged revisions 66739 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
48044
diff
changeset
|
561 /* 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
|
562 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
|
563 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
564 return PyInt_FromSsize_t(res); |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
565 } |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
566 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
567 PyDoc_STRVAR(sizeof__doc__, |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
568 "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
|
569 |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
570 static PyMethodDef frame_methods[] = { |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
571 {"__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
|
572 sizeof__doc__}, |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
573 {NULL, NULL} /* sentinel */ |
|
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
574 }; |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
575 |
| 5350 | 576 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
|
577 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 86 | 578 "frame", |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
579 sizeof(PyFrameObject), |
|
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
580 sizeof(PyObject *), |
| 40971 | 581 (destructor)frame_dealloc, /* tp_dealloc */ |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
582 0, /* tp_print */ |
| 40971 | 583 0, /* tp_getattr */ |
| 584 0, /* tp_setattr */ | |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
585 0, /* tp_compare */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
586 0, /* tp_repr */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
587 0, /* tp_as_number */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
588 0, /* tp_as_sequence */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
589 0, /* tp_as_mapping */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
590 0, /* tp_hash */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
591 0, /* tp_call */ |
|
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
592 0, /* tp_str */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
593 PyObject_GenericGetAttr, /* tp_getattro */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
594 PyObject_GenericSetAttr, /* tp_setattro */ |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
595 0, /* tp_as_buffer */ |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
596 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
| 40971 | 597 0, /* tp_doc */ |
| 598 (traverseproc)frame_traverse, /* tp_traverse */ | |
|
18510
f4ea21a0f954
GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18237
diff
changeset
|
599 (inquiry)frame_clear, /* tp_clear */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
600 0, /* tp_richcompare */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
601 0, /* tp_weaklistoffset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
602 0, /* tp_iter */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
603 0, /* tp_iternext */ |
|
47922
7cfc28ac0715
Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
604 frame_methods, /* tp_methods */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
605 frame_memberlist, /* tp_members */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
606 frame_getsetlist, /* tp_getset */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
607 0, /* tp_base */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18510
diff
changeset
|
608 0, /* tp_dict */ |
| 86 | 609 }; |
| 610 | |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
611 static PyObject *builtin_object; |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
612 |
|
26923
dbfc3ef7d003
Since the *_Init() are private, prefix with _, suggested by Skip
Neal Norwitz <nnorwitz@gmail.com>
parents:
26889
diff
changeset
|
613 int _PyFrame_Init() |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
614 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
615 builtin_object = PyString_InternFromString("__builtins__"); |
|
52219
d2b7887f8c9a
fix strange errors when setting attributes on tracebacks #4034
Benjamin Peterson <benjamin@python.org>
parents:
50259
diff
changeset
|
616 if (builtin_object == NULL) |
|
d2b7887f8c9a
fix strange errors when setting attributes on tracebacks #4034
Benjamin Peterson <benjamin@python.org>
parents:
50259
diff
changeset
|
617 return 0; |
|
d2b7887f8c9a
fix strange errors when setting attributes on tracebacks #4034
Benjamin Peterson <benjamin@python.org>
parents:
50259
diff
changeset
|
618 return 1; |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
619 } |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
620 |
| 5350 | 621 PyFrameObject * |
|
37727
62c9038a578a
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
37724
diff
changeset
|
622 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
|
623 PyObject *locals) |
| 86 | 624 { |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5350
diff
changeset
|
625 PyFrameObject *back = tstate->frame; |
| 5350 | 626 PyFrameObject *f; |
| 627 PyObject *builtins; | |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
628 Py_ssize_t i; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
629 |
|
24895
c8d9592c9e74
Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents:
24844
diff
changeset
|
630 #ifdef Py_DEBUG |
|
c8d9592c9e74
Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents:
24844
diff
changeset
|
631 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
|
632 (locals != NULL && !PyMapping_Check(locals))) { |
| 5350 | 633 PyErr_BadInternalCall(); |
| 86 | 634 return NULL; |
| 635 } | |
|
24895
c8d9592c9e74
Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents:
24844
diff
changeset
|
636 #endif |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
637 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
|
638 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
|
639 if (builtins) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
640 if (PyModule_Check(builtins)) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
641 builtins = PyModule_GetDict(builtins); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
642 assert(!builtins || PyDict_Check(builtins)); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
643 } |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
644 else if (!PyDict_Check(builtins)) |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
645 builtins = NULL; |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
646 } |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
647 if (builtins == NULL) { |
| 40971 | 648 /* 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
|
649 Give them 'None', at least. */ |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
650 builtins = PyDict_New(); |
|
37727
62c9038a578a
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
37724
diff
changeset
|
651 if (builtins == NULL || |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
652 PyDict_SetItemString( |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
653 builtins, "None", Py_None) < 0) |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
654 return NULL; |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
655 } |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
656 else |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
657 Py_INCREF(builtins); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
658 |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
659 } |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
660 else { |
|
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
661 /* 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
|
662 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
|
663 builtins = back->f_builtins; |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
664 assert(builtins != NULL && PyDict_Check(builtins)); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
665 Py_INCREF(builtins); |
|
7399
b8d78650f8df
Vladimir Marangozov' performance hack: copy f_builtins from ancestor
Guido van Rossum <guido@python.org>
parents:
6543
diff
changeset
|
666 } |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
667 if (code->co_zombieframe != NULL) { |
| 40971 | 668 f = code->co_zombieframe; |
| 669 code->co_zombieframe = NULL; | |
| 670 _Py_NewReference((PyObject *)f); | |
| 671 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
|
672 } |
| 40971 | 673 else { |
| 674 Py_ssize_t extras, ncells, nfrees; | |
| 675 ncells = PyTuple_GET_SIZE(code->co_cellvars); | |
| 676 nfrees = PyTuple_GET_SIZE(code->co_freevars); | |
| 677 extras = code->co_stacksize + code->co_nlocals + ncells + | |
| 678 nfrees; | |
| 679 if (free_list == NULL) { | |
| 680 f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, | |
| 681 extras); | |
| 682 if (f == NULL) { | |
| 683 Py_DECREF(builtins); | |
| 684 return NULL; | |
| 685 } | |
| 686 } | |
| 687 else { | |
| 688 assert(numfree > 0); | |
| 689 --numfree; | |
| 690 f = free_list; | |
| 691 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
|
692 if (Py_SIZE(f) < extras) { |
| 40971 | 693 f = PyObject_GC_Resize(PyFrameObject, f, extras); |
| 694 if (f == NULL) { | |
| 695 Py_DECREF(builtins); | |
| 696 return NULL; | |
| 697 } | |
| 698 } | |
| 699 _Py_NewReference((PyObject *)f); | |
| 700 } | |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
701 |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
702 f->f_code = code; |
|
38254
bf5fb6e7527c
fix broken merge
Richard Jones <richard@commonground.com.au>
parents:
38253
diff
changeset
|
703 extras = code->co_nlocals + ncells + nfrees; |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
704 f->f_valuestack = f->f_localsplus + extras; |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
705 for (i=0; i<extras; i++) |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
706 f->f_localsplus[i] = NULL; |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
707 f->f_locals = NULL; |
|
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
708 f->f_trace = NULL; |
| 40971 | 709 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
|
710 } |
|
39128
af4a3a0d47cc
Move the initialization of some pointers earlier. The problem is
Neal Norwitz <nnorwitz@gmail.com>
parents:
38766
diff
changeset
|
711 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
|
712 f->f_builtins = builtins; |
| 5350 | 713 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
|
714 f->f_back = back; |
| 5350 | 715 Py_INCREF(code); |
| 716 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
|
717 f->f_globals = globals; |
|
27706
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
718 /* Most functions have CO_NEWLOCALS and CO_OPTIMIZED set. */ |
|
37727
62c9038a578a
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
37724
diff
changeset
|
719 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
|
720 (CO_NEWLOCALS | CO_OPTIMIZED)) |
|
38244
a637c78bf119
Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents:
37729
diff
changeset
|
721 ; /* 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
|
722 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
|
723 locals = PyDict_New(); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
724 if (locals == NULL) { |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
725 Py_DECREF(f); |
|
537bfce2b730
Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26923
diff
changeset
|
726 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
|
727 } |
| 40971 | 728 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
|
729 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
730 else { |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
731 if (locals == NULL) |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
732 locals = globals; |
| 5350 | 733 Py_INCREF(locals); |
| 40971 | 734 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
|
735 } |
|
5921
800a5217e67e
Avoid function calls to access the current thread state and builtins
Guido van Rossum <guido@python.org>
parents:
5405
diff
changeset
|
736 f->f_tstate = tstate; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
737 |
| 24844 | 738 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
|
739 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
|
740 f->f_iblock = 0; |
|
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
741 |
|
19579
43ddc46c5a99
Make frames a PyVarObject. Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18933
diff
changeset
|
742 _PyObject_GC_TRACK(f); |
| 86 | 743 return f; |
| 744 } | |
| 745 | |
| 746 /* Block management */ | |
| 747 | |
| 748 void | |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
749 PyFrame_BlockSetup(PyFrameObject *f, int type, int handler, int level) |
| 86 | 750 { |
| 5350 | 751 PyTryBlock *b; |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
752 if (f->f_iblock >= CO_MAXBLOCKS) |
| 5350 | 753 Py_FatalError("XXX block stack overflow"); |
| 86 | 754 b = &f->f_blockstack[f->f_iblock++]; |
| 755 b->b_type = type; | |
| 756 b->b_level = level; | |
| 757 b->b_handler = handler; | |
| 758 } | |
| 759 | |
| 5350 | 760 PyTryBlock * |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
761 PyFrame_BlockPop(PyFrameObject *f) |
| 86 | 762 { |
| 5350 | 763 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
|
764 if (f->f_iblock <= 0) |
| 5350 | 765 Py_FatalError("XXX block stack underflow"); |
| 86 | 766 b = &f->f_blockstack[--f->f_iblock]; |
| 767 return b; | |
| 768 } | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
769 |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
770 /* 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
|
771 |
| 40971 | 772 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
|
773 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
|
774 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
|
775 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
|
776 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
|
777 |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
778 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
|
779 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
|
780 in dict. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
781 |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
782 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
|
783 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
|
784 */ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
785 |
|
17518
f939ce52a734
Make some private symbols static.
Guido van Rossum <guido@python.org>
parents:
17104
diff
changeset
|
786 static void |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
787 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
|
788 int deref) |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
789 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
790 Py_ssize_t j; |
| 40971 | 791 assert(PyTuple_Check(map)); |
| 792 assert(PyDict_Check(dict)); | |
| 793 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
|
794 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
|
795 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
|
796 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
|
797 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
|
798 if (deref) { |
| 40971 | 799 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
|
800 value = PyCell_GET(value); |
| 40971 | 801 } |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
802 if (value == NULL) { |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
803 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
|
804 PyErr_Clear(); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
805 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
806 else { |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
807 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
|
808 PyErr_Clear(); |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
809 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
810 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
811 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
812 |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
813 /* 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
|
814 |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
815 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
|
816 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
|
817 |
| 40971 | 818 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
|
819 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
|
820 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
|
821 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
|
822 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
|
823 |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
824 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
|
825 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
|
826 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
|
827 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
|
828 dict are ignored. |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
829 |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
830 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
|
831 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
|
832 */ |
|
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
833 |
|
17519
f9dfd587c142
Make one more private symbol static.
Guido van Rossum <guido@python.org>
parents:
17518
diff
changeset
|
834 static void |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
835 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
|
836 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
|
837 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
838 Py_ssize_t j; |
| 40971 | 839 assert(PyTuple_Check(map)); |
| 840 assert(PyDict_Check(dict)); | |
| 841 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
|
842 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
|
843 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
|
844 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
|
845 assert(PyString_Check(key)); |
| 40971 | 846 /* 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
|
847 if (value == NULL) { |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
848 PyErr_Clear(); |
| 40971 | 849 if (!clear) |
| 850 continue; | |
| 851 } | |
|
17104
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
852 if (deref) { |
| 40971 | 853 assert(PyCell_Check(values[j])); |
| 854 if (PyCell_GET(values[j]) != value) { | |
| 855 if (PyCell_Set(values[j], value) < 0) | |
| 856 PyErr_Clear(); | |
| 857 } | |
|
40938
047ee23c0f87
Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39128
diff
changeset
|
858 } else if (values[j] != value) { |
| 40971 | 859 Py_XINCREF(value); |
| 860 Py_XDECREF(values[j]); | |
| 861 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
|
862 } |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
863 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
|
864 } |
|
a488a63cb867
Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17034
diff
changeset
|
865 } |
|
16355
e4420c2468f9
Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16257
diff
changeset
|
866 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
867 void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
868 PyFrame_FastToLocals(PyFrameObject *f) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
869 { |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
870 /* Merge fast locals into f->f_locals */ |
| 5350 | 871 PyObject *locals, *map; |
| 872 PyObject **fast; | |
| 873 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
|
874 PyCodeObject *co; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
875 Py_ssize_t j; |
| 40971 | 876 int ncells, nfreevars; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
877 if (f == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
878 return; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
879 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
|
880 if (locals == NULL) { |
| 5350 | 881 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
|
882 if (locals == NULL) { |
| 5350 | 883 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
|
884 return; |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
885 } |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2627
diff
changeset
|
886 } |
|
38253
4bd299d00e4c
Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.
Richard Jones <richard@commonground.com.au>
parents:
38244
diff
changeset
|
887 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
|
888 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
|
889 if (!PyTuple_Check(map)) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
890 return; |
| 5350 | 891 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
|
892 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
|
893 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
|
894 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
|
895 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
|
896 if (co->co_nlocals) |
| 30741 | 897 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
|
898 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
|
899 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
|
900 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
|
901 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
|
902 locals, fast + co->co_nlocals, 1); |
| 40971 | 903 /* If the namespace is unoptimized, then one of the |
| 904 following cases applies: | |
| 905 1. It does not contain free variables, because it | |
| 906 uses import * or is a top-level namespace. | |
| 907 2. It is a class namespace. | |
| 908 We don't want to accidentally copy free variables | |
| 909 into the locals dict used by the class. | |
| 910 */ | |
| 911 if (co->co_flags & CO_OPTIMIZED) { | |
| 912 map_to_dict(co->co_freevars, nfreevars, | |
| 913 locals, fast + co->co_nlocals + ncells, 1); | |
| 914 } | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
915 } |
| 5350 | 916 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
|
917 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
918 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
919 void |
|
13456
6211315eb592
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
920 PyFrame_LocalsToFast(PyFrameObject *f, int clear) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
921 { |
|
5013
4ca4e54c9cd8
Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents:
5007
diff
changeset
|
922 /* Merge f->f_locals into fast locals */ |
| 5350 | 923 PyObject *locals, *map; |
| 924 PyObject **fast; | |
| 925 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
|
926 PyCodeObject *co; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35766
diff
changeset
|
927 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
|
928 int ncells, nfreevars; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
929 if (f == NULL) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
930 return; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
931 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
|
932 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
|
933 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
|
934 if (locals == NULL) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
935 return; |
|
32463
d4a59230e93a
SF Bug #215126: Over restricted type checking on eval() function
Raymond Hettinger <python@rcn.com>
parents:
31708
diff
changeset
|
936 if (!PyTuple_Check(map)) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
937 return; |
| 5350 | 938 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
|
939 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
|
940 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
|
941 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
|
942 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
|
943 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
|
944 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
|
945 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
|
946 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
|
947 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
|
948 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
|
949 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
|
950 /* 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
|
951 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
|
952 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
|
953 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
|
954 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
|
955 } |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1334
diff
changeset
|
956 } |
| 5350 | 957 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
|
958 } |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
959 |
|
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
960 /* 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
|
961 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
|
962 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
|
963 { |
|
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
|
964 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
|
965 |
|
5933
b210d2059812
Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents:
5921
diff
changeset
|
966 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
|
967 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
|
968 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
|
969 PyObject_GC_Del(f); |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
970 --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
|
971 } |
|
23018
b1ab4bc52243
SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents:
22626
diff
changeset
|
972 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
|
973 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
|
974 } |
|
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
|
975 |
|
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
|
976 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
|
977 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
|
978 { |
|
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
|
979 (void)PyFrame_ClearFreeList(); |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
980 Py_XDECREF(builtin_object); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26717
diff
changeset
|
981 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
|
982 } |
