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

Delta Between Two Patch Sets: Python/compile.c

Issue 23722: During metaclass.__init__, super() of the constructed class does not work
Left Patch Set: Created 3 years ago
Right Patch Set: Created 3 years 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:
Right: Side by side diff | Download
« Python/bltinmodule.c ('K') | « Python/bltinmodule.c ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /* 1 /*
2 * This file compiles an abstract syntax tree (AST) into Python bytecode. 2 * This file compiles an abstract syntax tree (AST) into Python bytecode.
3 * 3 *
4 * The primary entry point is PyAST_Compile(), which returns a 4 * The primary entry point is PyAST_Compile(), which returns a
5 * PyCodeObject. The compiler makes several passes to build the code 5 * PyCodeObject. The compiler makes several passes to build the code
6 * object: 6 * object:
7 * 1. Checks for future statements. See future.c 7 * 1. Checks for future statements. See future.c
8 * 2. Builds a symbol table. See symtable.c. 8 * 2. Builds a symbol table. See symtable.c.
9 * 3. Generate code for basic blocks. See compiler_mod() in this file. 9 * 3. Generate code for basic blocks. See compiler_mod() in this file.
10 * 4. Assemble the basic blocks into final code. See assemble() in 10 * 4. Assemble the basic blocks into final code. See assemble() in
(...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 Py_XDECREF(str); 1960 Py_XDECREF(str);
1961 compiler_exit_scope(c); 1961 compiler_exit_scope(c);
1962 return 0; 1962 return 0;
1963 } 1963 }
1964 Py_DECREF(str); 1964 Py_DECREF(str);
1965 /* compile the body proper */ 1965 /* compile the body proper */
1966 if (!compiler_body(c, s->v.ClassDef.body)) { 1966 if (!compiler_body(c, s->v.ClassDef.body)) {
1967 compiler_exit_scope(c); 1967 compiler_exit_scope(c);
1968 return 0; 1968 return 0;
1969 } 1969 }
1970 /* Return __classcell__ if it is referenced, otherwise return None */
1970 if (c->u->u_ste->ste_needs_class_closure) { 1971 if (c->u->u_ste->ste_needs_class_closure) {
1971 /* store __classcell__ into class namespace */ 1972 /* Store __classcell__ into class namespace & return it */
1972 str = PyUnicode_InternFromString("__class__"); 1973 str = PyUnicode_InternFromString("__class__");
1973 if (str == NULL) { 1974 if (str == NULL) {
1974 compiler_exit_scope(c); 1975 compiler_exit_scope(c);
1975 return 0; 1976 return 0;
1976 } 1977 }
1977 i = compiler_lookup_arg(c->u->u_cellvars, str); 1978 i = compiler_lookup_arg(c->u->u_cellvars, str);
1978 Py_DECREF(str); 1979 Py_DECREF(str);
1979 if (i < 0) { 1980 if (i < 0) {
1980 compiler_exit_scope(c); 1981 compiler_exit_scope(c);
1981 return 0; 1982 return 0;
1982 } 1983 }
1983 assert(i == 0); 1984 assert(i == 0);
1984 1985
1985 ADDOP_I(c, LOAD_CLOSURE, i); 1986 ADDOP_I(c, LOAD_CLOSURE, i);
1987 ADDOP(c, DUP_TOP);
1986 str = PyUnicode_InternFromString("__classcell__"); 1988 str = PyUnicode_InternFromString("__classcell__");
1987 if (!str || !compiler_nameop(c, str, Store)) { 1989 if (!str || !compiler_nameop(c, str, Store)) {
1988 Py_XDECREF(str); 1990 Py_XDECREF(str);
1989 compiler_exit_scope(c); 1991 compiler_exit_scope(c);
1990 return 0; 1992 return 0;
1991 } 1993 }
1992 Py_DECREF(str); 1994 Py_DECREF(str);
1993 } 1995 }
1994 else { 1996 else {
1995 /* This happens when nobody references the cell. */ 1997 /* No methods referenced __class__, so just return None */
1996 assert(PyDict_Size(c->u->u_cellvars) == 0); 1998 assert(PyDict_Size(c->u->u_cellvars) == 0);
1997 } 1999 ADDOP_O(c, LOAD_CONST, Py_None, consts);
2000 }
2001 ADDOP_IN_SCOPE(c, RETURN_VALUE);
1998 /* create the code object */ 2002 /* create the code object */
1999 co = assemble(c, 1); 2003 co = assemble(c, 1);
2000 } 2004 }
2001 /* leave the new scope */ 2005 /* leave the new scope */
2002 compiler_exit_scope(c); 2006 compiler_exit_scope(c);
2003 if (co == NULL) 2007 if (co == NULL)
2004 return 0; 2008 return 0;
2005 2009
2006 /* 2. load the 'build_class' function */ 2010 /* 2. load the 'build_class' function */
2007 ADDOP(c, LOAD_BUILD_CLASS); 2011 ADDOP(c, LOAD_BUILD_CLASS);
(...skipping 3358 matching lines...) Expand 10 before | Expand all | Expand 10 after
5366 return co; 5370 return co;
5367 } 5371 }
5368 5372
5369 #undef PyAST_Compile 5373 #undef PyAST_Compile
5370 PyAPI_FUNC(PyCodeObject *) 5374 PyAPI_FUNC(PyCodeObject *)
5371 PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags, 5375 PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags,
5372 PyArena *arena) 5376 PyArena *arena)
5373 { 5377 {
5374 return PyAST_CompileEx(mod, filename, flags, -1, arena); 5378 return PyAST_CompileEx(mod, filename, flags, -1, arena);
5375 } 5379 }
LEFTRIGHT

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