Skip to content

Commit

Permalink
sv_clear: with zero SvREFCNT, call sv_free2, not sv_free
Browse files Browse the repository at this point in the history
Towards the bottom of `Perl_sv_clear`, there is a region described as
being `* unrolled SvREFCNT_dec and sv_free2 follows: */`. This was
introduced in 5239d5c
but the definitions of `Perl_sv_free`, `Perl_sv_free2`, and `SvREFCNT_dec`
were updated in 75a9bf9
and this region of code didn't get updated.

The unrolling remains valid, but the call to `sv_free(sv)` ultimately boils
down to a call to `sv_free2`, so this commit just goes there directly.
  • Loading branch information
richardleach committed Dec 12, 2024
1 parent 9e152df commit c38b052
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -7120,12 +7120,18 @@ Perl_sv_clear(pTHX_ SV *const orig_sv)
}
}

/* unrolled SvREFCNT_dec and sv_free2 follows: */
/* Do the equivalent of SvREFCNT_dec(sv), except:
- for the case of RC==1, inline the actions normally taken
by sv_free2() prior it calling sv_clear(), and handle the
sv_clear() actions ourselves (without needing to
recurse).
- For the exceptional case of RC==0, do a traditional
recursive free. */

if (!sv)
continue;
if (!SvREFCNT(sv)) {
sv_free(sv);
Perl_sv_free2(aTHX_ sv, 0);
continue;
}
if (--(SvREFCNT(sv)))
Expand Down

0 comments on commit c38b052

Please sign in to comment.