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

Side by Side Diff: Python/compile.c

Issue 23722: During metaclass.__init__, super() of the constructed class does not work
Patch Set: Created 3 years, 4 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
« Python/bltinmodule.c ('K') | « Python/bltinmodule.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1865 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 compiler_exit_scope(c); 1876 compiler_exit_scope(c);
1877 return 0; 1877 return 0;
1878 } 1878 }
1879 Py_DECREF(str); 1879 Py_DECREF(str);
1880 /* compile the body proper */ 1880 /* compile the body proper */
1881 if (!compiler_body(c, s->v.ClassDef.body)) { 1881 if (!compiler_body(c, s->v.ClassDef.body)) {
1882 compiler_exit_scope(c); 1882 compiler_exit_scope(c);
1883 return 0; 1883 return 0;
1884 } 1884 }
1885 if (c->u->u_ste->ste_needs_class_closure) { 1885 if (c->u->u_ste->ste_needs_class_closure) {
1886 /* return the (empty) __class__ cell */ 1886 /* store __classcell__ into class namespace */
1887 str = PyUnicode_InternFromString("__class__"); 1887 str = PyUnicode_InternFromString("__class__");
1888 if (str == NULL) { 1888 if (str == NULL) {
1889 compiler_exit_scope(c); 1889 compiler_exit_scope(c);
1890 return 0; 1890 return 0;
1891 } 1891 }
1892 i = compiler_lookup_arg(c->u->u_cellvars, str); 1892 i = compiler_lookup_arg(c->u->u_cellvars, str);
1893 Py_DECREF(str); 1893 Py_DECREF(str);
1894 if (i < 0) { 1894 if (i < 0) {
1895 compiler_exit_scope(c); 1895 compiler_exit_scope(c);
1896 return 0; 1896 return 0;
1897 } 1897 }
1898 assert(i == 0); 1898 assert(i == 0);
1899 /* Return the cell where to store __class__ */ 1899
1900 ADDOP_I(c, LOAD_CLOSURE, i); 1900 ADDOP_I(c, LOAD_CLOSURE, i);
1901 str = PyUnicode_InternFromString("__classcell__");
tecki 2016/07/17 18:49:21 At the end of the class body, the compiler used to
1902 if (!str || !compiler_nameop(c, str, Store)) {
1903 Py_XDECREF(str);
1904 compiler_exit_scope(c);
1905 return 0;
1906 }
1907 Py_DECREF(str);
1901 } 1908 }
1902 else { 1909 else {
1910 /* This happens when nobody references the cell. */
1903 assert(PyDict_Size(c->u->u_cellvars) == 0); 1911 assert(PyDict_Size(c->u->u_cellvars) == 0);
1904 /* This happens when nobody references the cell. Return None. */
1905 ADDOP_O(c, LOAD_CONST, Py_None, consts);
1906 } 1912 }
1907 ADDOP_IN_SCOPE(c, RETURN_VALUE);
1908 /* create the code object */ 1913 /* create the code object */
1909 co = assemble(c, 1); 1914 co = assemble(c, 1);
1910 } 1915 }
1911 /* leave the new scope */ 1916 /* leave the new scope */
1912 compiler_exit_scope(c); 1917 compiler_exit_scope(c);
1913 if (co == NULL) 1918 if (co == NULL)
1914 return 0; 1919 return 0;
1915 1920
1916 /* 2. load the 'build_class' function */ 1921 /* 2. load the 'build_class' function */
1917 ADDOP(c, LOAD_BUILD_CLASS); 1922 ADDOP(c, LOAD_BUILD_CLASS);
(...skipping 3076 matching lines...) Expand 10 before | Expand all | Expand 10 after
4994 return co; 4999 return co;
4995 } 5000 }
4996 5001
4997 #undef PyAST_Compile 5002 #undef PyAST_Compile
4998 PyAPI_FUNC(PyCodeObject *) 5003 PyAPI_FUNC(PyCodeObject *)
4999 PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags, 5004 PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags,
5000 PyArena *arena) 5005 PyArena *arena)
5001 { 5006 {
5002 return PyAST_CompileEx(mod, filename, flags, -1, arena); 5007 return PyAST_CompileEx(mod, filename, flags, -1, arena);
5003 } 5008 }
OLDNEW
« Python/bltinmodule.c ('K') | « Python/bltinmodule.c ('k') | no next file » | no next file with comments »

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