Skip to content

Commit c2697a0

Browse files
committed
Consistently use size_t as array count/index in OP_MULTIPARAM
Recently-added code was written largely by copying existing practices in various places. In particular, much of the original code was using `UV` typed variables to store sizes and indexes in various list or array structures, counts of parameters, and so on. On fully 64-bit platforms this is all fine, but on 32-bit platforms with -Duse64bitint enabled, this is a 64-bit integer that won't ever be counting that high. These values might as well be stored as 32-bit integers in that case.
1 parent f372896 commit c2697a0

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

dump.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,13 +1786,13 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o,
17861786
case OP_MULTIPARAM:
17871787
{
17881788
struct op_multiparam_aux *aux = (struct op_multiparam_aux *)cUNOP_AUXo->op_aux;
1789-
UV min_args = aux->min_args;
1790-
UV n_positional = aux->n_positional;
1789+
size_t min_args = aux->min_args;
1790+
size_t n_positional = aux->n_positional;
17911791
if(n_positional > min_args)
1792-
S_opdump_indent(aTHX_ o, level, bar, file, "ARGS = %" UVuf " .. %" UVuf "\n",
1792+
S_opdump_indent(aTHX_ o, level, bar, file, "ARGS = %zu .. %zu\n",
17931793
min_args, n_positional);
17941794
else
1795-
S_opdump_indent(aTHX_ o, level, bar, file, "ARGS = %" UVuf "\n",
1795+
S_opdump_indent(aTHX_ o, level, bar, file, "ARGS = %zu\n",
17961796
min_args);
17971797

17981798
for(Size_t i = 0; i < n_positional; i++) {

ext/B/B.xs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,12 +1397,12 @@ aux_list(o, cv)
13971397
case OP_MULTIPARAM:
13981398
{
13991399
struct op_multiparam_aux *p = (struct op_multiparam_aux *)aux;
1400-
UV nparams = p->n_positional;
1400+
size_t nparams = p->n_positional;
14011401
EXTEND(SP, (IV)(3 + nparams + 1));
14021402
mPUSHu(p->min_args);
14031403
mPUSHu(p->n_positional);
14041404
PUSHs(sv_2mortal(p->slurpy ? newSVpvf("%c", p->slurpy) : &PL_sv_no));
1405-
for(UV parami = 0; parami < nparams; parami++)
1405+
for(size_t parami = 0; parami < nparams; parami++)
14061406
mPUSHu(p->param_padix[parami]);
14071407
mPUSHu(p->slurpy_padix);
14081408
XSRETURN(3 + nparams + 1);

ext/XS-APItest/APItest.xs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,14 +1204,14 @@ static OP *THX_parse_keyword_subsignature(pTHX)
12041204
struct op_multiparam_aux *p =
12051205
(struct op_multiparam_aux *)(cUNOP_AUXx(kid)->op_aux);
12061206
PADNAMELIST *names = PadlistNAMES(CvPADLIST(find_runcv(0)));
1207-
SV *retsv = newSVpvf("multiparam:%" UVuf "..%" UVuf ":%c",
1207+
SV *retsv = newSVpvf("multiparam:%zu..%zu:%c",
12081208
p->min_args, p->n_positional, p->slurpy ? p->slurpy : '-');
1209-
for (UV paramidx = 0; paramidx < p->n_positional; paramidx++) {
1209+
for (size_t paramidx = 0; paramidx < p->n_positional; paramidx++) {
12101210
char *namepv = PadnamePV(padnamelist_fetch(names, p->param_padix[paramidx]));
12111211
if(namepv)
1212-
sv_catpvf(retsv, ":%s=%" UVf, namepv, paramidx);
1212+
sv_catpvf(retsv, ":%s=%zu", namepv, paramidx);
12131213
else
1214-
sv_catpvf(retsv, ":(anon)=%" UVf, paramidx);
1214+
sv_catpvf(retsv, ":(anon)=%zu", paramidx);
12151215
if(paramidx >= p->min_args)
12161216
sv_catpvs(retsv, "?");
12171217
}

op.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16562,7 +16562,7 @@ Perl_rcpv_copy(pTHX_ char *pv) {
1656216562
/* Subroutine signature parsing */
1656316563

1656416564
struct yy_parser_signature_param {
16565-
UV argix; /* positional index of the param */
16565+
size_t argix; /* positional index of the param */
1656616566
PADOFFSET padix; /* pad index of the var holding the param */
1656716567
OP *defcop;
1656816568
OPCODE defmode;
@@ -16595,7 +16595,7 @@ destroy_subsignature_context(pTHX_ void *p)
1659516595
yy_parser_signature *signature = (yy_parser_signature *)p;
1659616596

1659716597
if(signature->params) {
16598-
for(UV parami = 0; parami < signature->nparams; parami++) {
16598+
for(size_t parami = 0; parami < signature->nparams; parami++) {
1659916599
struct yy_parser_signature_param *param = signature->params + parami;
1660016600

1660116601
if(param->defcop)
@@ -16830,7 +16830,7 @@ Perl_subsignature_finish(pTHX)
1683016830
sigops = op_append_elem(OP_LINESEQ, sigops,
1683116831
newSTATEOP(0, NULL, NULL));
1683216832

16833-
UV end_argix = signature->next_argix;
16833+
size_t end_argix = signature->next_argix;
1683416834

1683516835
struct op_multiparam_aux *aux = (struct op_multiparam_aux *)PerlMemShared_malloc(
1683616836
sizeof(struct op_multiparam_aux) + (end_argix * sizeof(PADOFFSET)));
@@ -16861,12 +16861,12 @@ Perl_subsignature_finish(pTHX)
1686116861
}
1686216862

1686316863
struct yy_parser_signature_param *params = signature->params;
16864-
UV max_argix = 0;
16864+
size_t max_argix = 0;
1686516865

16866-
for(UV parami = 0; parami < signature->nparams; parami++) {
16866+
for(size_t parami = 0; parami < signature->nparams; parami++) {
1686716867
struct yy_parser_signature_param *param = params + parami;
1686816868

16869-
UV argix = param->argix;
16869+
size_t argix = param->argix;
1687016870
PADOFFSET padix = param->padix;
1687116871

1687216872
while(max_argix < argix) {

op.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,8 @@ struct op_argcheck_aux {
11921192
/* for OP_MULTIPARAM */
11931193

11941194
struct op_multiparam_aux {
1195-
UV min_args; /* = the number of mandatory scalar parameters */
1196-
UV n_positional; /* = the number of mandatory + optional scalar parameters, not counting a final slurpy */
1195+
size_t min_args; /* = the number of mandatory scalar parameters */
1196+
size_t n_positional; /* = the number of mandatory + optional scalar parameters, not counting a final slurpy */
11971197
char slurpy;
11981198
PADOFFSET *param_padix; /* points at storage allocated along with the struct itself, immediately following */
11991199
PADOFFSET slurpy_padix;

pp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7889,17 +7889,17 @@ PP(pp_argcheck)
78897889
PP(pp_multiparam)
78907890
{
78917891
struct op_multiparam_aux *aux = (struct op_multiparam_aux *)cUNOP_AUX->op_aux;
7892-
UV nparams = aux->n_positional;
7892+
size_t nparams = aux->n_positional;
78937893
char slurpy = aux->slurpy;
78947894
PADOFFSET *param_padix = aux->param_padix;
78957895
AV *defav = GvAV(PL_defgv); /* @_ */
78967896

78977897
assert(!SvMAGICAL(defav));
7898-
UV argc = (UV)(AvFILLp(defav) + 1);
7898+
size_t argc = (AvFILLp(defav) + 1);
78997899

79007900
S_check_argc(aTHX_ argc, nparams, nparams - aux->min_args, slurpy);
79017901

7902-
UV parami;
7902+
size_t parami;
79037903
for(parami = 0; parami < nparams; parami++) {
79047904
PADOFFSET padix = param_padix[parami];
79057905
if(!padix) {
@@ -7949,7 +7949,7 @@ PP(pp_multiparam)
79497949

79507950
av_extend(av, argc);
79517951

7952-
IV avidx = 0;
7952+
size_t avidx = 0;
79537953
for(; argc; parami++, argc--) {
79547954
SV **valp = av_fetch(defav, parami, FALSE);
79557955
SV *val = valp ? *valp : &PL_sv_undef;

0 commit comments

Comments
 (0)