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

Delta Between Two Patch Sets: Python/bltinmodule.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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Objects/typeobject.c ('k') | Python/compile.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 Py_DECREF(meta); 165 Py_DECREF(meta);
166 Py_XDECREF(mkw); 166 Py_XDECREF(mkw);
167 Py_DECREF(bases); 167 Py_DECREF(bases);
168 return NULL; 168 return NULL;
169 } 169 }
170 cell = PyEval_EvalCodeEx(PyFunction_GET_CODE(func), PyFunction_GET_GLOBALS(f unc), ns, 170 cell = PyEval_EvalCodeEx(PyFunction_GET_CODE(func), PyFunction_GET_GLOBALS(f unc), ns,
171 NULL, 0, NULL, 0, NULL, 0, NULL, 171 NULL, 0, NULL, 0, NULL, 0, NULL,
172 PyFunction_GET_CLOSURE(func)); 172 PyFunction_GET_CLOSURE(func));
173 if (cell != NULL) { 173 if (cell != NULL) {
174 PyObject *margs[3] = {name, bases, ns}; 174 PyObject *margs[3] = {name, bases, ns};
175 cls = _PyObject_FastCallDict(meta, margs, 3, mkw); 175 cls = _PyObject_FastCallDict(meta, margs, 3, mkw);
storchaka 2016/12/04 11:23:35 Is it worth to check that cls is a type?
Nick Coghlan 2016/12/04 13:39:05 Essential, as it turns out - the missing test case
176 if (cls != NULL && PyCell_Check(cell)) { 176 if (cls != NULL && PyType_Check(cls) && PyCell_Check(cell)) {
177 PyObject *cell_cls = PyCell_GET(cell); 177 PyObject *cell_cls = PyCell_GET(cell);
178 if (cell_cls != cls) { 178 if (cell_cls != cls) {
179 int cell_error = 0; 179 /* TODO: In 3.7, the deprecation warning becomes a RuntimeError
storchaka 2016/12/04 11:23:35 Initialization is not needed.
Nick Coghlan 2016/12/04 13:39:05 Done.
storchaka 2016/12/04 14:10:59 A dot is needed since the next line is a different
180 /*TODO: In 3.7, deprecation warning becomes a RuntimeError */ 180 * At that point, cell_error won't be needed.
storchaka 2016/12/04 11:23:35 Missed space after "/*".
Nick Coghlan 2016/12/04 13:39:05 Done.
181 */
182 int cell_error;
181 if (cell_cls == NULL) { 183 if (cell_cls == NULL) {
182 char *msg = "__class__ not set for %.200R. " 184 const char *msg =
storchaka 2016/12/04 11:23:35 It would be better to use "const char *".
Nick Coghlan 2016/12/04 13:39:05 Done.
183 "Was __classcell__ propagated to type.__new__?"; 185 "__class__ not set defining %.200R as %.200R. "
186 "Was __classcell__ propagated to type.__new__?";
184 cell_error = PyErr_WarnFormat( 187 cell_error = PyErr_WarnFormat(
185 PyExc_DeprecationWarning, 1, msg, cls); 188 PyExc_DeprecationWarning, 1, msg, name, cls);
186 } else { 189 } else {
187 char *msg = "__class__ set to %.200R for %.200R. "; 190 const char *msg =
storchaka 2016/12/04 11:23:35 Redundant space at the end. The dot perhaps is not
Nick Coghlan 2016/12/04 13:39:05 Done.
188 PyErr_Format(PyExc_TypeError, msg, cell_cls, cls); 191 "__class__ set to %.200R defining %.200R as %.200R.";
storchaka 2016/12/04 14:10:59 What about the ending dot? It usually is not used
192 PyErr_Format(PyExc_TypeError, msg, cell_cls, name, cls);
189 cell_error = 1; 193 cell_error = 1;
190 } 194 }
191 if (cell_error) { 195 if (cell_error) {
192 Py_DECREF(cls); 196 Py_DECREF(cls);
193 cls = NULL; 197 cls = NULL;
194 goto error; 198 goto error;
195 } else { 199 } else {
196 /* Fill in the cell, since type.__new__ didn't do it */ 200 /* Fill in the cell, since type.__new__ didn't do it */
197 PyCell_SET(cell, cls); 201 PyCell_Set(cell, cls);
storchaka 2016/12/04 11:23:35 Leaks old value of the cell. You can add Py_XDECR
Nick Coghlan 2016/12/04 13:39:05 Done.
198 } 202 }
199 } 203 }
200 } 204 }
201 } 205 }
202 error: 206 error:
203 Py_XDECREF(cell); 207 Py_XDECREF(cell);
204 Py_DECREF(ns); 208 Py_DECREF(ns);
205 Py_DECREF(meta); 209 Py_DECREF(meta);
206 Py_XDECREF(mkw); 210 Py_XDECREF(mkw);
207 Py_DECREF(bases); 211 Py_DECREF(bases);
(...skipping 2529 matching lines...) Expand 10 before | Expand all | Expand 10 after
2737 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { 2741 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
2738 Py_DECREF(debug); 2742 Py_DECREF(debug);
2739 return NULL; 2743 return NULL;
2740 } 2744 }
2741 Py_DECREF(debug); 2745 Py_DECREF(debug);
2742 2746
2743 return mod; 2747 return mod;
2744 #undef ADD_TO_ALL 2748 #undef ADD_TO_ALL
2745 #undef SETBUILTIN 2749 #undef SETBUILTIN
2746 } 2750 }
LEFTRIGHT

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