annotate Objects/frameobject.c @ 54294:dba767bc3155 legacy-trunk

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