Skip to content

Commit f71cf50

Browse files
committed
sv_setsv_cow: change prototype to allow this to fail
This will actually fail in some cases in the next commit.
1 parent bcd28b1 commit f71cf50

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

embed.fnc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3979,7 +3979,7 @@ RTp |MEM_SIZE|malloc_good_size \
39793979
#endif
39803980
#if defined(PERL_ANY_COW)
39813981
: Used in regexec.c
3982-
EXpx |SV * |sv_setsv_cow |NULLOK SV *dsv \
3982+
EXpx |bool |sv_setsv_cow |NN SV **pdsv \
39833983
|NN SV *ssv
39843984
#endif
39853985
#if defined(PERL_CORE)

proto.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

regexec.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3534,7 +3534,9 @@ S_reg_set_capture_string(pTHX_ REGEXP * const rx,
35343534
else {
35353535
/* create new COW SV to share string */
35363536
RXp_MATCH_COPY_FREE(prog);
3537-
RXp_SAVED_COPY(prog) = sv_setsv_cow(RXp_SAVED_COPY(prog), sv);
3537+
/* sv_setsv_cow() might not COW for some reason */
3538+
if (!sv_setsv_cow(&RXp_SAVED_COPY(prog), sv))
3539+
goto didnt_cow;
35383540
}
35393541
RXp_SUBBEG(prog) = (char *)SvPVX_const(RXp_SAVED_COPY(prog));
35403542
assert (SvPOKp(RXp_SAVED_COPY(prog)));
@@ -3544,6 +3546,9 @@ S_reg_set_capture_string(pTHX_ REGEXP * const rx,
35443546
} else
35453547
#endif
35463548
{
3549+
#ifdef PERL_ANY_COW
3550+
didnt_cow:
3551+
#endif
35473552
SSize_t min = 0;
35483553
SSize_t max = strend - strbeg;
35493554
SSize_t sublen;

sv.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4889,8 +4889,8 @@ Perl_sv_setsv_mg(pTHX_ SV *const dsv, SV *const ssv)
48894889

48904890
#ifdef PERL_ANY_COW
48914891
# define SVt_COW SVt_PV
4892-
SV *
4893-
Perl_sv_setsv_cow(pTHX_ SV *dsv, SV *ssv)
4892+
bool
4893+
Perl_sv_setsv_cow(pTHX_ SV **pdsv, SV *ssv)
48944894
{
48954895
STRLEN cur = SvCUR(ssv);
48964896
STRLEN len = SvLEN(ssv);
@@ -4901,6 +4901,8 @@ Perl_sv_setsv_cow(pTHX_ SV *dsv, SV *ssv)
49014901
#endif
49024902

49034903
PERL_ARGS_ASSERT_SV_SETSV_COW;
4904+
4905+
SV *dsv = *pdsv;
49044906
#ifdef DEBUGGING
49054907
if (DEBUG_C_TEST) {
49064908
PerlIO_printf(Perl_debug_log, "Fast copy on write: %p -> %p\n",
@@ -4955,6 +4957,7 @@ Perl_sv_setsv_cow(pTHX_ SV *dsv, SV *ssv)
49554957
sv_buf_to_ro(ssv);
49564958

49574959
common_exit:
4960+
*pdsv = dsv;
49584961
SvPV_set(dsv, new_pv);
49594962
SvFLAGS(dsv) = new_flags;
49604963
if (SvUTF8(ssv))
@@ -4965,7 +4968,7 @@ Perl_sv_setsv_cow(pTHX_ SV *dsv, SV *ssv)
49654968
if (DEBUG_C_TEST)
49664969
sv_dump(dsv);
49674970
#endif
4968-
return dsv;
4971+
return TRUE;
49694972
}
49704973
#endif
49714974

0 commit comments

Comments
 (0)