@@ -708,102 +708,98 @@ dummy_func(
708708 macro (BINARY_OP_SUBTRACT_INT ) =
709709 _GUARD_TOS_INT + _GUARD_NOS_INT + unused /5 + _BINARY_OP_SUBTRACT_INT + _POP_TOP_INT + _POP_TOP_INT ;
710710
711- // Inplace compact int ops: try to mutate the uniquely-referenced
712- // operand. If TARGET is immortal (small int at runtime) or the
713- // result doesn't fit, fall back to _PyCompactLong_*. Tier 2 only.
711+ // Inplace compact int ops: mutate the uniquely-referenced operand
712+ // when possible. If TARGET is immortal (small int) or the result
713+ // is a small int or overflows, fall back to _PyCompactLong_*.
714+ // On mutation success, DUP the target so POP_TOP_INT can safely
715+ // decref the original. Tier 2 only.
714716 tier2 op (_BINARY_OP_ADD_INT_INPLACE , (left , right -- res , l , r )) {
715717 INT_INPLACE_OP (left , right , left , + );
716718 if (_int_inplace_ok ) {
717- res = left ;
718- l = PyStackRef_NULL ;
719+ res = PyStackRef_DUP (left );
719720 }
720721 else {
721722 res = _PyCompactLong_Add ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
722723 (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
723724 EXIT_IF (PyStackRef_IsNull (res ));
724- l = left ;
725725 }
726+ l = left ;
726727 r = right ;
727728 INPUTS_DEAD ();
728729 }
729730
730731 tier2 op (_BINARY_OP_SUBTRACT_INT_INPLACE , (left , right -- res , l , r )) {
731732 INT_INPLACE_OP (left , right , left , - );
732733 if (_int_inplace_ok ) {
733- res = left ;
734- l = PyStackRef_NULL ;
734+ res = PyStackRef_DUP (left );
735735 }
736736 else {
737737 res = _PyCompactLong_Subtract ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
738738 (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
739739 EXIT_IF (PyStackRef_IsNull (res ));
740- l = left ;
741740 }
741+ l = left ;
742742 r = right ;
743743 INPUTS_DEAD ();
744744 }
745745
746746 tier2 op (_BINARY_OP_MULTIPLY_INT_INPLACE , (left , right -- res , l , r )) {
747747 INT_INPLACE_OP (left , right , left , * );
748748 if (_int_inplace_ok ) {
749- res = left ;
750- l = PyStackRef_NULL ;
749+ res = PyStackRef_DUP (left );
751750 }
752751 else {
753752 res = _PyCompactLong_Multiply ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
754753 (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
755754 EXIT_IF (PyStackRef_IsNull (res ));
756- l = left ;
757755 }
756+ l = left ;
758757 r = right ;
759758 INPUTS_DEAD ();
760759 }
761760
762761 tier2 op (_BINARY_OP_ADD_INT_INPLACE_RIGHT , (left , right -- res , l , r )) {
763762 INT_INPLACE_OP (left , right , right , + );
764763 if (_int_inplace_ok ) {
765- res = right ;
766- r = PyStackRef_NULL ;
764+ res = PyStackRef_DUP (right );
767765 }
768766 else {
769767 res = _PyCompactLong_Add ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
770768 (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
771769 EXIT_IF (PyStackRef_IsNull (res ));
772- r = right ;
773770 }
774771 l = left ;
772+ r = right ;
775773 INPUTS_DEAD ();
776774 }
777775
778776 tier2 op (_BINARY_OP_SUBTRACT_INT_INPLACE_RIGHT , (left , right -- res , l , r )) {
779777 INT_INPLACE_OP (left , right , right , - );
780778 if (_int_inplace_ok ) {
781- res = right ;
782- r = PyStackRef_NULL ;
779+ res = PyStackRef_DUP (right );
783780 }
784781 else {
785782 res = _PyCompactLong_Subtract ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
786783 (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
787784 EXIT_IF (PyStackRef_IsNull (res ));
788- r = right ;
789785 }
790786 l = left ;
787+ r = right ;
791788 INPUTS_DEAD ();
792789 }
793790
794791 tier2 op (_BINARY_OP_MULTIPLY_INT_INPLACE_RIGHT , (left , right -- res , l , r )) {
795792 INT_INPLACE_OP (left , right , right , * );
796793 if (_int_inplace_ok ) {
797- res = right ;
798- r = PyStackRef_NULL ;
794+ res = PyStackRef_DUP (right );
799795 }
800796 else {
801797 res = _PyCompactLong_Multiply ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
802798 (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
803799 EXIT_IF (PyStackRef_IsNull (res ));
804- r = right ;
805800 }
806801 l = left ;
802+ r = right ;
807803 INPUTS_DEAD ();
808804 }
809805
0 commit comments