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

Commit

Permalink
Harmonize TOKENBUF_SIZE and stack buf sizes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rurban committed Jun 18, 2017
1 parent 284f609 commit 27c9cdd
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doio.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ S_openn_cleanup(pTHX_ GV *gv, IO *io, PerlIO *fp, char *mode, const char *oname,
&& IoTYPE(io) != IoTYPE_WRONLY /* Dups of STD* filehandles already have */
&& IoTYPE(io) != IoTYPE_RDONLY /* type so they aren't marked as sockets */
) { /* on OS's that return 0 on fstat()ed pipe */
char tmpbuf[256];
char tmpbuf[256]; /* SOCK_MAXADDRLEN 255 */
Sock_size_t buflen = sizeof tmpbuf;
if (PerlSock_getsockname(fd, (struct sockaddr *)tmpbuf, &buflen) >= 0
|| errno != ENOTSOCK)
Expand Down
2 changes: 1 addition & 1 deletion mg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ Perl_magic_setenv(pTHX_ SV *sv, MAGIC *mg)
/* set MGf_TAINTEDDIR if any component of the new path is
* relative or world-writeable */
while (s < strend) {
char tmpbuf[256];
char tmpbuf[TOKENBUF_SIZE];
Stat_t st;
I32 i;
#ifdef __VMS /* Hmm. How do we get $Config{path_sep} from C? */
Expand Down
4 changes: 2 additions & 2 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -12967,12 +12967,12 @@ Perl_ck_sort(pTHX_ OP *o)
o->op_flags |= OPf_SPECIAL;
}
else if (IS_CONST_OP(kid) && kid->op_private & OPpCONST_BARE) {
char tmpbuf[256];
char tmpbuf[TOKENBUF_SIZE];
STRLEN len;
PADOFFSET off;
const char * const name = SvPV(kSVOP_sv, len);
*tmpbuf = '&';
assert (len < 256);
assert (len < TOKENBUF_SIZE);
Copy(name, tmpbuf+1, len, char);
off = pad_findmy_pvn(tmpbuf, len+1, SvUTF8(kSVOP_sv));
if (off != NOT_IN_PAD) {
Expand Down
2 changes: 1 addition & 1 deletion pp_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ PP(pp_backtick)
PerlIO_apply_layers(aTHX_ fp,mode,type);

if (gimme == G_VOID) {
char tmpbuf[256];
char tmpbuf[1024];
while (PerlIO_read(fp, tmpbuf, sizeof tmpbuf) > 0)
NOOP;
}
Expand Down
6 changes: 0 additions & 6 deletions sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -8636,13 +8636,7 @@ Perl_sv_gets(pTHX_ SV *const sv, PerlIO *const fp, STRLEN append)
if (fd >= 0 && (PerlLIO_fstat(fd, &st) == 0) && S_ISREG(st.st_mode)) {
const Off_t offset = PerlIO_tell(fp);
if (offset != (Off_t) -1 && (Off_t)(st.st_size + append) > offset) {
#ifdef PERL_COPY_ON_WRITE
/* Add an extra byte for the sake of copy-on-write's
* buffer reference count. */
(void) SvGROW(sv, (STRLEN)((st.st_size - offset) + append + 2));
#else
(void) SvGROW(sv, (STRLEN)((st.st_size - offset) + append + 1));
#endif
}
}
rsptr = NULL;
Expand Down
6 changes: 3 additions & 3 deletions toke.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ S_def_coretype(pTHX_ SV *sv, const char *t1, int len)

static void
S_no_such_class(pTHX_ char *s) {
char tmpbuf[1024];
char tmpbuf[TOKENBUF_SIZE];
int len;
PL_bufptr = s;
len = my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
Expand Down Expand Up @@ -9468,7 +9468,7 @@ S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
return;
if (s - w <= 254) {
PADOFFSET off;
char tmpbuf[256];
char tmpbuf[TOKENBUF_SIZE];
Copy(w, tmpbuf+1, s - w, char);
*tmpbuf = '&';
off = pad_findmy_pvn(tmpbuf, s-w+1, 0);
Expand Down Expand Up @@ -13209,7 +13209,7 @@ Perl_parse_subsignature(pTHX)
if (!typestash)
typestash = find_in_coretypes(PL_tokenbuf, len);
if (!typestash) {
char tmpbuf[1024];
char tmpbuf[TOKENBUF_SIZE];
int len;
PL_bufptr = s;
len = my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
Expand Down

0 comments on commit 27c9cdd

Please sign in to comment.