summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2010-12-27 08:22:21 +0000
committerNicholas Clark <nick@ccl4.org>2010-12-27 08:22:21 +0000
commit2f9970be002ee78a22fc687876139eedc9eb3a65 (patch)
tree675d2ea2057c047a2331d7dc73c254b27f1ab0c3
parent20cf1f79230fba6e0a6ba5053785e5fc841ee053 (diff)
downloadperl-2f9970be002ee78a22fc687876139eedc9eb3a65.tar.gz
Convert Perl_do_chomp() to the same prototype as Perl_do_chop().
Pass in an SV to hold the count, rather than returning the count.
-rw-r--r--doop.c27
-rw-r--r--embed.fnc2
-rw-r--r--embed.h2
-rw-r--r--pp.c8
-rw-r--r--proto.h7
5 files changed, 23 insertions, 23 deletions
diff --git a/doop.c b/doop.c
index 550e6fb2b6..1b71fe1e73 100644
--- a/doop.c
+++ b/doop.c
@@ -1060,11 +1060,10 @@ Perl_do_chop(pTHX_ register SV *astr, register SV *sv)
SvSETMAGIC(sv);
}
-I32
-Perl_do_chomp(pTHX_ register SV *sv)
+void
+Perl_do_chomp(pTHX_ SV *count, SV *sv)
{
dVAR;
- register I32 count;
STRLEN len;
char *s;
char *temp_buffer = NULL;
@@ -1073,10 +1072,9 @@ Perl_do_chomp(pTHX_ register SV *sv)
PERL_ARGS_ASSERT_DO_CHOMP;
if (RsSNARF(PL_rs))
- return 0;
+ return;
if (RsRECORD(PL_rs))
- return 0;
- count = 0;
+ return;
if (SvTYPE(sv) == SVt_PVAV) {
register I32 i;
AV *const av = MUTABLE_AV(sv);
@@ -1085,17 +1083,17 @@ Perl_do_chomp(pTHX_ register SV *sv)
for (i = 0; i <= max; i++) {
sv = MUTABLE_SV(av_fetch(av, i, FALSE));
if (sv && ((sv = *(SV**)sv), sv != &PL_sv_undef))
- count += do_chomp(sv);
+ do_chomp(count, sv);
}
- return count;
+ return;
}
else if (SvTYPE(sv) == SVt_PVHV) {
HV* const hv = MUTABLE_HV(sv);
HE* entry;
(void)hv_iterinit(hv);
while ((entry = hv_iternext(hv)))
- count += do_chomp(hv_iterval(hv,entry));
- return count;
+ do_chomp(count, hv_iterval(hv,entry));
+ return;
}
else if (SvREADONLY(sv)) {
if (SvFAKE(sv)) {
@@ -1123,11 +1121,11 @@ Perl_do_chomp(pTHX_ register SV *sv)
if (RsPARA(PL_rs)) {
if (*s != '\n')
goto nope;
- ++count;
+ ++SvIVX(count);
while (len && s[-1] == '\n') {
--len;
--s;
- ++count;
+ ++SvIVX(count);
}
}
else {
@@ -1171,7 +1169,7 @@ Perl_do_chomp(pTHX_ register SV *sv)
if (rslen == 1) {
if (*s != *rsptr)
goto nope;
- ++count;
+ ++SvIVX(count);
}
else {
if (len < rslen - 1)
@@ -1180,7 +1178,7 @@ Perl_do_chomp(pTHX_ register SV *sv)
s -= rslen - 1;
if (memNE(s, rsptr, rslen))
goto nope;
- count += rs_charlen;
+ SvIVX(count) += rs_charlen;
}
}
s = SvPV_force_nolen(sv);
@@ -1194,7 +1192,6 @@ Perl_do_chomp(pTHX_ register SV *sv)
SvREFCNT_dec(svrecode);
Safefree(temp_buffer);
- return count;
}
void
diff --git a/embed.fnc b/embed.fnc
index ed1cd714c2..88129d7fd9 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -355,7 +355,7 @@ p |bool |do_print |NULLOK SV* sv|NN PerlIO* fp
: Used in pp_sys.c
pR |OP* |do_readline
: Used in pp.c
-p |I32 |do_chomp |NN SV* sv
+p |void |do_chomp |NN SV *count|NN SV *sv
: Defined in doio.c, used only in pp_sys.c
p |bool |do_seek |NULLOK GV* gv|Off_t pos|int whence
Ap |void |do_sprintf |NN SV* sv|I32 len|NN SV** sarg
diff --git a/embed.h b/embed.h
index 5f846f5545..a427ef563c 100644
--- a/embed.h
+++ b/embed.h
@@ -974,7 +974,7 @@
#define delete_eval_scope() Perl_delete_eval_scope(aTHX)
#define die_unwind(a) Perl_die_unwind(aTHX_ a)
#define do_aexec5(a,b,c,d,e) Perl_do_aexec5(aTHX_ a,b,c,d,e)
-#define do_chomp(a) Perl_do_chomp(aTHX_ a)
+#define do_chomp(a,b) Perl_do_chomp(aTHX_ a,b)
#define do_chop(a,b) Perl_do_chop(aTHX_ a,b)
#define do_dump_pad(a,b,c,d) Perl_do_dump_pad(aTHX_ a,b,c,d)
#define do_eof(a) Perl_do_eof(aTHX_ a)
diff --git a/pp.c b/pp.c
index 78b03eaeaf..ef325a9e30 100644
--- a/pp.c
+++ b/pp.c
@@ -812,17 +812,19 @@ PP(pp_chop)
PP(pp_schomp)
{
dVAR; dSP; dTARGET;
- SETi(do_chomp(TOPs));
+ sv_setiv(TARG, 0);
+ do_chomp(TARG, TOPs);
+ SETs(TARG);
RETURN;
}
PP(pp_chomp)
{
dVAR; dSP; dMARK; dTARGET; dORIGMARK;
- register I32 count = 0;
+ sv_setiv(TARG, 0);
while (MARK < SP)
- count += do_chomp(*++MARK);
+ do_chomp(TARG, *++MARK);
SP = ORIGMARK;
XPUSHTARG;
RETURN;
diff --git a/proto.h b/proto.h
index c4df3e20e2..1ee666e4cf 100644
--- a/proto.h
+++ b/proto.h
@@ -707,10 +707,11 @@ PERL_CALLCONV int Perl_do_binmode(pTHX_ PerlIO *fp, int iotype, int mode)
#define PERL_ARGS_ASSERT_DO_BINMODE \
assert(fp)
-PERL_CALLCONV I32 Perl_do_chomp(pTHX_ SV* sv)
- __attribute__nonnull__(pTHX_1);
+PERL_CALLCONV void Perl_do_chomp(pTHX_ SV *count, SV *sv)
+ __attribute__nonnull__(pTHX_1)
+ __attribute__nonnull__(pTHX_2);
#define PERL_ARGS_ASSERT_DO_CHOMP \
- assert(sv)
+ assert(count); assert(sv)
PERL_CALLCONV void Perl_do_chop(pTHX_ SV *astr, SV *sv)
__attribute__nonnull__(pTHX_1)