@@ -2431,9 +2431,11 @@ stackref_from_object_new(PyObject *self, PyObject *op)
24312431static PyObject *
24322432stackref_from_object_steal_with_incref (PyObject * self , PyObject * op )
24332433{
2434+ // The next two lines are equivalent to PyStackRef_FromPyObjectNew.
24342435 Py_INCREF (op );
24352436 _PyStackRef ref = PyStackRef_FromPyObjectSteal (op );
24362437 PyObject * obj = _PyStackRef_AsTuple (ref , op );
2438+ // The next two lines are equivalent to PyStackRef_CLOSE.
24372439 PyObject * op2 = PyStackRef_AsPyObjectSteal (ref );
24382440 Py_DECREF (op2 );
24392441 return obj ;
@@ -2443,6 +2445,7 @@ static PyObject *
24432445stackref_make_heap_safe (PyObject * self , PyObject * op )
24442446{
24452447 _PyStackRef ref = PyStackRef_FromPyObjectNew (op );
2448+ // In no-GIL production build ref2 is equal to ref.
24462449 _PyStackRef ref2 = PyStackRef_MakeHeapSafe (ref );
24472450 PyObject * obj = _PyStackRef_AsTuple (ref2 , op );
24482451 PyStackRef_CLOSE (ref2 );
@@ -2455,6 +2458,7 @@ stackref_make_heap_safe_with_borrow(PyObject *self, PyObject *op)
24552458 _PyStackRef ref = PyStackRef_FromPyObjectNew (op );
24562459 _PyStackRef ref2 = PyStackRef_Borrow (ref );
24572460 _PyStackRef ref3 = PyStackRef_MakeHeapSafe (ref2 );
2461+ // We can close ref, since ref3 is heap safe.
24582462 PyStackRef_CLOSE (ref );
24592463 PyObject * obj = _PyStackRef_AsTuple (ref3 , op );
24602464 PyStackRef_CLOSE (ref3 );
@@ -2464,6 +2468,7 @@ stackref_make_heap_safe_with_borrow(PyObject *self, PyObject *op)
24642468static PyObject *
24652469stackref_strong_reference (PyObject * self , PyObject * op )
24662470{
2471+ // The next two lines are equivalent to op2 = Py_NewRef(op).
24672472 _PyStackRef ref = PyStackRef_FromPyObjectBorrow (op );
24682473 PyObject * op2 = PyStackRef_AsPyObjectSteal (ref );
24692474 _PyStackRef ref2 = PyStackRef_FromPyObjectSteal (op2 );
@@ -2485,7 +2490,9 @@ static PyObject *
24852490stackref_dup_borrowed_with_close (PyObject * self , PyObject * op )
24862491{
24872492 _PyStackRef ref = PyStackRef_FromPyObjectBorrow (op );
2493+ // In no-GIL production build ref2 is equal to ref.
24882494 _PyStackRef ref2 = PyStackRef_DUP (ref );
2495+ // In production build closing borrowed ref is no-op.
24892496 PyStackRef_XCLOSE (ref );
24902497 PyObject * obj = _PyStackRef_AsTuple (ref2 , op );
24912498 PyStackRef_XCLOSE (ref2 );
0 commit comments