Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 27c9cdd

Browse files
committed
Harmonize TOKENBUF_SIZE and stack buf sizes
The max identifier length depends on the max tokenbuf size, which went from 256 in perl5 to 1024 in cperl, mostly to speed up parsing with a larger parser buffer. Harmonize a few places which still kept a hardcoded 256. Fixes id:000099,sig:11,src:027197,op:havoc,rep:4 from #293 Use a larger IO buffer of 1024 for pp_backtick, when draining it for the sideeffect only. Get rid of unnecessary sv_gets COW logic. SvGROW already does add +1.
1 parent 284f609 commit 27c9cdd

File tree

6 files changed

+8
-14
lines changed

6 files changed

+8
-14
lines changed

doio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ S_openn_cleanup(pTHX_ GV *gv, IO *io, PerlIO *fp, char *mode, const char *oname,
670670
&& IoTYPE(io) != IoTYPE_WRONLY /* Dups of STD* filehandles already have */
671671
&& IoTYPE(io) != IoTYPE_RDONLY /* type so they aren't marked as sockets */
672672
) { /* on OS's that return 0 on fstat()ed pipe */
673-
char tmpbuf[256];
673+
char tmpbuf[256]; /* SOCK_MAXADDRLEN 255 */
674674
Sock_size_t buflen = sizeof tmpbuf;
675675
if (PerlSock_getsockname(fd, (struct sockaddr *)tmpbuf, &buflen) >= 0
676676
|| errno != ENOTSOCK)

mg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ Perl_magic_setenv(pTHX_ SV *sv, MAGIC *mg)
13031303
/* set MGf_TAINTEDDIR if any component of the new path is
13041304
* relative or world-writeable */
13051305
while (s < strend) {
1306-
char tmpbuf[256];
1306+
char tmpbuf[TOKENBUF_SIZE];
13071307
Stat_t st;
13081308
I32 i;
13091309
#ifdef __VMS /* Hmm. How do we get $Config{path_sep} from C? */

op.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12967,12 +12967,12 @@ Perl_ck_sort(pTHX_ OP *o)
1296712967
o->op_flags |= OPf_SPECIAL;
1296812968
}
1296912969
else if (IS_CONST_OP(kid) && kid->op_private & OPpCONST_BARE) {
12970-
char tmpbuf[256];
12970+
char tmpbuf[TOKENBUF_SIZE];
1297112971
STRLEN len;
1297212972
PADOFFSET off;
1297312973
const char * const name = SvPV(kSVOP_sv, len);
1297412974
*tmpbuf = '&';
12975-
assert (len < 256);
12975+
assert (len < TOKENBUF_SIZE);
1297612976
Copy(name, tmpbuf+1, len, char);
1297712977
off = pad_findmy_pvn(tmpbuf, len+1, SvUTF8(kSVOP_sv));
1297812978
if (off != NOT_IN_PAD) {

pp_sys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ PP(pp_backtick)
312312
PerlIO_apply_layers(aTHX_ fp,mode,type);
313313

314314
if (gimme == G_VOID) {
315-
char tmpbuf[256];
315+
char tmpbuf[1024];
316316
while (PerlIO_read(fp, tmpbuf, sizeof tmpbuf) > 0)
317317
NOOP;
318318
}

sv.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8636,13 +8636,7 @@ Perl_sv_gets(pTHX_ SV *const sv, PerlIO *const fp, STRLEN append)
86368636
if (fd >= 0 && (PerlLIO_fstat(fd, &st) == 0) && S_ISREG(st.st_mode)) {
86378637
const Off_t offset = PerlIO_tell(fp);
86388638
if (offset != (Off_t) -1 && (Off_t)(st.st_size + append) > offset) {
8639-
#ifdef PERL_COPY_ON_WRITE
8640-
/* Add an extra byte for the sake of copy-on-write's
8641-
* buffer reference count. */
8642-
(void) SvGROW(sv, (STRLEN)((st.st_size - offset) + append + 2));
8643-
#else
86448639
(void) SvGROW(sv, (STRLEN)((st.st_size - offset) + append + 1));
8645-
#endif
86468640
}
86478641
}
86488642
rsptr = NULL;

toke.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ S_def_coretype(pTHX_ SV *sv, const char *t1, int len)
556556

557557
static void
558558
S_no_such_class(pTHX_ char *s) {
559-
char tmpbuf[1024];
559+
char tmpbuf[TOKENBUF_SIZE];
560560
int len;
561561
PL_bufptr = s;
562562
len = my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
@@ -9468,7 +9468,7 @@ S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
94689468
return;
94699469
if (s - w <= 254) {
94709470
PADOFFSET off;
9471-
char tmpbuf[256];
9471+
char tmpbuf[TOKENBUF_SIZE];
94729472
Copy(w, tmpbuf+1, s - w, char);
94739473
*tmpbuf = '&';
94749474
off = pad_findmy_pvn(tmpbuf, s-w+1, 0);
@@ -13209,7 +13209,7 @@ Perl_parse_subsignature(pTHX)
1320913209
if (!typestash)
1321013210
typestash = find_in_coretypes(PL_tokenbuf, len);
1321113211
if (!typestash) {
13212-
char tmpbuf[1024];
13212+
char tmpbuf[TOKENBUF_SIZE];
1321313213
int len;
1321413214
PL_bufptr = s;
1321513215
len = my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);

0 commit comments

Comments
 (0)