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

Delta Between Two Patch Sets: Objects/codeobject.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 | « Lib/test/test_compile.py ('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 #include "Python.h" 1 #include "Python.h"
2 #include "code.h" 2 #include "code.h"
3 #include "structmember.h" 3 #include "structmember.h"
4 4
5 #define NAME_CHARS \ 5 #define NAME_CHARS \
6 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" 6 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
7 7
8 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */ 8 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */
9 9
10 static int 10 static int
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 PyObject *key; 415 PyObject *key;
416 416
417 /* Py_None and Py_Ellipsis are singleton */ 417 /* Py_None and Py_Ellipsis are singleton */
418 if (op == Py_None || op == Py_Ellipsis 418 if (op == Py_None || op == Py_Ellipsis
419 || PyLong_CheckExact(op) 419 || PyLong_CheckExact(op)
420 || PyBool_Check(op) 420 || PyBool_Check(op)
421 || PyBytes_CheckExact(op) 421 || PyBytes_CheckExact(op)
422 || PyUnicode_CheckExact(op) 422 || PyUnicode_CheckExact(op)
423 /* code_richcompare() uses _PyCode_ConstantKey() internally */ 423 /* code_richcompare() uses _PyCode_ConstantKey() internally */
424 || PyCode_Check(op)) { 424 || PyCode_Check(op)) {
425 key = PyTuple_Pack(2, op, Py_TYPE(op)); 425 key = PyTuple_Pack(2, Py_TYPE(op), op);
426 } 426 }
427 else if (PyFloat_CheckExact(op)) { 427 else if (PyFloat_CheckExact(op)) {
428 double d = PyFloat_AS_DOUBLE(op); 428 double d = PyFloat_AS_DOUBLE(op);
429 /* all we need is to make the tuple different in either the 0.0 429 /* all we need is to make the tuple different in either the 0.0
430 * or -0.0 case from all others, just to avoid the "coercion". 430 * or -0.0 case from all others, just to avoid the "coercion".
431 */ 431 */
432 if (d == 0.0 && copysign(1.0, d) < 0.0) 432 if (d == 0.0 && copysign(1.0, d) < 0.0)
433 key = PyTuple_Pack(3, op, Py_TYPE(op), Py_None); 433 key = PyTuple_Pack(3, Py_TYPE(op), op, Py_None);
434 else 434 else
435 key = PyTuple_Pack(2, op, Py_TYPE(op)); 435 key = PyTuple_Pack(2, Py_TYPE(op), op);
436 } 436 }
437 else if (PyComplex_CheckExact(op)) { 437 else if (PyComplex_CheckExact(op)) {
438 Py_complex z; 438 Py_complex z;
439 int real_negzero, imag_negzero; 439 int real_negzero, imag_negzero;
440 /* For the complex case we must make complex(x, 0.) 440 /* For the complex case we must make complex(x, 0.)
441 different from complex(x, -0.) and complex(0., y) 441 different from complex(x, -0.) and complex(0., y)
442 different from complex(-0., y), for any x and y. 442 different from complex(-0., y), for any x and y.
443 All four complex zeros must be distinguished.*/ 443 All four complex zeros must be distinguished.*/
444 z = PyComplex_AsCComplex(op); 444 z = PyComplex_AsCComplex(op);
445 real_negzero = z.real == 0.0 && copysign(1.0, z.real) < 0.0; 445 real_negzero = z.real == 0.0 && copysign(1.0, z.real) < 0.0;
446 imag_negzero = z.imag == 0.0 && copysign(1.0, z.imag) < 0.0; 446 imag_negzero = z.imag == 0.0 && copysign(1.0, z.imag) < 0.0;
447 /* use True, False and None singleton as tags for the real and imag 447 /* use True, False and None singleton as tags for the real and imag
448 * sign, to make tuples different */ 448 * sign, to make tuples different */
449 if (real_negzero && imag_negzero) { 449 if (real_negzero && imag_negzero) {
450 key = PyTuple_Pack(3, op, Py_TYPE(op), Py_True); 450 key = PyTuple_Pack(3, Py_TYPE(op), op, Py_True);
451 } 451 }
452 else if (imag_negzero) { 452 else if (imag_negzero) {
453 key = PyTuple_Pack(3, op, Py_TYPE(op), Py_False); 453 key = PyTuple_Pack(3, Py_TYPE(op), op, Py_False);
454 } 454 }
455 else if (real_negzero) { 455 else if (real_negzero) {
456 key = PyTuple_Pack(3, op, Py_TYPE(op), Py_None); 456 key = PyTuple_Pack(3, Py_TYPE(op), op, Py_None);
457 } 457 }
458 else { 458 else {
459 key = PyTuple_Pack(2, op, Py_TYPE(op)); 459 key = PyTuple_Pack(2, Py_TYPE(op), op);
460 } 460 }
461 } 461 }
462 else if (PyTuple_CheckExact(op)) { 462 else if (PyTuple_CheckExact(op)) {
463 Py_ssize_t i, len; 463 Py_ssize_t i, len;
464 PyObject *tuple; 464 PyObject *tuple;
465 465
466 len = PyTuple_GET_SIZE(op); 466 len = PyTuple_GET_SIZE(op);
467 tuple = PyTuple_New(len); 467 tuple = PyTuple_New(len);
468 if (tuple == NULL) 468 if (tuple == NULL)
469 return NULL; 469 return NULL;
470 470
471 for (i=0; i < len; i++) { 471 for (i=0; i < len; i++) {
472 PyObject *item, *item_key; 472 PyObject *item, *item_key;
473 473
474 item = PyTuple_GET_ITEM(op, i); 474 item = PyTuple_GET_ITEM(op, i);
475 item_key = _PyCode_ConstantKey(item); 475 item_key = _PyCode_ConstantKey(item);
476 if (item_key == NULL) { 476 if (item_key == NULL) {
477 Py_DECREF(tuple); 477 Py_DECREF(tuple);
478 return NULL; 478 return NULL;
479 } 479 }
480 480
481 PyTuple_SET_ITEM(tuple, i, item_key); 481 PyTuple_SET_ITEM(tuple, i, item_key);
482 } 482 }
483 483
484 key = PyTuple_Pack(3, op, Py_TYPE(op), tuple); 484 key = PyTuple_Pack(3, Py_TYPE(op), op, tuple);
485 Py_DECREF(tuple); 485 Py_DECREF(tuple);
486 } 486 }
487 else if (PyAnySet_CheckExact(op)) { 487 else if (PyFrozenSet_CheckExact(op)) {
488 Py_ssize_t pos = 0; 488 Py_ssize_t pos = 0;
489 PyObject *item; 489 PyObject *item;
490 Py_hash_t hash; 490 Py_hash_t hash;
491 Py_ssize_t i, len; 491 Py_ssize_t i, len;
492 PyObject *tuple, *set; 492 PyObject *tuple, *set;
493 493
494 len = PySet_GET_SIZE(op); 494 len = PySet_GET_SIZE(op);
495 tuple = PyTuple_New(len); 495 tuple = PyTuple_New(len);
496 if (tuple == NULL) 496 if (tuple == NULL)
497 return NULL; 497 return NULL;
498 498
499 i = 0; 499 i = 0;
500 while (_PySet_NextEntry(op, &pos, &item, &hash)) { 500 while (_PySet_NextEntry(op, &pos, &item, &hash)) {
501 PyObject *item_key; 501 PyObject *item_key;
502 502
503 item_key = _PyCode_ConstantKey(item); 503 item_key = _PyCode_ConstantKey(item);
504 if (item_key == NULL) { 504 if (item_key == NULL) {
505 Py_DECREF(tuple); 505 Py_DECREF(tuple);
506 return NULL; 506 return NULL;
507 } 507 }
508 508
509 assert(i < len); 509 assert(i < len);
510 PyTuple_SET_ITEM(tuple, i, item_key); 510 PyTuple_SET_ITEM(tuple, i, item_key);
511 i++; 511 i++;
512 } 512 }
513 if (PyFrozenSet_CheckExact(op)) 513 set = PyFrozenSet_New(tuple);
514 set = PyFrozenSet_New(tuple);
515 else
516 set = PySet_New(tuple);
517 Py_DECREF(tuple); 514 Py_DECREF(tuple);
518 if (set == NULL) 515 if (set == NULL)
519 return NULL; 516 return NULL;
520 517
521 key = PyTuple_Pack(3, op, Py_TYPE(op), set); 518 key = PyTuple_Pack(3, Py_TYPE(op), op, set);
522 Py_DECREF(set); 519 Py_DECREF(set);
523 return key; 520 return key;
524 } 521 }
525 else { 522 else {
526 /* for other types, use the identifier to *not* merge them 523 /* for other types, use the identifier to *not* merge them
527 * even if they are equal */ 524 * even if they are equal */
528 PyObject *obj_id = PyLong_FromVoidPtr(op); 525 PyObject *obj_id = PyLong_FromVoidPtr(op);
529 if (obj_id == NULL) 526 if (obj_id == NULL)
530 return NULL; 527 return NULL;
531 528
532 key = PyTuple_Pack(3, op, Py_TYPE(op), obj_id); 529 key = PyTuple_Pack(3, Py_TYPE(op), op, obj_id);
533 Py_DECREF(obj_id); 530 Py_DECREF(obj_id);
534 } 531 }
535 return key; 532 return key;
536 } 533 }
537 534
538 static PyObject * 535 static PyObject *
539 code_richcompare(PyObject *self, PyObject *other, int op) 536 code_richcompare(PyObject *self, PyObject *other, int op)
540 { 537 {
541 PyCodeObject *co, *cp; 538 PyCodeObject *co, *cp;
542 int eq; 539 int eq;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 p++; 745 p++;
749 } 746 }
750 bounds->ap_upper = addr; 747 bounds->ap_upper = addr;
751 } 748 }
752 else { 749 else {
753 bounds->ap_upper = INT_MAX; 750 bounds->ap_upper = INT_MAX;
754 } 751 }
755 752
756 return line; 753 return line;
757 } 754 }
LEFTRIGHT

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