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

Side by Side Diff: Python/bltinmodule.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
OLDNEW
1 /* Built-in functions */ 1 /* Built-in functions */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "Python-ast.h" 4 #include "Python-ast.h"
5 5
6 #include "node.h" 6 #include "node.h"
7 #include "code.h" 7 #include "code.h"
8 8
9 #include "asdl.h" 9 #include "asdl.h"
10 #include "ast.h" 10 #include "ast.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 _Py_IDENTIFIER(stdin); 45 _Py_IDENTIFIER(stdin);
46 _Py_IDENTIFIER(stdout); 46 _Py_IDENTIFIER(stdout);
47 _Py_IDENTIFIER(stderr); 47 _Py_IDENTIFIER(stderr);
48 48
49 #include "clinic/bltinmodule.c.h" 49 #include "clinic/bltinmodule.c.h"
50 50
51 /* AC: cannot convert yet, waiting for *args support */ 51 /* AC: cannot convert yet, waiting for *args support */
52 static PyObject * 52 static PyObject *
53 builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) 53 builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
54 { 54 {
55 PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns, *cell; 55 PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns, *none;
56 PyObject *cls = NULL; 56 PyObject *cls = NULL;
57 Py_ssize_t nargs; 57 Py_ssize_t nargs;
58 int isclass = 0; /* initialize to prevent gcc warning */ 58 int isclass = 0; /* initialize to prevent gcc warning */
59 59
60 assert(args != NULL); 60 assert(args != NULL);
61 if (!PyTuple_Check(args)) { 61 if (!PyTuple_Check(args)) {
62 PyErr_SetString(PyExc_TypeError, 62 PyErr_SetString(PyExc_TypeError,
63 "__build_class__: args is not a tuple"); 63 "__build_class__: args is not a tuple");
64 return NULL; 64 return NULL;
65 } 65 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 ns = PyEval_CallObjectWithKeywords(prep, pargs, mkw); 166 ns = PyEval_CallObjectWithKeywords(prep, pargs, mkw);
167 Py_DECREF(pargs); 167 Py_DECREF(pargs);
168 Py_DECREF(prep); 168 Py_DECREF(prep);
169 } 169 }
170 if (ns == NULL) { 170 if (ns == NULL) {
171 Py_DECREF(meta); 171 Py_DECREF(meta);
172 Py_XDECREF(mkw); 172 Py_XDECREF(mkw);
173 Py_DECREF(bases); 173 Py_DECREF(bases);
174 return NULL; 174 return NULL;
175 } 175 }
176 cell = PyEval_EvalCodeEx(PyFunction_GET_CODE(func), PyFunction_GET_GLOBALS(f unc), ns, 176 none = PyEval_EvalCodeEx(PyFunction_GET_CODE(func), PyFunction_GET_GLOBALS(f unc), ns,
177 NULL, 0, NULL, 0, NULL, 0, NULL, 177 NULL, 0, NULL, 0, NULL, 0, NULL,
178 PyFunction_GET_CLOSURE(func)); 178 PyFunction_GET_CLOSURE(func));
179 if (cell != NULL) { 179 if (none != NULL) {
180 PyObject *margs; 180 PyObject *margs;
181 margs = PyTuple_Pack(3, name, bases, ns); 181 margs = PyTuple_Pack(3, name, bases, ns);
182 if (margs != NULL) { 182 if (margs != NULL) {
183 cls = PyEval_CallObjectWithKeywords(meta, margs, mkw); 183 cls = PyEval_CallObjectWithKeywords(meta, margs, mkw);
184 Py_DECREF(margs); 184 Py_DECREF(margs);
185 } 185 }
186 if (cls != NULL && PyCell_Check(cell)) 186 Py_DECREF(none);
tecki 2016/07/17 18:49:21 This is where the method's __class__ used to be se
187 PyCell_Set(cell, cls);
188 Py_DECREF(cell);
189 } 187 }
190 Py_DECREF(ns); 188 Py_DECREF(ns);
191 Py_DECREF(meta); 189 Py_DECREF(meta);
192 Py_XDECREF(mkw); 190 Py_XDECREF(mkw);
193 Py_DECREF(bases); 191 Py_DECREF(bases);
194 return cls; 192 return cls;
195 } 193 }
196 194
197 PyDoc_STRVAR(build_class_doc, 195 PyDoc_STRVAR(build_class_doc,
198 "__build_class__(func, name, *bases, metaclass=None, **kwds) -> class\n\ 196 "__build_class__(func, name, *bases, metaclass=None, **kwds) -> class\n\
(...skipping 2513 matching lines...) Expand 10 before | Expand all | Expand 10 after
2712 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { 2710 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
2713 Py_DECREF(debug); 2711 Py_DECREF(debug);
2714 return NULL; 2712 return NULL;
2715 } 2713 }
2716 Py_DECREF(debug); 2714 Py_DECREF(debug);
2717 2715
2718 return mod; 2716 return mod;
2719 #undef ADD_TO_ALL 2717 #undef ADD_TO_ALL
2720 #undef SETBUILTIN 2718 #undef SETBUILTIN
2721 } 2719 }
OLDNEW

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