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

Delta Between Two Patch Sets: Python/compile.c

Issue 25843: lambdas on the same line may incorrectly share code objects
Left Patch Set: Created 4 years, 1 month ago
Right Patch Set: Created 4 years, 1 month 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/codeobject.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
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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 if (!dict) return NULL; 386 if (!dict) return NULL;
387 387
388 n = PyList_Size(list); 388 n = PyList_Size(list);
389 for (i = 0; i < n; i++) { 389 for (i = 0; i < n; i++) {
390 v = PyLong_FromSsize_t(i); 390 v = PyLong_FromSsize_t(i);
391 if (!v) { 391 if (!v) {
392 Py_DECREF(dict); 392 Py_DECREF(dict);
393 return NULL; 393 return NULL;
394 } 394 }
395 k = PyList_GET_ITEM(list, i); 395 k = PyList_GET_ITEM(list, i);
396 k = PyTuple_Pack(2, k, k->ob_type); 396 k = _PyCode_ConstantKey(k);
397 if (k == NULL || PyDict_SetItem(dict, k, v) < 0) { 397 if (k == NULL || PyDict_SetItem(dict, k, v) < 0) {
398 Py_XDECREF(k); 398 Py_XDECREF(k);
399 Py_DECREF(v); 399 Py_DECREF(v);
400 Py_DECREF(dict); 400 Py_DECREF(dict);
401 return NULL; 401 return NULL;
402 } 402 }
403 Py_DECREF(k); 403 Py_DECREF(k);
404 Py_DECREF(v); 404 Py_DECREF(v);
405 } 405 }
406 return dict; 406 return dict;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 scope = (vi >> SCOPE_OFFSET) & SCOPE_MASK; 449 scope = (vi >> SCOPE_OFFSET) & SCOPE_MASK;
450 450
451 if (scope == scope_type || vi & flag) { 451 if (scope == scope_type || vi & flag) {
452 PyObject *tuple, *item = PyLong_FromSsize_t(i); 452 PyObject *tuple, *item = PyLong_FromSsize_t(i);
453 if (item == NULL) { 453 if (item == NULL) {
454 Py_DECREF(sorted_keys); 454 Py_DECREF(sorted_keys);
455 Py_DECREF(dest); 455 Py_DECREF(dest);
456 return NULL; 456 return NULL;
457 } 457 }
458 i++; 458 i++;
459 tuple = PyTuple_Pack(2, k, k->ob_type); 459 tuple = _PyCode_ConstantKey(k);
460 if (!tuple || PyDict_SetItem(dest, tuple, item) < 0) { 460 if (!tuple || PyDict_SetItem(dest, tuple, item) < 0) {
461 Py_DECREF(sorted_keys); 461 Py_DECREF(sorted_keys);
462 Py_DECREF(item); 462 Py_DECREF(item);
463 Py_DECREF(dest); 463 Py_DECREF(dest);
464 Py_XDECREF(tuple); 464 Py_XDECREF(tuple);
465 return NULL; 465 return NULL;
466 } 466 }
467 Py_DECREF(item); 467 Py_DECREF(item);
468 Py_DECREF(tuple); 468 Py_DECREF(tuple);
469 } 469 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 _Py_IDENTIFIER(__class__); 552 _Py_IDENTIFIER(__class__);
553 PyObject *tuple, *name, *zero; 553 PyObject *tuple, *name, *zero;
554 int res; 554 int res;
555 assert(u->u_scope_type == COMPILER_SCOPE_CLASS); 555 assert(u->u_scope_type == COMPILER_SCOPE_CLASS);
556 assert(PyDict_Size(u->u_cellvars) == 0); 556 assert(PyDict_Size(u->u_cellvars) == 0);
557 name = _PyUnicode_FromId(&PyId___class__); 557 name = _PyUnicode_FromId(&PyId___class__);
558 if (!name) { 558 if (!name) {
559 compiler_unit_free(u); 559 compiler_unit_free(u);
560 return 0; 560 return 0;
561 } 561 }
562 tuple = PyTuple_Pack(2, name, Py_TYPE(name)); 562 tuple = _PyCode_ConstantKey(name);
563 if (!tuple) { 563 if (!tuple) {
564 compiler_unit_free(u); 564 compiler_unit_free(u);
565 return 0; 565 return 0;
566 } 566 }
567 zero = PyLong_FromLong(0); 567 zero = PyLong_FromLong(0);
568 if (!zero) { 568 if (!zero) {
569 Py_DECREF(tuple); 569 Py_DECREF(tuple);
570 compiler_unit_free(u); 570 compiler_unit_free(u);
571 return 0; 571 return 0;
572 } 572 }
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 Py_FatalError(buf); 1413 Py_FatalError(buf);
1414 } 1414 }
1415 1415
1416 return scope; 1416 return scope;
1417 } 1417 }
1418 1418
1419 static int 1419 static int
1420 compiler_lookup_arg(PyObject *dict, PyObject *name) 1420 compiler_lookup_arg(PyObject *dict, PyObject *name)
1421 { 1421 {
1422 PyObject *k, *v; 1422 PyObject *k, *v;
1423 k = PyTuple_Pack(2, name, name->ob_type); 1423 k = _PyCode_ConstantKey(name);
1424 if (k == NULL) 1424 if (k == NULL)
1425 return -1; 1425 return -1;
1426 v = PyDict_GetItem(dict, k); 1426 v = PyDict_GetItem(dict, k);
1427 Py_DECREF(k); 1427 Py_DECREF(k);
1428 if (v == NULL) 1428 if (v == NULL)
1429 return -1; 1429 return -1;
1430 return PyLong_AS_LONG(v); 1430 return PyLong_AS_LONG(v);
1431 } 1431 }
1432 1432
1433 static int 1433 static int
(...skipping 3177 matching lines...) Expand 10 before | Expand all | Expand 10 after
4611 dict_keys_inorder(PyObject *dict, Py_ssize_t offset) 4611 dict_keys_inorder(PyObject *dict, Py_ssize_t offset)
4612 { 4612 {
4613 PyObject *tuple, *k, *v; 4613 PyObject *tuple, *k, *v;
4614 Py_ssize_t i, pos = 0, size = PyDict_Size(dict); 4614 Py_ssize_t i, pos = 0, size = PyDict_Size(dict);
4615 4615
4616 tuple = PyTuple_New(size); 4616 tuple = PyTuple_New(size);
4617 if (tuple == NULL) 4617 if (tuple == NULL)
4618 return NULL; 4618 return NULL;
4619 while (PyDict_Next(dict, &pos, &k, &v)) { 4619 while (PyDict_Next(dict, &pos, &k, &v)) {
4620 i = PyLong_AS_LONG(v); 4620 i = PyLong_AS_LONG(v);
4621 /* The keys of the dictionary are tuples. (see compiler_add_o) 4621 /* The keys of the dictionary are tuples. (see compiler_add_o
4622 The object we want is always first, though. */ 4622 * and _PyCode_ConstantKey). The object we want is always second,
4623 k = PyTuple_GET_ITEM(k, 0); 4623 * though. */
4624 k = PyTuple_GET_ITEM(k, 1);
4624 Py_INCREF(k); 4625 Py_INCREF(k);
4625 assert((i - offset) < size); 4626 assert((i - offset) < size);
4626 assert((i - offset) >= 0); 4627 assert((i - offset) >= 0);
4627 PyTuple_SET_ITEM(tuple, i - offset, k); 4628 PyTuple_SET_ITEM(tuple, i - offset, k);
4628 } 4629 }
4629 return tuple; 4630 return tuple;
4630 } 4631 }
4631 4632
4632 static int 4633 static int
4633 compute_code_flags(struct compiler *c) 4634 compute_code_flags(struct compiler *c)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
4832 return co; 4833 return co;
4833 } 4834 }
4834 4835
4835 #undef PyAST_Compile 4836 #undef PyAST_Compile
4836 PyAPI_FUNC(PyCodeObject *) 4837 PyAPI_FUNC(PyCodeObject *)
4837 PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags, 4838 PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags,
4838 PyArena *arena) 4839 PyArena *arena)
4839 { 4840 {
4840 return PyAST_CompileEx(mod, filename, flags, -1, arena); 4841 return PyAST_CompileEx(mod, filename, flags, -1, arena);
4841 } 4842 }
LEFTRIGHT

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