annotate Objects/frameobject.c @ 65035:87f4b32905df 2.7

Cosmetic fix to use print function.
author Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
date Fri, 01 Oct 2010 10:48:47 +0000
parents fd25030223b0
children b36cb4602e21
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[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
18 {"f_back", T_OBJECT, OFF(f_back), RO},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
19 {"f_code", T_OBJECT, OFF(f_code), RO},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
20 {"f_builtins", T_OBJECT, OFF(f_builtins),RO},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
21 {"f_globals", T_OBJECT, OFF(f_globals), RO},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
22 {"f_lasti", T_INT, OFF(f_lasti), RO},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
23 {NULL} /* Sentinel */
86
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) { \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
28 if (PyErr_WarnPy3k(#NAME " has been removed in 3.x", 2) < 0) \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
29 return NULL; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
30 if (f->NAME) { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
31 Py_INCREF(f->NAME); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
32 return f->NAME; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
33 } \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
34 Py_RETURN_NONE; \
50259
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) { \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
37 if (PyErr_WarnPy3k(#NAME " has been removed in 3.x", 2) < 0) \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
38 return -1; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
39 if (f->NAME) { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
40 Py_CLEAR(f->NAME); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
41 } \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
42 if (new == Py_None) \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
43 new = NULL; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
44 Py_XINCREF(new); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
45 f->NAME = new; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
46 return 0; \
50259
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
58 PyFrame_FastToLocals(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
59 Py_INCREF(f->f_locals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
66 if (f->f_trace)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
67 return f->f_lineno;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
68 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
69 return PyCode_Addr2Line(f->f_code, f->f_lasti);
53931
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
96 int new_lineno = 0; /* The new value of f_lineno */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
97 int new_lasti = 0; /* The new value of f_lasti */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
98 int new_iblock = 0; /* The new value of f_iblock */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
99 unsigned char *code = NULL; /* The bytecode for the frame... */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
100 Py_ssize_t code_len = 0; /* ...and its length */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
101 unsigned char *lnotab = NULL; /* Iterating over co_lnotab */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
102 Py_ssize_t lnotab_len = 0; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
103 int offset = 0; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
104 int line = 0; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
105 int addr = 0; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
106 int min_addr = 0; /* Scanning the SETUPs and POPs */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
107 int max_addr = 0; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
108 int delta_iblock = 0; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
109 int min_delta_iblock = 0; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
110 int min_iblock = 0; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
111 int f_lasti_setup_addr = 0; /* Policing no-jump-into-finally */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
112 int new_lasti_setup_addr = 0; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
113 int blockstack[CO_MAXBLOCKS]; /* Walking the 'finally' blocks */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
114 int in_finally[CO_MAXBLOCKS]; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
115 int blockstack_top = 0; /* (ditto) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
118 /* f_lineno must be an integer. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
119 if (!PyInt_Check(p_new_lineno)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
120 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
121 "lineno must be an integer");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
122 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
123 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
124
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
125 /* You can only do this from within a trace function, not via
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
126 * _getframe or similar hackery. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
127 if (!f->f_trace)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
128 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
129 PyErr_Format(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
130 "f_lineno can only be set by a"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
131 " line trace function");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
132 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
133 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
134
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
135 /* Fail if the line comes before the start of the code block. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
136 new_lineno = (int) PyInt_AsLong(p_new_lineno);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
137 if (new_lineno < f->f_code->co_firstlineno) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
138 PyErr_Format(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
139 "line %d comes before the current code block",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
140 new_lineno);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
141 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
142 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
143 else if (new_lineno == f->f_code->co_firstlineno) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
144 new_lasti = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
145 new_lineno = f->f_code->co_firstlineno;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
146 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
147 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
148 /* Find the bytecode offset for the start of the given
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
149 * line, or the first code-owning line after it. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
150 char *tmp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
151 PyString_AsStringAndSize(f->f_code->co_lnotab,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
152 &tmp, &lnotab_len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
153 lnotab = (unsigned char *) tmp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
154 addr = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
155 line = f->f_code->co_firstlineno;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
156 new_lasti = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
157 for (offset = 0; offset < lnotab_len; offset += 2) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
158 addr += lnotab[offset];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
159 line += lnotab[offset+1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
160 if (line >= new_lineno) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
161 new_lasti = addr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
162 new_lineno = line;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
163 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
164 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
165 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
166 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
167
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
168 /* If we didn't reach the requested line, return an error. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
169 if (new_lasti == -1) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
170 PyErr_Format(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
171 "line %d comes after the current code block",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
172 new_lineno);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
173 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
174 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
175
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
176 /* We're now ready to look at the bytecode. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
177 PyString_AsStringAndSize(f->f_code->co_code, (char **)&code, &code_len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
178 min_addr = MIN(new_lasti, f->f_lasti);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
179 max_addr = MAX(new_lasti, f->f_lasti);
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
180
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
181 /* You can't jump onto a line with an 'except' statement on it -
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
182 * they expect to have an exception on the top of the stack, which
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
183 * won't be true if you jump to them. They always start with code
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
184 * that either pops the exception using POP_TOP (plain 'except:'
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
185 * lines do this) or duplicates the exception on the stack using
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
186 * DUP_TOP (if there's an exception type specified). See compile.c,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
187 * 'com_try_except' for the full details. There aren't any other
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
188 * cases (AFAIK) where a line's code can start with DUP_TOP or
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
189 * POP_TOP, but if any ever appear, they'll be subject to the same
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
190 * restriction (but with a different error message). */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
191 if (code[new_lasti] == DUP_TOP || code[new_lasti] == POP_TOP) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
192 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
193 "can't jump to 'except' line as there's no exception");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
194 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
195 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
196
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
197 /* You can't jump into or out of a 'finally' block because the 'try'
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
198 * block leaves something on the stack for the END_FINALLY to clean
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
199 * up. So we walk the bytecode, maintaining a simulated blockstack.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
200 * When we reach the old or new address and it's in a 'finally' block
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
201 * we note the address of the corresponding SETUP_FINALLY. The jump
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
202 * is only legal if neither address is in a 'finally' block or
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
203 * they're both in the same one. 'blockstack' is a stack of the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
204 * bytecode addresses of the SETUP_X opcodes, and 'in_finally' tracks
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
205 * whether we're in a 'finally' block at each blockstack level. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
206 f_lasti_setup_addr = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
207 new_lasti_setup_addr = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
208 memset(blockstack, '\0', sizeof(blockstack));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
209 memset(in_finally, '\0', sizeof(in_finally));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
210 blockstack_top = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
211 for (addr = 0; addr < code_len; addr++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
212 unsigned char op = code[addr];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
213 switch (op) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
214 case SETUP_LOOP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
215 case SETUP_EXCEPT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
216 case SETUP_FINALLY:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
217 blockstack[blockstack_top++] = addr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
218 in_finally[blockstack_top-1] = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
219 break;
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
220
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
221 case POP_BLOCK:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
222 assert(blockstack_top > 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
223 setup_op = code[blockstack[blockstack_top-1]];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
224 if (setup_op == SETUP_FINALLY) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
225 in_finally[blockstack_top-1] = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
226 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
227 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
228 blockstack_top--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
229 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
230 break;
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
231
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
232 case END_FINALLY:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
233 /* Ignore END_FINALLYs for SETUP_EXCEPTs - they exist
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
234 * in the bytecode but don't correspond to an actual
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
235 * 'finally' block. (If blockstack_top is 0, we must
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
236 * be seeing such an END_FINALLY.) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
237 if (blockstack_top > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
238 setup_op = code[blockstack[blockstack_top-1]];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
239 if (setup_op == SETUP_FINALLY) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
240 blockstack_top--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
241 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
242 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
243 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
244 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
245
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
246 /* For the addresses we're interested in, see whether they're
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
247 * within a 'finally' block and if so, remember the address
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
248 * of the SETUP_FINALLY. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
249 if (addr == new_lasti || addr == f->f_lasti) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
250 int i = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
251 int setup_addr = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
252 for (i = blockstack_top-1; i >= 0; i--) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
253 if (in_finally[i]) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
254 setup_addr = blockstack[i];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
255 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
256 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
257 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
258
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
259 if (setup_addr != -1) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
260 if (addr == new_lasti) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
261 new_lasti_setup_addr = setup_addr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
262 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
263
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
264 if (addr == f->f_lasti) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
265 f_lasti_setup_addr = setup_addr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
266 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
267 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
268 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
269
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
270 if (op >= HAVE_ARGUMENT) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
271 addr += 2;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
272 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
273 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
274
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
275 /* Verify that the blockstack tracking code didn't get lost. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
276 assert(blockstack_top == 0);
26717
f55f5e1e30bc Fix bug introduced by SF patch #643835, Set Next Statement for Python debuggers
Neal Norwitz <nnorwitz@gmail.com>
parents: 26709
diff changeset
277
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
278 /* After all that, are we jumping into / out of a 'finally' block? */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
279 if (new_lasti_setup_addr != f_lasti_setup_addr) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
280 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
281 "can't jump into or out of a 'finally' block");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
282 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
283 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
284
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
285
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
286 /* Police block-jumping (you can't jump into the middle of a block)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
287 * and ensure that the blockstack finishes up in a sensible state (by
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
288 * popping any blocks we're jumping out of). We look at all the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
289 * blockstack operations between the current position and the new
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
290 * one, and keep track of how many blocks we drop out of on the way.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
291 * By also keeping track of the lowest blockstack position we see, we
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
292 * can tell whether the jump goes into any blocks without coming out
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
293 * again - in that case we raise an exception below. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
294 delta_iblock = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
295 for (addr = min_addr; addr < max_addr; addr++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
296 unsigned char op = code[addr];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
297 switch (op) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
298 case SETUP_LOOP:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
299 case SETUP_EXCEPT:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
300 case SETUP_FINALLY:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
301 delta_iblock++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
302 break;
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
303
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
304 case POP_BLOCK:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
305 delta_iblock--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
306 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
307 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
308
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
309 min_delta_iblock = MIN(min_delta_iblock, delta_iblock);
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
310
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
311 if (op >= HAVE_ARGUMENT) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
312 addr += 2;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
313 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
314 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
315
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
316 /* Derive the absolute iblock values from the deltas. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
317 min_iblock = f->f_iblock + min_delta_iblock;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
318 if (new_lasti > f->f_lasti) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
319 /* Forwards jump. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
320 new_iblock = f->f_iblock + delta_iblock;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
321 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
322 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
323 /* Backwards jump. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
324 new_iblock = f->f_iblock - delta_iblock;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
325 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
326
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
327 /* Are we jumping into a block? */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
328 if (new_iblock > min_iblock) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
329 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
330 "can't jump into the middle of a block");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
331 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
332 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
333
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
334 /* Pop any blocks that we're jumping out of. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
335 while (f->f_iblock > new_iblock) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
336 PyTryBlock *b = &f->f_blockstack[--f->f_iblock];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
337 while ((f->f_stacktop - f->f_valuestack) > b->b_level) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
338 PyObject *v = (*--f->f_stacktop);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
339 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
340 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
341 }
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
342
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
343 /* Finally set the new f_lineno and f_lasti and return OK. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
344 f->f_lineno = new_lineno;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
345 f->f_lasti = new_lasti;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
346 return 0;
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
347 }
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
348
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
349 static PyObject *
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
350 frame_gettrace(PyFrameObject *f, void *closure)
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
351 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
352 PyObject* trace = f->f_trace;
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
353
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
354 if (trace == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
355 trace = Py_None;
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
356
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
357 Py_INCREF(trace);
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
358
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
359 return trace;
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
360 }
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
361
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
362 static int
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
363 frame_settrace(PyFrameObject *f, PyObject* v, void *closure)
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
364 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
365 PyObject* old_value;
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
366
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
367 /* We rely on f_lineno being accurate when f_trace is set. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
368 f->f_lineno = PyFrame_GetLineNumber(f);
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
369
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
370 old_value = f->f_trace;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
371 Py_XINCREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
372 f->f_trace = v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
373 Py_XDECREF(old_value);
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
374
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
375 return 0;
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
376 }
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 25074
diff changeset
377
38766
79983cf634c0 Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents: 38739
diff changeset
378 static PyObject *
79983cf634c0 Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents: 38739
diff changeset
379 frame_getrestricted(PyFrameObject *f, void *closure)
79983cf634c0 Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents: 38739
diff changeset
380 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
381 return PyBool_FromLong(PyFrame_IsRestricted(f));
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
382 }
79983cf634c0 Get rid of f_restricted too. Doc the other 4 ints that were already removed
Neal Norwitz <nnorwitz@gmail.com>
parents: 38739
diff changeset
383
20015
ca7af2a5d915 Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents: 20012
diff changeset
384 static PyGetSetDef frame_getsetlist[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
385 {"f_locals", (getter)frame_getlocals, NULL, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
386 {"f_lineno", (getter)frame_getlineno,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
387 (setter)frame_setlineno, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
388 {"f_trace", (getter)frame_gettrace, (setter)frame_settrace, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
389 {"f_restricted",(getter)frame_getrestricted,NULL, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
390 {"f_exc_traceback", (getter)frame_get_f_exc_traceback,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
391 (setter)frame_set_f_exc_traceback, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
392 {"f_exc_type", (getter)frame_get_f_exc_type,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
393 (setter)frame_set_f_exc_type, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
394 {"f_exc_value", (getter)frame_get_f_exc_value,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
395 (setter)frame_set_f_exc_value, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
396 {0}
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18510
diff changeset
397 };
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1334
diff changeset
398
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
399 /* Stack frames are allocated and deallocated at a considerable rate.
38244
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
400 In an attempt to improve the speed of function calls, we:
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
401
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
402 1. Hold a single "zombie" frame on each code object. This retains
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
403 the allocated and initialised frame object from an invocation of
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
404 the code object. The zombie is reanimated the next time we need a
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
405 frame object for that code object. Doing this saves the malloc/
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
406 realloc required when using a free_list frame that isn't the
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
407 correct size. It also saves some field initialisation.
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
408
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
409 In zombie mode, no field of PyFrameObject holds a reference, but
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
410 the following fields are still valid:
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
411
38254
bf5fb6e7527c fix broken merge
Richard Jones <richard@commonground.com.au>
parents: 38253
diff changeset
412 * ob_type, ob_size, f_code, f_valuestack;
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
413
38244
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
414 * f_locals, f_trace,
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
415 f_exc_type, f_exc_value, f_exc_traceback are NULL;
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
416
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
417 * f_localsplus does not require re-allocation and
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
418 the local variables in f_localsplus are NULL.
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
419
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
420 2. We also maintain a separate free list of stack frames (just like
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
421 integers are allocated in a special way -- see intobject.c). When
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
422 a stack frame is on the free list, only the following members have
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
423 a meaning:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
424 ob_type == &Frametype
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
425 f_back next item on free list, or NULL
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
426 f_stacksize size of value stack
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
427 ob_size size of localsplus
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
428 Note that the value and block stacks are preserved -- this can save
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
429 another malloc() call or two (and two free() calls as well!).
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
430 Also note that, unlike for integers, each frame object is a
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
431 malloc'ed object in its own right -- it is only the actual calls to
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
432 malloc() that we are trying to save here, not the administration.
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
433 After all, while a typical program may make millions of calls, a
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
434 call depth of more than 20 or 30 is probably already exceptional
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
435 unless the program contains run-away recursion. I hope.
23018
b1ab4bc52243 SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents: 22626
diff changeset
436
45191
920a7633ae08 Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents: 44350
diff changeset
437 Later, PyFrame_MAXFREELIST was added to bound the # of frames saved on
23018
b1ab4bc52243 SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents: 22626
diff changeset
438 free_list. Else programs creating lots of cyclic trash involving
b1ab4bc52243 SF bug 543148: Memory leak with stackframes + inspect.
Tim Peters <tim.peters@gmail.com>
parents: 22626
diff changeset
439 frames could provoke free_list into growing without bound.
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
440 */
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
441
5350
688c3fd42ca6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5260
diff changeset
442 static PyFrameObject *free_list = NULL;
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
443 static int numfree = 0; /* number of frames currently in free_list */
45191
920a7633ae08 Unified naming convention for free lists and their limits. All free lists
Christian Heimes <christian@cheimes.de>
parents: 44350
diff changeset
444 /* max value for numfree */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
445 #define PyFrame_MAXFREELIST 200
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
446
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 static void
13456
6211315eb592 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
448 frame_dealloc(PyFrameObject *f)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
450 PyObject **p, **valuestack;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
451 PyCodeObject *co;
5097
57b7a03a3252 Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents: 5045
diff changeset
452
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
453 PyObject_GC_UnTrack(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
454 Py_TRASHCAN_SAFE_BEGIN(f)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
455 /* Kill all local variables */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
456 valuestack = f->f_valuestack;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
457 for (p = f->f_localsplus; p < valuestack; p++)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
458 Py_CLEAR(*p);
5097
57b7a03a3252 Kill all local variables when the frame is deallocated (moved here
Guido van Rossum <guido@python.org>
parents: 5045
diff changeset
459
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
460 /* Free stack */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
461 if (f->f_stacktop != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
462 for (p = valuestack; p < f->f_stacktop; p++)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
463 Py_XDECREF(*p);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
464 }
37727
62c9038a578a Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 37724
diff changeset
465
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
466 Py_XDECREF(f->f_back);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
467 Py_DECREF(f->f_builtins);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
468 Py_DECREF(f->f_globals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
469 Py_CLEAR(f->f_locals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
470 Py_CLEAR(f->f_trace);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
471 Py_CLEAR(f->f_exc_type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
472 Py_CLEAR(f->f_exc_value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
473 Py_CLEAR(f->f_exc_traceback);
38244
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
474
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
475 co = f->f_code;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
476 if (co->co_zombieframe == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
477 co->co_zombieframe = f;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
478 else if (numfree < PyFrame_MAXFREELIST) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
479 ++numfree;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
480 f->f_back = free_list;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
481 free_list = f;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
482 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
483 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
484 PyObject_GC_Del(f);
38244
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
485
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
486 Py_DECREF(co);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
487 Py_TRASHCAN_SAFE_END(f)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
488 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
489
18510
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
490 static int
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
491 frame_traverse(PyFrameObject *f, visitproc visit, void *arg)
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
492 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
493 PyObject **fastlocals, **p;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
494 int i, slots;
18510
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
495
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
496 Py_VISIT(f->f_back);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
497 Py_VISIT(f->f_code);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
498 Py_VISIT(f->f_builtins);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
499 Py_VISIT(f->f_globals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
500 Py_VISIT(f->f_locals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
501 Py_VISIT(f->f_trace);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
502 Py_VISIT(f->f_exc_type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
503 Py_VISIT(f->f_exc_value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
504 Py_VISIT(f->f_exc_traceback);
18510
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
505
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
506 /* locals */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
507 slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + PyTuple_GET_SIZE(f->f_code->co_freevars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
508 fastlocals = f->f_localsplus;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
509 for (i = slots; --i >= 0; ++fastlocals)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
510 Py_VISIT(*fastlocals);
18510
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
511
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
512 /* stack */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
513 if (f->f_stacktop != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
514 for (p = f->f_valuestack; p < f->f_stacktop; p++)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
515 Py_VISIT(*p);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
516 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
517 return 0;
18510
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
518 }
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
519
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
520 static void
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
521 frame_clear(PyFrameObject *f)
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
522 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
523 PyObject **fastlocals, **p, **oldtop;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
524 int i, slots;
18510
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
525
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
526 /* Before anything else, make sure that this frame is clearly marked
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
527 * as being defunct! Else, e.g., a generator reachable from this
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
528 * frame may also point to this frame, believe itself to still be
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
529 * active, and try cleaning up this frame again.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
530 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
531 oldtop = f->f_stacktop;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
532 f->f_stacktop = NULL;
37724
31929da0b05a Fix SF#1470508: crash in generator cycle finalization. There were two
Phillip J. Eby <pje@telecommunity.com>
parents: 37086
diff changeset
533
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
534 Py_CLEAR(f->f_exc_type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
535 Py_CLEAR(f->f_exc_value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
536 Py_CLEAR(f->f_exc_traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
537 Py_CLEAR(f->f_trace);
18510
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
538
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
539 /* locals */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
540 slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + PyTuple_GET_SIZE(f->f_code->co_freevars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
541 fastlocals = f->f_localsplus;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
542 for (i = slots; --i >= 0; ++fastlocals)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
543 Py_CLEAR(*fastlocals);
18510
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
544
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
545 /* stack */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
546 if (oldtop != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
547 for (p = f->f_valuestack; p < oldtop; p++)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
548 Py_CLEAR(*p);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
549 }
18510
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
550 }
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
551
47922
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
552 static PyObject *
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
553 frame_sizeof(PyFrameObject *f)
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
554 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
555 Py_ssize_t res, extras, ncells, nfrees;
47922
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
556
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
557 ncells = PyTuple_GET_SIZE(f->f_code->co_cellvars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
558 nfrees = PyTuple_GET_SIZE(f->f_code->co_freevars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
559 extras = f->f_code->co_stacksize + f->f_code->co_nlocals +
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
560 ncells + nfrees;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
561 /* subtract one as it is already included in PyFrameObject */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
562 res = sizeof(PyFrameObject) + (extras-1) * sizeof(PyObject *);
47922
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
563
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
564 return PyInt_FromSsize_t(res);
47922
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
565 }
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
566
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
567 PyDoc_STRVAR(sizeof__doc__,
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
568 "F.__sizeof__() -> size of F in memory, in bytes");
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
569
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
570 static PyMethodDef frame_methods[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
571 {"__sizeof__", (PyCFunction)frame_sizeof, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
572 sizeof__doc__},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
573 {NULL, NULL} /* sentinel */
47922
7cfc28ac0715 Added additional __sizeof__ implementations and addressed comments made in
Robert Schuppenies <okkotonushi@googlemail.com>
parents: 47527
diff changeset
574 };
18510
f4ea21a0f954 GC for frame objects.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18237
diff changeset
575
5350
688c3fd42ca6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5260
diff changeset
576 PyTypeObject PyFrame_Type = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
577 PyVarObject_HEAD_INIT(&PyType_Type, 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
578 "frame",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
579 sizeof(PyFrameObject),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
580 sizeof(PyObject *),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
581 (destructor)frame_dealloc, /* tp_dealloc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
582 0, /* tp_print */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
583 0, /* tp_getattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
584 0, /* tp_setattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
585 0, /* tp_compare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
586 0, /* tp_repr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
587 0, /* tp_as_number */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
588 0, /* tp_as_sequence */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
589 0, /* tp_as_mapping */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
590 0, /* tp_hash */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
591 0, /* tp_call */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
592 0, /* tp_str */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
593 PyObject_GenericGetAttr, /* tp_getattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
594 PyObject_GenericSetAttr, /* tp_setattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
595 0, /* tp_as_buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
596 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
597 0, /* tp_doc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
598 (traverseproc)frame_traverse, /* tp_traverse */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
599 (inquiry)frame_clear, /* tp_clear */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
600 0, /* tp_richcompare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
601 0, /* tp_weaklistoffset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
602 0, /* tp_iter */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
603 0, /* tp_iternext */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
604 frame_methods, /* tp_methods */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
605 frame_memberlist, /* tp_members */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
606 frame_getsetlist, /* tp_getset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
607 0, /* tp_base */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
608 0, /* tp_dict */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
609 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
610
26889
12753e7b15f7 SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents: 26717
diff changeset
611 static PyObject *builtin_object;
12753e7b15f7 SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents: 26717
diff changeset
612
26923
dbfc3ef7d003 Since the *_Init() are private, prefix with _, suggested by Skip
Neal Norwitz <nnorwitz@gmail.com>
parents: 26889
diff changeset
613 int _PyFrame_Init()
26889
12753e7b15f7 SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents: 26717
diff changeset
614 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
615 builtin_object = PyString_InternFromString("__builtins__");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
616 if (builtin_object == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
617 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
618 return 1;
26889
12753e7b15f7 SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents: 26717
diff changeset
619 }
12753e7b15f7 SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents: 26717
diff changeset
620
5350
688c3fd42ca6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5260
diff changeset
621 PyFrameObject *
37727
62c9038a578a Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 37724
diff changeset
622 PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
623 PyObject *locals)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
624 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
625 PyFrameObject *back = tstate->frame;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
626 PyFrameObject *f;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
627 PyObject *builtins;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
628 Py_ssize_t i;
5013
4ca4e54c9cd8 Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents: 5007
diff changeset
629
24895
c8d9592c9e74 Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents: 24844
diff changeset
630 #ifdef Py_DEBUG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
631 if (code == NULL || globals == NULL || !PyDict_Check(globals) ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
632 (locals != NULL && !PyMapping_Check(locals))) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
633 PyErr_BadInternalCall();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
634 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
635 }
24895
c8d9592c9e74 Check in my ultra-shortlived patch #597220.
Michael W. Hudson <mwh@python.net>
parents: 24844
diff changeset
636 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
637 if (back == NULL || back->f_globals != globals) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
638 builtins = PyDict_GetItem(globals, builtin_object);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
639 if (builtins) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
640 if (PyModule_Check(builtins)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
641 builtins = PyModule_GetDict(builtins);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
642 assert(!builtins || PyDict_Check(builtins));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
643 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
644 else if (!PyDict_Check(builtins))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
645 builtins = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
646 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
647 if (builtins == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
648 /* No builtins! Make up a minimal one
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
649 Give them 'None', at least. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
650 builtins = PyDict_New();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
651 if (builtins == NULL ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
652 PyDict_SetItemString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
653 builtins, "None", Py_None) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
654 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
655 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
656 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
657 Py_INCREF(builtins);
27706
537bfce2b730 Refactor the logic for setting f_builtins.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26923
diff changeset
658
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
659 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
660 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
661 /* If we share the globals, we share the builtins.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
662 Save a lookup and a call. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
663 builtins = back->f_builtins;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
664 assert(builtins != NULL && PyDict_Check(builtins));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
665 Py_INCREF(builtins);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
666 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
667 if (code->co_zombieframe != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
668 f = code->co_zombieframe;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
669 code->co_zombieframe = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
670 _Py_NewReference((PyObject *)f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
671 assert(f->f_code == code);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
672 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
673 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
674 Py_ssize_t extras, ncells, nfrees;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
675 ncells = PyTuple_GET_SIZE(code->co_cellvars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
676 nfrees = PyTuple_GET_SIZE(code->co_freevars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
677 extras = code->co_stacksize + code->co_nlocals + ncells +
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
678 nfrees;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
679 if (free_list == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
680 f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
681 extras);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
682 if (f == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
683 Py_DECREF(builtins);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
684 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
685 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
686 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
687 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
688 assert(numfree > 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
689 --numfree;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
690 f = free_list;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
691 free_list = free_list->f_back;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
692 if (Py_SIZE(f) < extras) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
693 f = PyObject_GC_Resize(PyFrameObject, f, extras);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
694 if (f == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
695 Py_DECREF(builtins);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
696 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
697 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
698 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
699 _Py_NewReference((PyObject *)f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
700 }
38244
a637c78bf119 Merge from rjones-funccall branch.
Richard Jones <richard@commonground.com.au>
parents: 37729
diff changeset
701
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
702 f->f_code = code;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
703 extras = code->co_nlocals + ncells + nfrees;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
704 f->f_valuestack = f->f_localsplus + extras;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
705 for (i=0; i<extras; i++)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
706 f->f_localsplus[i] = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
707 f->f_locals = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
708 f->f_trace = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
709 f->f_exc_type = f->f_exc_value = f->f_exc_traceback = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
710 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
711 f->f_stacktop = f->f_valuestack;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
712 f->f_builtins = builtins;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
713 Py_XINCREF(back);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
714 f->f_back = back;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
715 Py_INCREF(code);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
716 Py_INCREF(globals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
717 f->f_globals = globals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
718 /* Most functions have CO_NEWLOCALS and CO_OPTIMIZED set. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
719 if ((code->co_flags & (CO_NEWLOCALS | CO_OPTIMIZED)) ==
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
720 (CO_NEWLOCALS | CO_OPTIMIZED))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
721 ; /* f_locals = NULL; will be set by PyFrame_FastToLocals() */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
722 else if (code->co_flags & CO_NEWLOCALS) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
723 locals = PyDict_New();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
724 if (locals == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
725 Py_DECREF(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
726 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
727 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
728 f->f_locals = locals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
729 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
730 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
731 if (locals == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
732 locals = globals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
733 Py_INCREF(locals);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
734 f->f_locals = locals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
735 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
736 f->f_tstate = tstate;
5013
4ca4e54c9cd8 Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents: 5007
diff changeset
737
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
738 f->f_lasti = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
739 f->f_lineno = code->co_firstlineno;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
740 f->f_iblock = 0;
5013
4ca4e54c9cd8 Changes that appear to give another 12% speedup.
Guido van Rossum <guido@python.org>
parents: 5007
diff changeset
741
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
742 _PyObject_GC_TRACK(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
743 return f;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
744 }
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 /* Block management */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
747
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
748 void
13456
6211315eb592 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
749 PyFrame_BlockSetup(PyFrameObject *f, int type, int handler, int level)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
750 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
751 PyTryBlock *b;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
752 if (f->f_iblock >= CO_MAXBLOCKS)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
753 Py_FatalError("XXX block stack overflow");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
754 b = &f->f_blockstack[f->f_iblock++];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
755 b->b_type = type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
756 b->b_level = level;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
757 b->b_handler = handler;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
758 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
759
5350
688c3fd42ca6 Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5260
diff changeset
760 PyTryBlock *
13456
6211315eb592 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
761 PyFrame_BlockPop(PyFrameObject *f)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
762 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
763 PyTryBlock *b;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
764 if (f->f_iblock <= 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
765 Py_FatalError("XXX block stack underflow");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
766 b = &f->f_blockstack[--f->f_iblock];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
767 return b;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
768 }
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1334
diff changeset
769
40938
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
770 /* Convert between "fast" version of locals and dictionary version.
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
771
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
772 map and values are input arguments. map is a tuple of strings.
40938
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
773 values is an array of PyObject*. At index i, map[i] is the name of
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
774 the variable with value values[i]. The function copies the first
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
775 nmap variable from map/values into dict. If values[i] is NULL,
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
776 the variable is deleted from dict.
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
777
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
778 If deref is true, then the values being copied are cell variables
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
779 and the value is extracted from the cell variable before being put
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
780 in dict.
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
781
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
782 Exceptions raised while modifying the dict are silently ignored,
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
783 because there is no good way to report them.
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
784 */
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1334
diff changeset
785
17518
f939ce52a734 Make some private symbols static.
Guido van Rossum <guido@python.org>
parents: 17104
diff changeset
786 static void
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35766
diff changeset
787 map_to_dict(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
788 int deref)
17104
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
789 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
790 Py_ssize_t j;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
791 assert(PyTuple_Check(map));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
792 assert(PyDict_Check(dict));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
793 assert(PyTuple_Size(map) >= nmap);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
794 for (j = nmap; --j >= 0; ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
795 PyObject *key = PyTuple_GET_ITEM(map, j);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
796 PyObject *value = values[j];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
797 assert(PyString_Check(key));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
798 if (deref) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
799 assert(PyCell_Check(value));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
800 value = PyCell_GET(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
801 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
802 if (value == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
803 if (PyObject_DelItem(dict, key) != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
804 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
805 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
806 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
807 if (PyObject_SetItem(dict, key, value) != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
808 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
809 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
810 }
17104
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
811 }
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
812
40938
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
813 /* Copy values from the "locals" dict into the fast locals.
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
814
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
815 dict is an input argument containing string keys representing
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
816 variables names and arbitrary PyObject* as values.
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
817
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
818 map and values are input arguments. map is a tuple of strings.
40938
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
819 values is an array of PyObject*. At index i, map[i] is the name of
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
820 the variable with value values[i]. The function copies the first
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
821 nmap variable from map/values into dict. If values[i] is NULL,
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
822 the variable is deleted from dict.
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
823
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
824 If deref is true, then the values being copied are cell variables
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
825 and the value is extracted from the cell variable before being put
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
826 in dict. If clear is true, then variables in map but not in dict
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
827 are set to NULL in map; if clear is false, variables missing in
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
828 dict are ignored.
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
829
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
830 Exceptions raised while modifying the dict are silently ignored,
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
831 because there is no good way to report them.
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
832 */
047ee23c0f87 Do not copy free variables to locals in class namespaces.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 39128
diff changeset
833
17519
f9dfd587c142 Make one more private symbol static.
Guido van Rossum <guido@python.org>
parents: 17518
diff changeset
834 static void
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35766
diff changeset
835 dict_to_map(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
836 int deref, int clear)
17104
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
837 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
838 Py_ssize_t j;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
839 assert(PyTuple_Check(map));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
840 assert(PyDict_Check(dict));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
841 assert(PyTuple_Size(map) >= nmap);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
842 for (j = nmap; --j >= 0; ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
843 PyObject *key = PyTuple_GET_ITEM(map, j);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
844 PyObject *value = PyObject_GetItem(dict, key);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
845 assert(PyString_Check(key));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
846 /* We only care about NULLs if clear is true. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
847 if (value == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
848 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
849 if (!clear)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
850 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
851 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
852 if (deref) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
853 assert(PyCell_Check(values[j]));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
854 if (PyCell_GET(values[j]) != value) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
855 if (PyCell_Set(values[j], value) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
856 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
857 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
858 } else if (values[j] != value) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
859 Py_XINCREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
860 Py_XDECREF(values[j]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
861 values[j] = value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
862 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
863 Py_XDECREF(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
864 }
17104
a488a63cb867 Fix PyFrame_FastToLocals() and counterpart to deal with cells and
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 17034
diff changeset
865 }
16355
e4420c2468f9 Remove f_closure slot of frameobject and use f_localsplus instead.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16257
diff changeset
866
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1334
diff changeset
867 void
13456
6211315eb592 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
868 PyFrame_FastToLocals(PyFrameObject *f)
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1334
diff changeset
869 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
870 /* Merge fast locals into f->f_locals */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
871 PyObject *locals, *map;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
872 PyObject **fast;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
873 PyObject *error_type, *error_value, *error_traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
874 PyCodeObject *co;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
875 Py_ssize_t j;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
876 int ncells, nfreevars;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
877 if (f == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
878 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
879 locals = f->f_locals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
880 if (locals == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
881 locals = f->f_locals = PyDict_New();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
882 if (locals == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
883 PyErr_Clear(); /* Can't report it :-( */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
884 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
885 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
886 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
887 co = f->f_code;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
888 map = co->co_varnames;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
889 if (!PyTuple_Check(map))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
890 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
891 PyErr_Fetch(&error_type, &error_value, &error_traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
892 fast = f->f_localsplus;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
893 j = PyTuple_GET_SIZE(map);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
894 if (j > co->co_nlocals)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
895 j = co->co_nlocals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
896 if (co->co_nlocals)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
897 map_to_dict(map, j, locals, fast, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
898 ncells = PyTuple_GET_SIZE(co->co_cellvars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
899 nfreevars = PyTuple_GET_SIZE(co->co_freevars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
900 if (ncells || nfreevars) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
901 map_to_dict(co->co_cellvars, ncells,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
902 locals, fast + co->co_nlocals, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
903 /* If the namespace is unoptimized, then one of the
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
904 following cases applies:
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
905 1. It does not contain free variables, because it
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
906 uses import * or is a top-level namespace.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
907 2. It is a class namespace.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
908 We don't want to accidentally copy free variables
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
909 into the locals dict used by the class.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
910 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
911 if (co->co_flags & CO_OPTIMIZED) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
912 map_to_dict(co->co_freevars, nfreevars,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
913 locals, fast + co->co_nlocals + ncells, 1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
914 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
915 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
916 PyErr_Restore(error_type, error_value, error_traceback);
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1334
diff changeset
917 }
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1334
diff changeset
918
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1334
diff changeset
919 void
13456
6211315eb592 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
920 PyFrame_LocalsToFast(PyFrameObject *f, int clear)
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1334
diff changeset
921 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
922 /* Merge f->f_locals into fast locals */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
923 PyObject *locals, *map;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
924 PyObject **fast;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
925 PyObject *error_type, *error_value, *error_traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
926 PyCodeObject *co;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
927 Py_ssize_t j;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
928 int ncells, nfreevars;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
929 if (f == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
930 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
931 locals = f->f_locals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
932 co = f->f_code;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
933 map = co->co_varnames;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
934 if (locals == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
935 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
936 if (!PyTuple_Check(map))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
937 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
938 PyErr_Fetch(&error_type, &error_value, &error_traceback);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
939 fast = f->f_localsplus;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
940 j = PyTuple_GET_SIZE(map);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
941 if (j > co->co_nlocals)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
942 j = co->co_nlocals;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
943 if (co->co_nlocals)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
944 dict_to_map(co->co_varnames, j, locals, fast, 0, clear);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
945 ncells = PyTuple_GET_SIZE(co->co_cellvars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
946 nfreevars = PyTuple_GET_SIZE(co->co_freevars);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
947 if (ncells || nfreevars) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
948 dict_to_map(co->co_cellvars, ncells,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
949 locals, fast + co->co_nlocals, 1, clear);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
950 /* Same test as in PyFrame_FastToLocals() above. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
951 if (co->co_flags & CO_OPTIMIZED) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
952 dict_to_map(co->co_freevars, nfreevars,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
953 locals, fast + co->co_nlocals + ncells, 1,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
954 clear);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
955 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
956 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
957 PyErr_Restore(error_type, error_value, error_traceback);
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1334
diff changeset
958 }
5933
b210d2059812 Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents: 5921
diff changeset
959
b210d2059812 Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents: 5921
diff changeset
960 /* Clear out the free list */
45341
65ae68c7aca3 Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents: 45191
diff changeset
961 int
65ae68c7aca3 Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents: 45191
diff changeset
962 PyFrame_ClearFreeList(void)
5933
b210d2059812 Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents: 5921
diff changeset
963 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
964 int freelist_size = numfree;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
965
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
966 while (free_list != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
967 PyFrameObject *f = free_list;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
968 free_list = free_list->f_back;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
969 PyObject_GC_Del(f);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
970 --numfree;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
971 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
972 assert(numfree == 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
973 return freelist_size;
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
974 }
65ae68c7aca3 Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents: 45191
diff changeset
975
65ae68c7aca3 Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents: 45191
diff changeset
976 void
65ae68c7aca3 Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents: 45191
diff changeset
977 PyFrame_Fini(void)
65ae68c7aca3 Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Christian Heimes <christian@cheimes.de>
parents: 45191
diff changeset
978 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
979 (void)PyFrame_ClearFreeList();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
980 Py_XDECREF(builtin_object);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54505
diff changeset
981 builtin_object = NULL;
5933
b210d2059812 Provide a dummy empty directory as f_builtins instead of failing, when
Guido van Rossum <guido@python.org>
parents: 5921
diff changeset
982 }