Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 1 | /* Frame object implementation */ |
| 2 | |
Guido van Rossum | 1875247 | 1997-04-29 14:49:28 +0000 | [diff] [blame] | 3 | #include "Python.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 4 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5 | #include "code.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 6 | #include "frameobject.h" |
| 7 | #include "opcode.h" |
| 8 | #include "structmember.h" |
| 9 | |
Guido van Rossum | 1875247 | 1997-04-29 14:49:28 +0000 | [diff] [blame] | 10 | #define OFF(x) offsetof(PyFrameObject, x) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 11 | |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 12 | static PyMemberDef frame_memberlist[] = { |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 13 | {"f_back", T_OBJECT, OFF(f_back), READONLY}, |
| 14 | {"f_code", T_OBJECT, OFF(f_code), READONLY}, |
| 15 | {"f_builtins", T_OBJECT, OFF(f_builtins), READONLY}, |
| 16 | {"f_globals", T_OBJECT, OFF(f_globals), READONLY}, |
| 17 | {"f_lasti", T_INT, OFF(f_lasti), READONLY}, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 18 | {NULL} /* Sentinel */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 19 | }; |
| 20 | |
Guido van Rossum | 1875247 | 1997-04-29 14:49:28 +0000 | [diff] [blame] | 21 | static PyObject * |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 22 | frame_getlocals(PyFrameObject *f, void *closure) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 23 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 24 | PyFrame_FastToLocals(f); |
| 25 | Py_INCREF(f->f_locals); |
| 26 | return f->f_locals; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 27 | } |
| 28 | |
Alexandre Vassalotti | 7b82b40 | 2009-07-21 04:30:03 +0000 | [diff] [blame] | 29 | int |
| 30 | PyFrame_GetLineNumber(PyFrameObject *f) |
| 31 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 32 | if (f->f_trace) |
| 33 | return f->f_lineno; |
| 34 | else |
| 35 | return PyCode_Addr2Line(f->f_code, f->f_lasti); |
Alexandre Vassalotti | 7b82b40 | 2009-07-21 04:30:03 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Michael W. Hudson | dd32a91 | 2002-08-15 14:59:02 +0000 | [diff] [blame] | 38 | static PyObject * |
| 39 | frame_getlineno(PyFrameObject *f, void *closure) |
| 40 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 41 | return PyLong_FromLong(PyFrame_GetLineNumber(f)); |
Michael W. Hudson | dd32a91 | 2002-08-15 14:59:02 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 44 | /* Setter for f_lineno - you can set f_lineno from within a trace function in |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 45 | * order to jump to a given line of code, subject to some restrictions. Most |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 46 | * lines are OK to jump to because they don't make any assumptions about the |
| 47 | * state of the stack (obvious because you could remove the line and the code |
| 48 | * would still work without any stack errors), but there are some constructs |
| 49 | * that limit jumping: |
| 50 | * |
| 51 | * o Lines with an 'except' statement on them can't be jumped to, because |
| 52 | * they expect an exception to be on the top of the stack. |
| 53 | * o Lines that live in a 'finally' block can't be jumped from or to, since |
| 54 | * the END_FINALLY expects to clean up the stack after the 'try' block. |
| 55 | * o 'try'/'for'/'while' blocks can't be jumped into because the blockstack |
| 56 | * needs to be set up before their code runs, and for 'for' loops the |
| 57 | * iterator needs to be on the stack. |
| 58 | */ |
| 59 | static int |
| 60 | frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno) |
| 61 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 62 | int new_lineno = 0; /* The new value of f_lineno */ |
| 63 | long l_new_lineno; |
| 64 | int overflow; |
| 65 | int new_lasti = 0; /* The new value of f_lasti */ |
| 66 | int new_iblock = 0; /* The new value of f_iblock */ |
| 67 | unsigned char *code = NULL; /* The bytecode for the frame... */ |
| 68 | Py_ssize_t code_len = 0; /* ...and its length */ |
| 69 | unsigned char *lnotab = NULL; /* Iterating over co_lnotab */ |
| 70 | Py_ssize_t lnotab_len = 0; /* (ditto) */ |
| 71 | int offset = 0; /* (ditto) */ |
| 72 | int line = 0; /* (ditto) */ |
| 73 | int addr = 0; /* (ditto) */ |
| 74 | int min_addr = 0; /* Scanning the SETUPs and POPs */ |
| 75 | int max_addr = 0; /* (ditto) */ |
| 76 | int delta_iblock = 0; /* (ditto) */ |
| 77 | int min_delta_iblock = 0; /* (ditto) */ |
| 78 | int min_iblock = 0; /* (ditto) */ |
| 79 | int f_lasti_setup_addr = 0; /* Policing no-jump-into-finally */ |
| 80 | int new_lasti_setup_addr = 0; /* (ditto) */ |
| 81 | int blockstack[CO_MAXBLOCKS]; /* Walking the 'finally' blocks */ |
| 82 | int in_finally[CO_MAXBLOCKS]; /* (ditto) */ |
| 83 | int blockstack_top = 0; /* (ditto) */ |
| 84 | unsigned char setup_op = 0; /* (ditto) */ |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 85 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 86 | /* f_lineno must be an integer. */ |
| 87 | if (!PyLong_CheckExact(p_new_lineno)) { |
| 88 | PyErr_SetString(PyExc_ValueError, |
| 89 | "lineno must be an integer"); |
| 90 | return -1; |
| 91 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 92 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 93 | /* You can only do this from within a trace function, not via |
| 94 | * _getframe or similar hackery. */ |
| 95 | if (!f->f_trace) |
| 96 | { |
| 97 | PyErr_Format(PyExc_ValueError, |
| 98 | "f_lineno can only be set by a" |
| 99 | " line trace function"); |
| 100 | return -1; |
| 101 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 102 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 103 | /* Fail if the line comes before the start of the code block. */ |
| 104 | l_new_lineno = PyLong_AsLongAndOverflow(p_new_lineno, &overflow); |
| 105 | if (overflow |
Martin v. Löwis | d1a1d1e | 2007-12-04 22:10:37 +0000 | [diff] [blame] | 106 | #if SIZEOF_LONG > SIZEOF_INT |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 107 | || l_new_lineno > INT_MAX |
| 108 | || l_new_lineno < INT_MIN |
Martin v. Löwis | d1a1d1e | 2007-12-04 22:10:37 +0000 | [diff] [blame] | 109 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 110 | ) { |
| 111 | PyErr_SetString(PyExc_ValueError, |
| 112 | "lineno out of range"); |
| 113 | return -1; |
| 114 | } |
| 115 | new_lineno = (int)l_new_lineno; |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 116 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 117 | if (new_lineno < f->f_code->co_firstlineno) { |
| 118 | PyErr_Format(PyExc_ValueError, |
| 119 | "line %d comes before the current code block", |
| 120 | new_lineno); |
| 121 | return -1; |
| 122 | } |
| 123 | else if (new_lineno == f->f_code->co_firstlineno) { |
| 124 | new_lasti = 0; |
| 125 | new_lineno = f->f_code->co_firstlineno; |
| 126 | } |
| 127 | else { |
| 128 | /* Find the bytecode offset for the start of the given |
| 129 | * line, or the first code-owning line after it. */ |
| 130 | char *tmp; |
| 131 | PyBytes_AsStringAndSize(f->f_code->co_lnotab, |
| 132 | &tmp, &lnotab_len); |
| 133 | lnotab = (unsigned char *) tmp; |
| 134 | addr = 0; |
| 135 | line = f->f_code->co_firstlineno; |
| 136 | new_lasti = -1; |
| 137 | for (offset = 0; offset < lnotab_len; offset += 2) { |
| 138 | addr += lnotab[offset]; |
| 139 | line += lnotab[offset+1]; |
| 140 | if (line >= new_lineno) { |
| 141 | new_lasti = addr; |
| 142 | new_lineno = line; |
| 143 | break; |
| 144 | } |
| 145 | } |
| 146 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 147 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 148 | /* If we didn't reach the requested line, return an error. */ |
| 149 | if (new_lasti == -1) { |
| 150 | PyErr_Format(PyExc_ValueError, |
| 151 | "line %d comes after the current code block", |
| 152 | new_lineno); |
| 153 | return -1; |
| 154 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 155 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 156 | /* We're now ready to look at the bytecode. */ |
| 157 | PyBytes_AsStringAndSize(f->f_code->co_code, (char **)&code, &code_len); |
Victor Stinner | 640c35c | 2013-06-04 23:14:37 +0200 | [diff] [blame] | 158 | min_addr = Py_MIN(new_lasti, f->f_lasti); |
| 159 | max_addr = Py_MAX(new_lasti, f->f_lasti); |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 160 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 161 | /* You can't jump onto a line with an 'except' statement on it - |
| 162 | * they expect to have an exception on the top of the stack, which |
| 163 | * won't be true if you jump to them. They always start with code |
| 164 | * that either pops the exception using POP_TOP (plain 'except:' |
| 165 | * lines do this) or duplicates the exception on the stack using |
| 166 | * DUP_TOP (if there's an exception type specified). See compile.c, |
| 167 | * 'com_try_except' for the full details. There aren't any other |
| 168 | * cases (AFAIK) where a line's code can start with DUP_TOP or |
| 169 | * POP_TOP, but if any ever appear, they'll be subject to the same |
| 170 | * restriction (but with a different error message). */ |
| 171 | if (code[new_lasti] == DUP_TOP || code[new_lasti] == POP_TOP) { |
| 172 | PyErr_SetString(PyExc_ValueError, |
| 173 | "can't jump to 'except' line as there's no exception"); |
| 174 | return -1; |
| 175 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 176 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 177 | /* You can't jump into or out of a 'finally' block because the 'try' |
| 178 | * block leaves something on the stack for the END_FINALLY to clean |
| 179 | * up. So we walk the bytecode, maintaining a simulated blockstack. |
| 180 | * When we reach the old or new address and it's in a 'finally' block |
| 181 | * we note the address of the corresponding SETUP_FINALLY. The jump |
| 182 | * is only legal if neither address is in a 'finally' block or |
| 183 | * they're both in the same one. 'blockstack' is a stack of the |
| 184 | * bytecode addresses of the SETUP_X opcodes, and 'in_finally' tracks |
| 185 | * whether we're in a 'finally' block at each blockstack level. */ |
| 186 | f_lasti_setup_addr = -1; |
| 187 | new_lasti_setup_addr = -1; |
| 188 | memset(blockstack, '\0', sizeof(blockstack)); |
| 189 | memset(in_finally, '\0', sizeof(in_finally)); |
| 190 | blockstack_top = 0; |
| 191 | for (addr = 0; addr < code_len; addr++) { |
| 192 | unsigned char op = code[addr]; |
| 193 | switch (op) { |
| 194 | case SETUP_LOOP: |
| 195 | case SETUP_EXCEPT: |
| 196 | case SETUP_FINALLY: |
Benjamin Peterson | e42fb30 | 2012-04-18 11:14:31 -0400 | [diff] [blame] | 197 | case SETUP_WITH: |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 198 | blockstack[blockstack_top++] = addr; |
| 199 | in_finally[blockstack_top-1] = 0; |
| 200 | break; |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 201 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 202 | case POP_BLOCK: |
| 203 | assert(blockstack_top > 0); |
| 204 | setup_op = code[blockstack[blockstack_top-1]]; |
Benjamin Peterson | e42fb30 | 2012-04-18 11:14:31 -0400 | [diff] [blame] | 205 | if (setup_op == SETUP_FINALLY || setup_op == SETUP_WITH) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 206 | in_finally[blockstack_top-1] = 1; |
| 207 | } |
| 208 | else { |
| 209 | blockstack_top--; |
| 210 | } |
| 211 | break; |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 212 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 213 | case END_FINALLY: |
| 214 | /* Ignore END_FINALLYs for SETUP_EXCEPTs - they exist |
| 215 | * in the bytecode but don't correspond to an actual |
| 216 | * 'finally' block. (If blockstack_top is 0, we must |
| 217 | * be seeing such an END_FINALLY.) */ |
| 218 | if (blockstack_top > 0) { |
| 219 | setup_op = code[blockstack[blockstack_top-1]]; |
Benjamin Peterson | e42fb30 | 2012-04-18 11:14:31 -0400 | [diff] [blame] | 220 | if (setup_op == SETUP_FINALLY || setup_op == SETUP_WITH) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 221 | blockstack_top--; |
| 222 | } |
| 223 | } |
| 224 | break; |
| 225 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 226 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 227 | /* For the addresses we're interested in, see whether they're |
| 228 | * within a 'finally' block and if so, remember the address |
| 229 | * of the SETUP_FINALLY. */ |
| 230 | if (addr == new_lasti || addr == f->f_lasti) { |
| 231 | int i = 0; |
| 232 | int setup_addr = -1; |
| 233 | for (i = blockstack_top-1; i >= 0; i--) { |
| 234 | if (in_finally[i]) { |
| 235 | setup_addr = blockstack[i]; |
| 236 | break; |
| 237 | } |
| 238 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 239 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 240 | if (setup_addr != -1) { |
| 241 | if (addr == new_lasti) { |
| 242 | new_lasti_setup_addr = setup_addr; |
| 243 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 244 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 245 | if (addr == f->f_lasti) { |
| 246 | f_lasti_setup_addr = setup_addr; |
| 247 | } |
| 248 | } |
| 249 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 250 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 251 | if (op >= HAVE_ARGUMENT) { |
| 252 | addr += 2; |
| 253 | } |
| 254 | } |
Neal Norwitz | ee65e22 | 2002-12-19 18:16:57 +0000 | [diff] [blame] | 255 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 256 | /* Verify that the blockstack tracking code didn't get lost. */ |
| 257 | assert(blockstack_top == 0); |
| 258 | |
| 259 | /* After all that, are we jumping into / out of a 'finally' block? */ |
| 260 | if (new_lasti_setup_addr != f_lasti_setup_addr) { |
| 261 | PyErr_SetString(PyExc_ValueError, |
| 262 | "can't jump into or out of a 'finally' block"); |
| 263 | return -1; |
| 264 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 265 | |
| 266 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 267 | /* Police block-jumping (you can't jump into the middle of a block) |
| 268 | * and ensure that the blockstack finishes up in a sensible state (by |
| 269 | * popping any blocks we're jumping out of). We look at all the |
| 270 | * blockstack operations between the current position and the new |
| 271 | * one, and keep track of how many blocks we drop out of on the way. |
| 272 | * By also keeping track of the lowest blockstack position we see, we |
| 273 | * can tell whether the jump goes into any blocks without coming out |
| 274 | * again - in that case we raise an exception below. */ |
| 275 | delta_iblock = 0; |
| 276 | for (addr = min_addr; addr < max_addr; addr++) { |
| 277 | unsigned char op = code[addr]; |
| 278 | switch (op) { |
| 279 | case SETUP_LOOP: |
| 280 | case SETUP_EXCEPT: |
| 281 | case SETUP_FINALLY: |
Benjamin Peterson | e42fb30 | 2012-04-18 11:14:31 -0400 | [diff] [blame] | 282 | case SETUP_WITH: |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 283 | delta_iblock++; |
| 284 | break; |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 285 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 286 | case POP_BLOCK: |
| 287 | delta_iblock--; |
| 288 | break; |
| 289 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 290 | |
Victor Stinner | 640c35c | 2013-06-04 23:14:37 +0200 | [diff] [blame] | 291 | min_delta_iblock = Py_MIN(min_delta_iblock, delta_iblock); |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 292 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 293 | if (op >= HAVE_ARGUMENT) { |
| 294 | addr += 2; |
| 295 | } |
| 296 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 297 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 298 | /* Derive the absolute iblock values from the deltas. */ |
| 299 | min_iblock = f->f_iblock + min_delta_iblock; |
| 300 | if (new_lasti > f->f_lasti) { |
| 301 | /* Forwards jump. */ |
| 302 | new_iblock = f->f_iblock + delta_iblock; |
| 303 | } |
| 304 | else { |
| 305 | /* Backwards jump. */ |
| 306 | new_iblock = f->f_iblock - delta_iblock; |
| 307 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 308 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 309 | /* Are we jumping into a block? */ |
| 310 | if (new_iblock > min_iblock) { |
| 311 | PyErr_SetString(PyExc_ValueError, |
| 312 | "can't jump into the middle of a block"); |
| 313 | return -1; |
| 314 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 315 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 316 | /* Pop any blocks that we're jumping out of. */ |
| 317 | while (f->f_iblock > new_iblock) { |
| 318 | PyTryBlock *b = &f->f_blockstack[--f->f_iblock]; |
| 319 | while ((f->f_stacktop - f->f_valuestack) > b->b_level) { |
| 320 | PyObject *v = (*--f->f_stacktop); |
| 321 | Py_DECREF(v); |
| 322 | } |
| 323 | } |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 324 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 325 | /* Finally set the new f_lineno and f_lasti and return OK. */ |
| 326 | f->f_lineno = new_lineno; |
| 327 | f->f_lasti = new_lasti; |
| 328 | return 0; |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Michael W. Hudson | 02ff6a9 | 2002-09-11 15:36:32 +0000 | [diff] [blame] | 331 | static PyObject * |
| 332 | frame_gettrace(PyFrameObject *f, void *closure) |
| 333 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 334 | PyObject* trace = f->f_trace; |
Michael W. Hudson | 02ff6a9 | 2002-09-11 15:36:32 +0000 | [diff] [blame] | 335 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 336 | if (trace == NULL) |
| 337 | trace = Py_None; |
Michael W. Hudson | 02ff6a9 | 2002-09-11 15:36:32 +0000 | [diff] [blame] | 338 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 339 | Py_INCREF(trace); |
Michael W. Hudson | 02ff6a9 | 2002-09-11 15:36:32 +0000 | [diff] [blame] | 340 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 341 | return trace; |
Michael W. Hudson | 02ff6a9 | 2002-09-11 15:36:32 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static int |
| 345 | frame_settrace(PyFrameObject *f, PyObject* v, void *closure) |
| 346 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 347 | PyObject* old_value; |
Alexandre Vassalotti | 7b82b40 | 2009-07-21 04:30:03 +0000 | [diff] [blame] | 348 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 349 | /* We rely on f_lineno being accurate when f_trace is set. */ |
| 350 | f->f_lineno = PyFrame_GetLineNumber(f); |
Michael W. Hudson | 02ff6a9 | 2002-09-11 15:36:32 +0000 | [diff] [blame] | 351 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 352 | old_value = f->f_trace; |
| 353 | Py_XINCREF(v); |
| 354 | f->f_trace = v; |
| 355 | Py_XDECREF(old_value); |
Michael W. Hudson | 02ff6a9 | 2002-09-11 15:36:32 +0000 | [diff] [blame] | 356 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 357 | return 0; |
Michael W. Hudson | 02ff6a9 | 2002-09-11 15:36:32 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 360 | |
Guido van Rossum | 32d34c8 | 2001-09-20 21:45:26 +0000 | [diff] [blame] | 361 | static PyGetSetDef frame_getsetlist[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 362 | {"f_locals", (getter)frame_getlocals, NULL, NULL}, |
| 363 | {"f_lineno", (getter)frame_getlineno, |
| 364 | (setter)frame_setlineno, NULL}, |
| 365 | {"f_trace", (getter)frame_gettrace, (setter)frame_settrace, NULL}, |
| 366 | {0} |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 367 | }; |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 368 | |
Guido van Rossum | a9e7dc1 | 1992-10-18 18:53:57 +0000 | [diff] [blame] | 369 | /* Stack frames are allocated and deallocated at a considerable rate. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 370 | In an attempt to improve the speed of function calls, we: |
| 371 | |
| 372 | 1. Hold a single "zombie" frame on each code object. This retains |
| 373 | the allocated and initialised frame object from an invocation of |
| 374 | the code object. The zombie is reanimated the next time we need a |
| 375 | frame object for that code object. Doing this saves the malloc/ |
| 376 | realloc required when using a free_list frame that isn't the |
| 377 | correct size. It also saves some field initialisation. |
| 378 | |
| 379 | In zombie mode, no field of PyFrameObject holds a reference, but |
| 380 | the following fields are still valid: |
| 381 | |
| 382 | * ob_type, ob_size, f_code, f_valuestack; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 383 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 384 | * f_locals, f_trace, |
| 385 | f_exc_type, f_exc_value, f_exc_traceback are NULL; |
| 386 | |
| 387 | * f_localsplus does not require re-allocation and |
| 388 | the local variables in f_localsplus are NULL. |
| 389 | |
| 390 | 2. We also maintain a separate free list of stack frames (just like |
Mark Dickinson | d19052c | 2010-06-27 18:19:09 +0000 | [diff] [blame] | 391 | floats are allocated in a special way -- see floatobject.c). When |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 392 | a stack frame is on the free list, only the following members have |
| 393 | a meaning: |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 394 | ob_type == &Frametype |
| 395 | f_back next item on free list, or NULL |
| 396 | f_stacksize size of value stack |
| 397 | ob_size size of localsplus |
Guido van Rossum | a9e7dc1 | 1992-10-18 18:53:57 +0000 | [diff] [blame] | 398 | Note that the value and block stacks are preserved -- this can save |
| 399 | another malloc() call or two (and two free() calls as well!). |
| 400 | Also note that, unlike for integers, each frame object is a |
| 401 | malloc'ed object in its own right -- it is only the actual calls to |
| 402 | malloc() that we are trying to save here, not the administration. |
| 403 | After all, while a typical program may make millions of calls, a |
| 404 | call depth of more than 20 or 30 is probably already exceptional |
| 405 | unless the program contains run-away recursion. I hope. |
Tim Peters | b7ba743 | 2002-04-13 05:21:47 +0000 | [diff] [blame] | 406 | |
Christian Heimes | 2202f87 | 2008-02-06 14:31:34 +0000 | [diff] [blame] | 407 | Later, PyFrame_MAXFREELIST was added to bound the # of frames saved on |
Tim Peters | b7ba743 | 2002-04-13 05:21:47 +0000 | [diff] [blame] | 408 | free_list. Else programs creating lots of cyclic trash involving |
| 409 | frames could provoke free_list into growing without bound. |
Guido van Rossum | a9e7dc1 | 1992-10-18 18:53:57 +0000 | [diff] [blame] | 410 | */ |
| 411 | |
Guido van Rossum | 1875247 | 1997-04-29 14:49:28 +0000 | [diff] [blame] | 412 | static PyFrameObject *free_list = NULL; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 413 | static int numfree = 0; /* number of frames currently in free_list */ |
Christian Heimes | 2202f87 | 2008-02-06 14:31:34 +0000 | [diff] [blame] | 414 | /* max value for numfree */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 415 | #define PyFrame_MAXFREELIST 200 |
Guido van Rossum | a9e7dc1 | 1992-10-18 18:53:57 +0000 | [diff] [blame] | 416 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 417 | static void |
Fred Drake | 1b190b4 | 2000-07-09 05:40:56 +0000 | [diff] [blame] | 418 | frame_dealloc(PyFrameObject *f) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 419 | { |
Antoine Pitrou | 9396356 | 2013-05-14 20:37:52 +0200 | [diff] [blame] | 420 | PyObject **p, **valuestack; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 421 | PyCodeObject *co; |
Guido van Rossum | 7582bfb | 1997-02-14 16:27:29 +0000 | [diff] [blame] | 422 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 423 | PyObject_GC_UnTrack(f); |
| 424 | Py_TRASHCAN_SAFE_BEGIN(f) |
Antoine Pitrou | 9396356 | 2013-05-14 20:37:52 +0200 | [diff] [blame] | 425 | /* Kill all local variables */ |
| 426 | valuestack = f->f_valuestack; |
| 427 | for (p = f->f_localsplus; p < valuestack; p++) |
| 428 | Py_CLEAR(*p); |
| 429 | |
| 430 | /* Free stack */ |
| 431 | if (f->f_stacktop != NULL) { |
| 432 | for (p = valuestack; p < f->f_stacktop; p++) |
| 433 | Py_XDECREF(*p); |
| 434 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 435 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 436 | Py_XDECREF(f->f_back); |
| 437 | Py_DECREF(f->f_builtins); |
| 438 | Py_DECREF(f->f_globals); |
| 439 | Py_CLEAR(f->f_locals); |
Antoine Pitrou | 9396356 | 2013-05-14 20:37:52 +0200 | [diff] [blame] | 440 | Py_CLEAR(f->f_trace); |
| 441 | Py_CLEAR(f->f_exc_type); |
| 442 | Py_CLEAR(f->f_exc_value); |
| 443 | Py_CLEAR(f->f_exc_traceback); |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 444 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 445 | co = f->f_code; |
| 446 | if (co->co_zombieframe == NULL) |
| 447 | co->co_zombieframe = f; |
| 448 | else if (numfree < PyFrame_MAXFREELIST) { |
| 449 | ++numfree; |
| 450 | f->f_back = free_list; |
| 451 | free_list = f; |
| 452 | } |
| 453 | else |
| 454 | PyObject_GC_Del(f); |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 455 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 456 | Py_DECREF(co); |
| 457 | Py_TRASHCAN_SAFE_END(f) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 460 | static int |
| 461 | frame_traverse(PyFrameObject *f, visitproc visit, void *arg) |
| 462 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 463 | PyObject **fastlocals, **p; |
Victor Stinner | 7a6d7cf | 2012-10-31 00:37:41 +0100 | [diff] [blame] | 464 | Py_ssize_t i, slots; |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 465 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 466 | Py_VISIT(f->f_back); |
| 467 | Py_VISIT(f->f_code); |
| 468 | Py_VISIT(f->f_builtins); |
| 469 | Py_VISIT(f->f_globals); |
| 470 | Py_VISIT(f->f_locals); |
| 471 | Py_VISIT(f->f_trace); |
| 472 | Py_VISIT(f->f_exc_type); |
| 473 | Py_VISIT(f->f_exc_value); |
| 474 | Py_VISIT(f->f_exc_traceback); |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 475 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 476 | /* locals */ |
| 477 | slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + PyTuple_GET_SIZE(f->f_code->co_freevars); |
| 478 | fastlocals = f->f_localsplus; |
| 479 | for (i = slots; --i >= 0; ++fastlocals) |
| 480 | Py_VISIT(*fastlocals); |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 481 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 482 | /* stack */ |
| 483 | if (f->f_stacktop != NULL) { |
| 484 | for (p = f->f_valuestack; p < f->f_stacktop; p++) |
| 485 | Py_VISIT(*p); |
| 486 | } |
| 487 | return 0; |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | static void |
Antoine Pitrou | 58720d6 | 2013-08-05 23:26:40 +0200 | [diff] [blame] | 491 | frame_tp_clear(PyFrameObject *f) |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 492 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 493 | PyObject **fastlocals, **p, **oldtop; |
Victor Stinner | 7a6d7cf | 2012-10-31 00:37:41 +0100 | [diff] [blame] | 494 | Py_ssize_t i, slots; |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 495 | |
Antoine Pitrou | 9396356 | 2013-05-14 20:37:52 +0200 | [diff] [blame] | 496 | /* Before anything else, make sure that this frame is clearly marked |
| 497 | * as being defunct! Else, e.g., a generator reachable from this |
| 498 | * frame may also point to this frame, believe itself to still be |
| 499 | * active, and try cleaning up this frame again. |
| 500 | */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 501 | oldtop = f->f_stacktop; |
| 502 | f->f_stacktop = NULL; |
Antoine Pitrou | 58720d6 | 2013-08-05 23:26:40 +0200 | [diff] [blame] | 503 | f->f_executing = 0; |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 504 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 505 | Py_CLEAR(f->f_exc_type); |
| 506 | Py_CLEAR(f->f_exc_value); |
| 507 | Py_CLEAR(f->f_exc_traceback); |
| 508 | Py_CLEAR(f->f_trace); |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 509 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 510 | /* locals */ |
| 511 | slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + PyTuple_GET_SIZE(f->f_code->co_freevars); |
| 512 | fastlocals = f->f_localsplus; |
| 513 | for (i = slots; --i >= 0; ++fastlocals) |
| 514 | Py_CLEAR(*fastlocals); |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 515 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 516 | /* stack */ |
| 517 | if (oldtop != NULL) { |
| 518 | for (p = f->f_valuestack; p < oldtop; p++) |
| 519 | Py_CLEAR(*p); |
| 520 | } |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Robert Schuppenies | fbe94c5 | 2008-07-14 10:13:31 +0000 | [diff] [blame] | 523 | static PyObject * |
Antoine Pitrou | 58720d6 | 2013-08-05 23:26:40 +0200 | [diff] [blame] | 524 | frame_clear(PyFrameObject *f) |
| 525 | { |
| 526 | if (f->f_executing) { |
| 527 | PyErr_SetString(PyExc_RuntimeError, |
| 528 | "cannot clear an executing frame"); |
| 529 | return NULL; |
| 530 | } |
| 531 | if (f->f_gen) { |
| 532 | _PyGen_Finalize(f->f_gen); |
| 533 | assert(f->f_gen == NULL); |
| 534 | } |
| 535 | frame_tp_clear(f); |
| 536 | Py_RETURN_NONE; |
| 537 | } |
| 538 | |
| 539 | PyDoc_STRVAR(clear__doc__, |
| 540 | "F.clear(): clear most references held by the frame"); |
| 541 | |
| 542 | static PyObject * |
Robert Schuppenies | fbe94c5 | 2008-07-14 10:13:31 +0000 | [diff] [blame] | 543 | frame_sizeof(PyFrameObject *f) |
| 544 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 545 | Py_ssize_t res, extras, ncells, nfrees; |
Robert Schuppenies | fbe94c5 | 2008-07-14 10:13:31 +0000 | [diff] [blame] | 546 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 547 | ncells = PyTuple_GET_SIZE(f->f_code->co_cellvars); |
| 548 | nfrees = PyTuple_GET_SIZE(f->f_code->co_freevars); |
| 549 | extras = f->f_code->co_stacksize + f->f_code->co_nlocals + |
| 550 | ncells + nfrees; |
| 551 | /* subtract one as it is already included in PyFrameObject */ |
| 552 | res = sizeof(PyFrameObject) + (extras-1) * sizeof(PyObject *); |
Robert Schuppenies | fbe94c5 | 2008-07-14 10:13:31 +0000 | [diff] [blame] | 553 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 554 | return PyLong_FromSsize_t(res); |
Robert Schuppenies | fbe94c5 | 2008-07-14 10:13:31 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | PyDoc_STRVAR(sizeof__doc__, |
| 558 | "F.__sizeof__() -> size of F in memory, in bytes"); |
| 559 | |
| 560 | static PyMethodDef frame_methods[] = { |
Antoine Pitrou | 58720d6 | 2013-08-05 23:26:40 +0200 | [diff] [blame] | 561 | {"clear", (PyCFunction)frame_clear, METH_NOARGS, |
| 562 | clear__doc__}, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 563 | {"__sizeof__", (PyCFunction)frame_sizeof, METH_NOARGS, |
| 564 | sizeof__doc__}, |
| 565 | {NULL, NULL} /* sentinel */ |
Robert Schuppenies | fbe94c5 | 2008-07-14 10:13:31 +0000 | [diff] [blame] | 566 | }; |
Neil Schemenauer | 19cd292 | 2001-07-12 13:27:11 +0000 | [diff] [blame] | 567 | |
Guido van Rossum | 1875247 | 1997-04-29 14:49:28 +0000 | [diff] [blame] | 568 | PyTypeObject PyFrame_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 569 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 570 | "frame", |
| 571 | sizeof(PyFrameObject), |
| 572 | sizeof(PyObject *), |
| 573 | (destructor)frame_dealloc, /* tp_dealloc */ |
| 574 | 0, /* tp_print */ |
| 575 | 0, /* tp_getattr */ |
| 576 | 0, /* tp_setattr */ |
| 577 | 0, /* tp_reserved */ |
| 578 | 0, /* tp_repr */ |
| 579 | 0, /* tp_as_number */ |
| 580 | 0, /* tp_as_sequence */ |
| 581 | 0, /* tp_as_mapping */ |
| 582 | 0, /* tp_hash */ |
| 583 | 0, /* tp_call */ |
| 584 | 0, /* tp_str */ |
| 585 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 586 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 587 | 0, /* tp_as_buffer */ |
| 588 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
| 589 | 0, /* tp_doc */ |
| 590 | (traverseproc)frame_traverse, /* tp_traverse */ |
Antoine Pitrou | 58720d6 | 2013-08-05 23:26:40 +0200 | [diff] [blame] | 591 | (inquiry)frame_tp_clear, /* tp_clear */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 592 | 0, /* tp_richcompare */ |
| 593 | 0, /* tp_weaklistoffset */ |
| 594 | 0, /* tp_iter */ |
| 595 | 0, /* tp_iternext */ |
| 596 | frame_methods, /* tp_methods */ |
| 597 | frame_memberlist, /* tp_members */ |
| 598 | frame_getsetlist, /* tp_getset */ |
| 599 | 0, /* tp_base */ |
| 600 | 0, /* tp_dict */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 601 | }; |
| 602 | |
Neal Norwitz | c91ed40 | 2002-12-30 22:29:22 +0000 | [diff] [blame] | 603 | static PyObject *builtin_object; |
| 604 | |
Neal Norwitz | b2501f4 | 2002-12-31 03:42:13 +0000 | [diff] [blame] | 605 | int _PyFrame_Init() |
Neal Norwitz | c91ed40 | 2002-12-30 22:29:22 +0000 | [diff] [blame] | 606 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 607 | builtin_object = PyUnicode_InternFromString("__builtins__"); |
| 608 | if (builtin_object == NULL) |
| 609 | return 0; |
| 610 | return 1; |
Neal Norwitz | c91ed40 | 2002-12-30 22:29:22 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Guido van Rossum | 1875247 | 1997-04-29 14:49:28 +0000 | [diff] [blame] | 613 | PyFrameObject * |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 614 | PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 615 | PyObject *locals) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 616 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 617 | PyFrameObject *back = tstate->frame; |
| 618 | PyFrameObject *f; |
| 619 | PyObject *builtins; |
| 620 | Py_ssize_t i; |
Guido van Rossum | f3e85a0 | 1997-01-20 04:20:52 +0000 | [diff] [blame] | 621 | |
Michael W. Hudson | 69734a5 | 2002-08-19 16:54:08 +0000 | [diff] [blame] | 622 | #ifdef Py_DEBUG |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 623 | if (code == NULL || globals == NULL || !PyDict_Check(globals) || |
| 624 | (locals != NULL && !PyMapping_Check(locals))) { |
| 625 | PyErr_BadInternalCall(); |
| 626 | return NULL; |
| 627 | } |
Michael W. Hudson | 69734a5 | 2002-08-19 16:54:08 +0000 | [diff] [blame] | 628 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 629 | if (back == NULL || back->f_globals != globals) { |
| 630 | builtins = PyDict_GetItem(globals, builtin_object); |
| 631 | if (builtins) { |
| 632 | if (PyModule_Check(builtins)) { |
| 633 | builtins = PyModule_GetDict(builtins); |
Victor Stinner | b0b2242 | 2012-04-19 00:57:45 +0200 | [diff] [blame] | 634 | assert(builtins != NULL); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 635 | } |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 636 | } |
| 637 | if (builtins == NULL) { |
| 638 | /* No builtins! Make up a minimal one |
| 639 | Give them 'None', at least. */ |
| 640 | builtins = PyDict_New(); |
| 641 | if (builtins == NULL || |
| 642 | PyDict_SetItemString( |
| 643 | builtins, "None", Py_None) < 0) |
| 644 | return NULL; |
| 645 | } |
| 646 | else |
| 647 | Py_INCREF(builtins); |
Jeremy Hylton | bd5cbf8 | 2003-02-05 22:39:29 +0000 | [diff] [blame] | 648 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 649 | } |
| 650 | else { |
| 651 | /* If we share the globals, we share the builtins. |
| 652 | Save a lookup and a call. */ |
| 653 | builtins = back->f_builtins; |
Victor Stinner | b0b2242 | 2012-04-19 00:57:45 +0200 | [diff] [blame] | 654 | assert(builtins != NULL); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 655 | Py_INCREF(builtins); |
| 656 | } |
| 657 | if (code->co_zombieframe != NULL) { |
| 658 | f = code->co_zombieframe; |
| 659 | code->co_zombieframe = NULL; |
| 660 | _Py_NewReference((PyObject *)f); |
| 661 | assert(f->f_code == code); |
| 662 | } |
| 663 | else { |
| 664 | Py_ssize_t extras, ncells, nfrees; |
| 665 | ncells = PyTuple_GET_SIZE(code->co_cellvars); |
| 666 | nfrees = PyTuple_GET_SIZE(code->co_freevars); |
| 667 | extras = code->co_stacksize + code->co_nlocals + ncells + |
| 668 | nfrees; |
| 669 | if (free_list == NULL) { |
| 670 | f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, |
| 671 | extras); |
| 672 | if (f == NULL) { |
| 673 | Py_DECREF(builtins); |
| 674 | return NULL; |
| 675 | } |
| 676 | } |
| 677 | else { |
| 678 | assert(numfree > 0); |
| 679 | --numfree; |
| 680 | f = free_list; |
| 681 | free_list = free_list->f_back; |
| 682 | if (Py_SIZE(f) < extras) { |
Kristjan Valur Jonsson | 85634d7 | 2012-05-31 09:37:31 +0000 | [diff] [blame] | 683 | PyFrameObject *new_f = PyObject_GC_Resize(PyFrameObject, f, extras); |
| 684 | if (new_f == NULL) { |
| 685 | PyObject_GC_Del(f); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 686 | Py_DECREF(builtins); |
| 687 | return NULL; |
| 688 | } |
Kristjan Valur Jonsson | 85634d7 | 2012-05-31 09:37:31 +0000 | [diff] [blame] | 689 | f = new_f; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 690 | } |
| 691 | _Py_NewReference((PyObject *)f); |
| 692 | } |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 693 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 694 | f->f_code = code; |
| 695 | extras = code->co_nlocals + ncells + nfrees; |
| 696 | f->f_valuestack = f->f_localsplus + extras; |
| 697 | for (i=0; i<extras; i++) |
| 698 | f->f_localsplus[i] = NULL; |
| 699 | f->f_locals = NULL; |
| 700 | f->f_trace = NULL; |
| 701 | f->f_exc_type = f->f_exc_value = f->f_exc_traceback = NULL; |
| 702 | } |
| 703 | f->f_stacktop = f->f_valuestack; |
| 704 | f->f_builtins = builtins; |
| 705 | Py_XINCREF(back); |
| 706 | f->f_back = back; |
| 707 | Py_INCREF(code); |
| 708 | Py_INCREF(globals); |
| 709 | f->f_globals = globals; |
| 710 | /* Most functions have CO_NEWLOCALS and CO_OPTIMIZED set. */ |
| 711 | if ((code->co_flags & (CO_NEWLOCALS | CO_OPTIMIZED)) == |
| 712 | (CO_NEWLOCALS | CO_OPTIMIZED)) |
| 713 | ; /* f_locals = NULL; will be set by PyFrame_FastToLocals() */ |
| 714 | else if (code->co_flags & CO_NEWLOCALS) { |
| 715 | locals = PyDict_New(); |
| 716 | if (locals == NULL) { |
| 717 | Py_DECREF(f); |
| 718 | return NULL; |
| 719 | } |
| 720 | f->f_locals = locals; |
| 721 | } |
| 722 | else { |
| 723 | if (locals == NULL) |
| 724 | locals = globals; |
| 725 | Py_INCREF(locals); |
| 726 | f->f_locals = locals; |
| 727 | } |
| 728 | f->f_tstate = tstate; |
Guido van Rossum | f3e85a0 | 1997-01-20 04:20:52 +0000 | [diff] [blame] | 729 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 730 | f->f_lasti = -1; |
| 731 | f->f_lineno = code->co_firstlineno; |
| 732 | f->f_iblock = 0; |
Antoine Pitrou | 58720d6 | 2013-08-05 23:26:40 +0200 | [diff] [blame] | 733 | f->f_executing = 0; |
| 734 | f->f_gen = NULL; |
Guido van Rossum | f3e85a0 | 1997-01-20 04:20:52 +0000 | [diff] [blame] | 735 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 736 | _PyObject_GC_TRACK(f); |
| 737 | return f; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 740 | /* Block management */ |
| 741 | |
| 742 | void |
Fred Drake | 1b190b4 | 2000-07-09 05:40:56 +0000 | [diff] [blame] | 743 | PyFrame_BlockSetup(PyFrameObject *f, int type, int handler, int level) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 744 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 745 | PyTryBlock *b; |
| 746 | if (f->f_iblock >= CO_MAXBLOCKS) |
| 747 | Py_FatalError("XXX block stack overflow"); |
| 748 | b = &f->f_blockstack[f->f_iblock++]; |
| 749 | b->b_type = type; |
| 750 | b->b_level = level; |
| 751 | b->b_handler = handler; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Guido van Rossum | 1875247 | 1997-04-29 14:49:28 +0000 | [diff] [blame] | 754 | PyTryBlock * |
Fred Drake | 1b190b4 | 2000-07-09 05:40:56 +0000 | [diff] [blame] | 755 | PyFrame_BlockPop(PyFrameObject *f) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 756 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 757 | PyTryBlock *b; |
| 758 | if (f->f_iblock <= 0) |
| 759 | Py_FatalError("XXX block stack underflow"); |
| 760 | b = &f->f_blockstack[--f->f_iblock]; |
| 761 | return b; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 762 | } |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 763 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 764 | /* Convert between "fast" version of locals and dictionary version. |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 765 | |
| 766 | map and values are input arguments. map is a tuple of strings. |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 767 | values is an array of PyObject*. At index i, map[i] is the name of |
| 768 | the variable with value values[i]. The function copies the first |
| 769 | nmap variable from map/values into dict. If values[i] is NULL, |
| 770 | the variable is deleted from dict. |
| 771 | |
| 772 | If deref is true, then the values being copied are cell variables |
| 773 | and the value is extracted from the cell variable before being put |
| 774 | in dict. |
| 775 | |
| 776 | Exceptions raised while modifying the dict are silently ignored, |
| 777 | because there is no good way to report them. |
| 778 | */ |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 779 | |
Guido van Rossum | f68d8e5 | 2001-04-14 17:55:09 +0000 | [diff] [blame] | 780 | static void |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 781 | map_to_dict(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 782 | int deref) |
Jeremy Hylton | 220ae7c | 2001-03-21 16:43:47 +0000 | [diff] [blame] | 783 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 784 | Py_ssize_t j; |
| 785 | assert(PyTuple_Check(map)); |
| 786 | assert(PyDict_Check(dict)); |
| 787 | assert(PyTuple_Size(map) >= nmap); |
| 788 | for (j = nmap; --j >= 0; ) { |
| 789 | PyObject *key = PyTuple_GET_ITEM(map, j); |
| 790 | PyObject *value = values[j]; |
| 791 | assert(PyUnicode_Check(key)); |
| 792 | if (deref) { |
| 793 | assert(PyCell_Check(value)); |
| 794 | value = PyCell_GET(value); |
| 795 | } |
| 796 | if (value == NULL) { |
| 797 | if (PyObject_DelItem(dict, key) != 0) |
| 798 | PyErr_Clear(); |
| 799 | } |
| 800 | else { |
| 801 | if (PyObject_SetItem(dict, key, value) != 0) |
| 802 | PyErr_Clear(); |
| 803 | } |
| 804 | } |
Jeremy Hylton | 220ae7c | 2001-03-21 16:43:47 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 807 | /* Copy values from the "locals" dict into the fast locals. |
| 808 | |
| 809 | dict is an input argument containing string keys representing |
| 810 | variables names and arbitrary PyObject* as values. |
| 811 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 812 | map and values are input arguments. map is a tuple of strings. |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 813 | values is an array of PyObject*. At index i, map[i] is the name of |
| 814 | the variable with value values[i]. The function copies the first |
| 815 | nmap variable from map/values into dict. If values[i] is NULL, |
| 816 | the variable is deleted from dict. |
| 817 | |
| 818 | If deref is true, then the values being copied are cell variables |
| 819 | and the value is extracted from the cell variable before being put |
| 820 | in dict. If clear is true, then variables in map but not in dict |
| 821 | are set to NULL in map; if clear is false, variables missing in |
| 822 | dict are ignored. |
| 823 | |
| 824 | Exceptions raised while modifying the dict are silently ignored, |
| 825 | because there is no good way to report them. |
| 826 | */ |
| 827 | |
Guido van Rossum | 6b356e7 | 2001-04-14 17:55:41 +0000 | [diff] [blame] | 828 | static void |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 829 | dict_to_map(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 830 | int deref, int clear) |
Jeremy Hylton | 220ae7c | 2001-03-21 16:43:47 +0000 | [diff] [blame] | 831 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 832 | Py_ssize_t j; |
| 833 | assert(PyTuple_Check(map)); |
| 834 | assert(PyDict_Check(dict)); |
| 835 | assert(PyTuple_Size(map) >= nmap); |
| 836 | for (j = nmap; --j >= 0; ) { |
| 837 | PyObject *key = PyTuple_GET_ITEM(map, j); |
| 838 | PyObject *value = PyObject_GetItem(dict, key); |
| 839 | assert(PyUnicode_Check(key)); |
| 840 | /* We only care about NULLs if clear is true. */ |
| 841 | if (value == NULL) { |
| 842 | PyErr_Clear(); |
| 843 | if (!clear) |
| 844 | continue; |
| 845 | } |
| 846 | if (deref) { |
| 847 | assert(PyCell_Check(values[j])); |
| 848 | if (PyCell_GET(values[j]) != value) { |
| 849 | if (PyCell_Set(values[j], value) < 0) |
| 850 | PyErr_Clear(); |
| 851 | } |
| 852 | } else if (values[j] != value) { |
| 853 | Py_XINCREF(value); |
| 854 | Py_XDECREF(values[j]); |
| 855 | values[j] = value; |
| 856 | } |
| 857 | Py_XDECREF(value); |
| 858 | } |
Jeremy Hylton | 220ae7c | 2001-03-21 16:43:47 +0000 | [diff] [blame] | 859 | } |
Jeremy Hylton | 2b724da | 2001-01-29 22:51:52 +0000 | [diff] [blame] | 860 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 861 | void |
Fred Drake | 1b190b4 | 2000-07-09 05:40:56 +0000 | [diff] [blame] | 862 | PyFrame_FastToLocals(PyFrameObject *f) |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 863 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 864 | /* Merge fast locals into f->f_locals */ |
| 865 | PyObject *locals, *map; |
| 866 | PyObject **fast; |
| 867 | PyObject *error_type, *error_value, *error_traceback; |
| 868 | PyCodeObject *co; |
| 869 | Py_ssize_t j; |
Victor Stinner | 7a6d7cf | 2012-10-31 00:37:41 +0100 | [diff] [blame] | 870 | Py_ssize_t ncells, nfreevars; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 871 | if (f == NULL) |
| 872 | return; |
| 873 | locals = f->f_locals; |
| 874 | if (locals == NULL) { |
| 875 | locals = f->f_locals = PyDict_New(); |
| 876 | if (locals == NULL) { |
| 877 | PyErr_Clear(); /* Can't report it :-( */ |
| 878 | return; |
| 879 | } |
| 880 | } |
| 881 | co = f->f_code; |
| 882 | map = co->co_varnames; |
| 883 | if (!PyTuple_Check(map)) |
| 884 | return; |
| 885 | PyErr_Fetch(&error_type, &error_value, &error_traceback); |
| 886 | fast = f->f_localsplus; |
| 887 | j = PyTuple_GET_SIZE(map); |
| 888 | if (j > co->co_nlocals) |
| 889 | j = co->co_nlocals; |
| 890 | if (co->co_nlocals) |
| 891 | map_to_dict(map, j, locals, fast, 0); |
| 892 | ncells = PyTuple_GET_SIZE(co->co_cellvars); |
| 893 | nfreevars = PyTuple_GET_SIZE(co->co_freevars); |
| 894 | if (ncells || nfreevars) { |
| 895 | map_to_dict(co->co_cellvars, ncells, |
| 896 | locals, fast + co->co_nlocals, 1); |
| 897 | /* If the namespace is unoptimized, then one of the |
| 898 | following cases applies: |
| 899 | 1. It does not contain free variables, because it |
| 900 | uses import * or is a top-level namespace. |
| 901 | 2. It is a class namespace. |
| 902 | We don't want to accidentally copy free variables |
| 903 | into the locals dict used by the class. |
| 904 | */ |
| 905 | if (co->co_flags & CO_OPTIMIZED) { |
| 906 | map_to_dict(co->co_freevars, nfreevars, |
| 907 | locals, fast + co->co_nlocals + ncells, 1); |
| 908 | } |
| 909 | } |
| 910 | PyErr_Restore(error_type, error_value, error_traceback); |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | void |
Fred Drake | 1b190b4 | 2000-07-09 05:40:56 +0000 | [diff] [blame] | 914 | PyFrame_LocalsToFast(PyFrameObject *f, int clear) |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 915 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 916 | /* Merge f->f_locals into fast locals */ |
| 917 | PyObject *locals, *map; |
| 918 | PyObject **fast; |
| 919 | PyObject *error_type, *error_value, *error_traceback; |
| 920 | PyCodeObject *co; |
| 921 | Py_ssize_t j; |
Victor Stinner | 7a6d7cf | 2012-10-31 00:37:41 +0100 | [diff] [blame] | 922 | Py_ssize_t ncells, nfreevars; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 923 | if (f == NULL) |
| 924 | return; |
| 925 | locals = f->f_locals; |
| 926 | co = f->f_code; |
| 927 | map = co->co_varnames; |
| 928 | if (locals == NULL) |
| 929 | return; |
| 930 | if (!PyTuple_Check(map)) |
| 931 | return; |
| 932 | PyErr_Fetch(&error_type, &error_value, &error_traceback); |
| 933 | fast = f->f_localsplus; |
| 934 | j = PyTuple_GET_SIZE(map); |
| 935 | if (j > co->co_nlocals) |
| 936 | j = co->co_nlocals; |
| 937 | if (co->co_nlocals) |
| 938 | dict_to_map(co->co_varnames, j, locals, fast, 0, clear); |
| 939 | ncells = PyTuple_GET_SIZE(co->co_cellvars); |
| 940 | nfreevars = PyTuple_GET_SIZE(co->co_freevars); |
| 941 | if (ncells || nfreevars) { |
| 942 | dict_to_map(co->co_cellvars, ncells, |
| 943 | locals, fast + co->co_nlocals, 1, clear); |
| 944 | /* Same test as in PyFrame_FastToLocals() above. */ |
| 945 | if (co->co_flags & CO_OPTIMIZED) { |
| 946 | dict_to_map(co->co_freevars, nfreevars, |
| 947 | locals, fast + co->co_nlocals + ncells, 1, |
| 948 | clear); |
| 949 | } |
| 950 | } |
| 951 | PyErr_Restore(error_type, error_value, error_traceback); |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 952 | } |
Guido van Rossum | 404b95d | 1997-08-05 02:09:46 +0000 | [diff] [blame] | 953 | |
| 954 | /* Clear out the free list */ |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 955 | int |
| 956 | PyFrame_ClearFreeList(void) |
Guido van Rossum | 404b95d | 1997-08-05 02:09:46 +0000 | [diff] [blame] | 957 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 958 | int freelist_size = numfree; |
| 959 | |
| 960 | while (free_list != NULL) { |
| 961 | PyFrameObject *f = free_list; |
| 962 | free_list = free_list->f_back; |
| 963 | PyObject_GC_Del(f); |
| 964 | --numfree; |
| 965 | } |
| 966 | assert(numfree == 0); |
| 967 | return freelist_size; |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | void |
| 971 | PyFrame_Fini(void) |
| 972 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 973 | (void)PyFrame_ClearFreeList(); |
| 974 | Py_XDECREF(builtin_object); |
| 975 | builtin_object = NULL; |
Guido van Rossum | 404b95d | 1997-08-05 02:09:46 +0000 | [diff] [blame] | 976 | } |
David Malcolm | 49526f4 | 2012-06-22 14:55:41 -0400 | [diff] [blame] | 977 | |
| 978 | /* Print summary info about the state of the optimized allocator */ |
| 979 | void |
| 980 | _PyFrame_DebugMallocStats(FILE *out) |
| 981 | { |
| 982 | _PyDebugAllocatorStats(out, |
| 983 | "free PyFrameObject", |
| 984 | numfree, sizeof(PyFrameObject)); |
| 985 | } |
| 986 | |