/* pp_sort.c
*
- * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 by Larry Wall and others
+ * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+ * 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*/
/*
- * ...they shuffled back towards the rear of the line. 'No, not at the
- * rear!' the slave-driver shouted. 'Three files up. And stay there...
+ * ...they shuffled back towards the rear of the line. 'No, not at the
+ * rear!' the slave-driver shouted. 'Three files up. And stay there...
+ *
+ * [p.931 of _The Lord of the Rings_, VI/ii: "The Land of Shadow"]
*/
/* This file contains pp ("push/pop") functions that
if (r >= t) p = r = t; /* too short to care about */
else {
while (((cmp(aTHX_ *(p-1), *p) > 0) == sense) &&
- ((p -= 2) > q));
+ ((p -= 2) > q)) {}
if (p <= q) {
/* b through r is a (long) run.
** Extend it as far as possible.
static I32
-cmp_desc(pTHX_ gptr a, gptr b)
+cmp_desc(pTHX_ gptr const a, gptr const b)
{
dVAR;
return -PL_sort_RealCmp(aTHX_ a, b);
static I32
-cmpindir(pTHX_ gptr a, gptr b)
+cmpindir(pTHX_ gptr const a, gptr const b)
{
dVAR;
gptr * const ap = (gptr *)a;
}
static I32
-cmpindir_desc(pTHX_ gptr a, gptr b)
+cmpindir_desc(pTHX_ gptr const a, gptr const b)
{
dVAR;
gptr * const ap = (gptr *)a;
else {
cv = sv_2cv(*++MARK, &stash, &gv, 0);
if (cv && SvPOK(cv)) {
- const char * const proto = SvPV_nolen_const((SV*)cv);
+ const char * const proto = SvPV_nolen_const(MUTABLE_SV(cv));
if (proto && strEQ(proto, "$$")) {
hasargs = TRUE;
}
if (priv & OPpSORT_INPLACE) {
assert( MARK+1 == SP && *SP && SvTYPE(*SP) == SVt_PVAV);
(void)POPMARK; /* remove mark associated with ex-OP_AASSIGN */
- av = (AV*)(*SP);
+ av = MUTABLE_AV((*SP));
max = AvFILL(av) + 1;
if (SvMAGICAL(av)) {
MEXTEND(SP, max);
- p2 = SP;
for (i=0; i < max; i++) {
SV **svp = av_fetch(av, i, FALSE);
*SP++ = (svp) ? *svp : NULL;
}
+ SP--;
+ p1 = p2 = SP - (max-1);
}
else {
if (SvREADONLY(av))
- Perl_croak(aTHX_ PL_no_modify);
+ Perl_croak(aTHX_ "%s", PL_no_modify);
else
SvREADONLY_on(av);
p1 = p2 = AvARRAY(av);
if (hasargs) {
/* This is mostly copied from pp_entersub */
- AV * const av = (AV*)PAD_SVl(0);
+ AV * const av = MUTABLE_AV(PAD_SVl(0));
cx->blk_sub.savearray = GvAV(PL_defgv);
- GvAV(PL_defgv) = (AV*)SvREFCNT_inc_simple(av);
+ GvAV(PL_defgv) = MUTABLE_AV(SvREFCNT_inc_simple(av));
CX_CURPAD_SAVE(cx->blk_sub);
cx->blk_sub.argarray = av;
}
SvREADONLY_off(av);
else if (av && !sorting_av) {
/* simulate pp_aassign of tied AV */
- SV** const base = ORIGMARK+1;
+ SV** const base = MARK+1;
for (i=0; i < max; i++) {
base[i] = newSVsv(base[i]);
}
}
static I32
-S_sortcv(pTHX_ SV *a, SV *b)
+S_sortcv(pTHX_ SV *const a, SV *const b)
{
dVAR;
const I32 oldsaveix = PL_savestack_ix;
}
static I32
-S_sortcv_stacked(pTHX_ SV *a, SV *b)
+S_sortcv_stacked(pTHX_ SV *const a, SV *const b)
{
dVAR;
const I32 oldsaveix = PL_savestack_ix;
}
static I32
-S_sortcv_xsub(pTHX_ SV *a, SV *b)
+S_sortcv_xsub(pTHX_ SV *const a, SV *const b)
{
dVAR; dSP;
const I32 oldsaveix = PL_savestack_ix;
const I32 oldscopeix = PL_scopestack_ix;
- CV * const cv=(CV*)PL_sortcop;
+ CV * const cv=MUTABLE_CV(PL_sortcop);
I32 result;
PERL_ARGS_ASSERT_SORTCV_XSUB;
static I32
-S_sv_ncmp(pTHX_ SV *a, SV *b)
+S_sv_ncmp(pTHX_ SV *const a, SV *const b)
{
const NV nv1 = SvNSIV(a);
const NV nv2 = SvNSIV(b);
}
static I32
-S_sv_i_ncmp(pTHX_ SV *a, SV *b)
+S_sv_i_ncmp(pTHX_ SV *const a, SV *const b)
{
const IV iv1 = SvIV(a);
const IV iv2 = SvIV(b);
#define SORT_NORMAL_RETURN_VALUE(val) (((val) > 0) ? 1 : ((val) ? -1 : 0))
static I32
-S_amagic_ncmp(pTHX_ register SV *a, register SV *b)
+S_amagic_ncmp(pTHX_ register SV *const a, register SV *const b)
{
dVAR;
SV * const tmpsv = tryCALL_AMAGICbin(a,b,ncmp);
}
static I32
-S_amagic_i_ncmp(pTHX_ register SV *a, register SV *b)
+S_amagic_i_ncmp(pTHX_ register SV *const a, register SV *const b)
{
dVAR;
SV * const tmpsv = tryCALL_AMAGICbin(a,b,ncmp);
}
static I32
-S_amagic_cmp(pTHX_ register SV *str1, register SV *str2)
+S_amagic_cmp(pTHX_ register SV *const str1, register SV *const str2)
{
dVAR;
SV * const tmpsv = tryCALL_AMAGICbin(str1,str2,scmp);
}
static I32
-S_amagic_cmp_locale(pTHX_ register SV *str1, register SV *str2)
+S_amagic_cmp_locale(pTHX_ register SV *const str1, register SV *const str2)
{
dVAR;
SV * const tmpsv = tryCALL_AMAGICbin(str1,str2,scmp);