Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(90338)

Side by Side Diff: Objects/frameobject.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Frame object implementation */ 1 /* Frame object implementation */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 4
5 #include "code.h" 5 #include "code.h"
6 #include "frameobject.h" 6 #include "frameobject.h"
7 #include "opcode.h" 7 #include "opcode.h"
8 #include "structmember.h" 8 #include "structmember.h"
9 9
10 #undef MIN 10 #undef MIN
11 #undef MAX 11 #undef MAX
12 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 12 #define MIN(a, b) ((a) < (b) ? (a) : (b))
13 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 13 #define MAX(a, b) ((a) > (b) ? (a) : (b))
14 14
15 #define OFF(x) offsetof(PyFrameObject, x) 15 #define OFF(x) offsetof(PyFrameObject, x)
16 16
17 static PyMemberDef frame_memberlist[] = { 17 static PyMemberDef frame_memberlist[] = {
18 {"f_back", T_OBJECT, OFF(f_back), READONLY}, 18 {"f_back", T_OBJECT, OFF(f_back), READONLY},
19 {"f_code", T_OBJECT, OFF(f_code), READONLY}, 19 {"f_code", T_OBJECT, OFF(f_code), READONLY},
20 {"f_builtins", T_OBJECT, OFF(f_builtins),READONLY}, 20 {"f_builtins", T_OBJECT, OFF(f_builtins), READONLY},
21 {"f_globals", T_OBJECT, OFF(f_globals), READONLY}, 21 {"f_globals", T_OBJECT, OFF(f_globals), READONLY},
22 {"f_lasti", T_INT, OFF(f_lasti), READONLY}, 22 {"f_lasti", T_INT, OFF(f_lasti), READONLY},
23 {"f_yieldfrom", T_OBJECT, OFF(f_yieldfrom), READONLY},
23 {NULL} /* Sentinel */ 24 {NULL} /* Sentinel */
24 }; 25 };
25 26
26 static PyObject * 27 static PyObject *
27 frame_getlocals(PyFrameObject *f, void *closure) 28 frame_getlocals(PyFrameObject *f, void *closure)
28 { 29 {
29 PyFrame_FastToLocals(f); 30 PyFrame_FastToLocals(f);
30 Py_INCREF(f->f_locals); 31 Py_INCREF(f->f_locals);
31 return f->f_locals; 32 return f->f_locals;
32 } 33 }
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 } 438 }
438 439
439 Py_XDECREF(f->f_back); 440 Py_XDECREF(f->f_back);
440 Py_DECREF(f->f_builtins); 441 Py_DECREF(f->f_builtins);
441 Py_DECREF(f->f_globals); 442 Py_DECREF(f->f_globals);
442 Py_CLEAR(f->f_locals); 443 Py_CLEAR(f->f_locals);
443 Py_CLEAR(f->f_trace); 444 Py_CLEAR(f->f_trace);
444 Py_CLEAR(f->f_exc_type); 445 Py_CLEAR(f->f_exc_type);
445 Py_CLEAR(f->f_exc_value); 446 Py_CLEAR(f->f_exc_value);
446 Py_CLEAR(f->f_exc_traceback); 447 Py_CLEAR(f->f_exc_traceback);
448 Py_CLEAR(f->f_yieldfrom);
447 449
448 co = f->f_code; 450 co = f->f_code;
449 if (co->co_zombieframe == NULL) 451 if (co->co_zombieframe == NULL)
450 co->co_zombieframe = f; 452 co->co_zombieframe = f;
451 else if (numfree < PyFrame_MAXFREELIST) { 453 else if (numfree < PyFrame_MAXFREELIST) {
452 ++numfree; 454 ++numfree;
453 f->f_back = free_list; 455 f->f_back = free_list;
454 free_list = f; 456 free_list = f;
455 } 457 }
456 else 458 else
(...skipping 11 matching lines...) Expand all
468 470
469 Py_VISIT(f->f_back); 471 Py_VISIT(f->f_back);
470 Py_VISIT(f->f_code); 472 Py_VISIT(f->f_code);
471 Py_VISIT(f->f_builtins); 473 Py_VISIT(f->f_builtins);
472 Py_VISIT(f->f_globals); 474 Py_VISIT(f->f_globals);
473 Py_VISIT(f->f_locals); 475 Py_VISIT(f->f_locals);
474 Py_VISIT(f->f_trace); 476 Py_VISIT(f->f_trace);
475 Py_VISIT(f->f_exc_type); 477 Py_VISIT(f->f_exc_type);
476 Py_VISIT(f->f_exc_value); 478 Py_VISIT(f->f_exc_value);
477 Py_VISIT(f->f_exc_traceback); 479 Py_VISIT(f->f_exc_traceback);
480 Py_VISIT(f->f_yieldfrom);
478 481
479 /* locals */ 482 /* locals */
480 slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + P yTuple_GET_SIZE(f->f_code->co_freevars); 483 slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + P yTuple_GET_SIZE(f->f_code->co_freevars);
481 fastlocals = f->f_localsplus; 484 fastlocals = f->f_localsplus;
482 for (i = slots; --i >= 0; ++fastlocals) 485 for (i = slots; --i >= 0; ++fastlocals)
483 Py_VISIT(*fastlocals); 486 Py_VISIT(*fastlocals);
484 487
485 /* stack */ 488 /* stack */
486 if (f->f_stacktop != NULL) { 489 if (f->f_stacktop != NULL) {
487 for (p = f->f_valuestack; p < f->f_stacktop; p++) 490 for (p = f->f_valuestack; p < f->f_stacktop; p++)
(...skipping 13 matching lines...) Expand all
501 * frame may also point to this frame, believe itself to still be 504 * frame may also point to this frame, believe itself to still be
502 * active, and try cleaning up this frame again. 505 * active, and try cleaning up this frame again.
503 */ 506 */
504 oldtop = f->f_stacktop; 507 oldtop = f->f_stacktop;
505 f->f_stacktop = NULL; 508 f->f_stacktop = NULL;
506 509
507 Py_CLEAR(f->f_exc_type); 510 Py_CLEAR(f->f_exc_type);
508 Py_CLEAR(f->f_exc_value); 511 Py_CLEAR(f->f_exc_value);
509 Py_CLEAR(f->f_exc_traceback); 512 Py_CLEAR(f->f_exc_traceback);
510 Py_CLEAR(f->f_trace); 513 Py_CLEAR(f->f_trace);
514 Py_CLEAR(f->f_yieldfrom);
511 515
512 /* locals */ 516 /* locals */
513 slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + P yTuple_GET_SIZE(f->f_code->co_freevars); 517 slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + P yTuple_GET_SIZE(f->f_code->co_freevars);
514 fastlocals = f->f_localsplus; 518 fastlocals = f->f_localsplus;
515 for (i = slots; --i >= 0; ++fastlocals) 519 for (i = slots; --i >= 0; ++fastlocals)
516 Py_CLEAR(*fastlocals); 520 Py_CLEAR(*fastlocals);
517 521
518 /* stack */ 522 /* stack */
519 if (oldtop != NULL) { 523 if (oldtop != NULL) {
520 for (p = f->f_valuestack; p < oldtop; p++) 524 for (p = f->f_valuestack; p < oldtop; p++)
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 if (locals == NULL) 708 if (locals == NULL)
705 locals = globals; 709 locals = globals;
706 Py_INCREF(locals); 710 Py_INCREF(locals);
707 f->f_locals = locals; 711 f->f_locals = locals;
708 } 712 }
709 f->f_tstate = tstate; 713 f->f_tstate = tstate;
710 714
711 f->f_lasti = -1; 715 f->f_lasti = -1;
712 f->f_lineno = code->co_firstlineno; 716 f->f_lineno = code->co_firstlineno;
713 f->f_iblock = 0; 717 f->f_iblock = 0;
718 f->f_yieldfrom = NULL;
714 719
715 _PyObject_GC_TRACK(f); 720 _PyObject_GC_TRACK(f);
716 return f; 721 return f;
717 } 722 }
718 723
719 /* Block management */ 724 /* Block management */
720 725
721 void 726 void
722 PyFrame_BlockSetup(PyFrameObject *f, int type, int handler, int level) 727 PyFrame_BlockSetup(PyFrameObject *f, int type, int handler, int level)
723 { 728 {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 return freelist_size; 951 return freelist_size;
947 } 952 }
948 953
949 void 954 void
950 PyFrame_Fini(void) 955 PyFrame_Fini(void)
951 { 956 {
952 (void)PyFrame_ClearFreeList(); 957 (void)PyFrame_ClearFreeList();
953 Py_XDECREF(builtin_object); 958 Py_XDECREF(builtin_object);
954 builtin_object = NULL; 959 builtin_object = NULL;
955 } 960 }
OLDNEW
« Objects/exceptions.c ('K') | « Objects/exceptions.c ('k') | Objects/genobject.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+