From owner-svn-src-all@freebsd.org Tue Nov 24 22:47:20 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 70675A37689; Tue, 24 Nov 2015 22:47:20 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4306D1967; Tue, 24 Nov 2015 22:47:20 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tAOMlJcb037497; Tue, 24 Nov 2015 22:47:19 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAOMlJgr037495; Tue, 24 Nov 2015 22:47:19 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201511242247.tAOMlJgr037495@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Tue, 24 Nov 2015 22:47:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291267 - head/bin/sh X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Nov 2015 22:47:20 -0000 Author: jilles Date: Tue Nov 24 22:47:19 2015 New Revision: 291267 URL: https://svnweb.freebsd.org/changeset/base/291267 Log: sh: Remove global state from nodes.c. No functional change is intended. Modified: head/bin/sh/mknodes.c head/bin/sh/nodes.c.pat Modified: head/bin/sh/mknodes.c ============================================================================== --- head/bin/sh/mknodes.c Tue Nov 24 19:55:11 2015 (r291266) +++ head/bin/sh/mknodes.c Tue Nov 24 22:47:19 2015 (r291267) @@ -296,10 +296,10 @@ outfunc(FILE *cfile, int calcsize) else fputs(" return NULL;\n", cfile); if (calcsize) - fputs(" funcblocksize += nodesize[n->type];\n", cfile); + fputs(" result->blocksize += nodesize[n->type];\n", cfile); else { - fputs(" new = funcblock;\n", cfile); - fputs(" funcblock = (char *)funcblock + nodesize[n->type];\n", cfile); + fputs(" new = state->block;\n", cfile); + fputs(" state->block = (char *)state->block + nodesize[n->type];\n", cfile); } fputs(" switch (n->type) {\n", cfile); for (sp = str ; sp < &str[nstr] ; sp++) { @@ -313,33 +313,33 @@ outfunc(FILE *cfile, int calcsize) case T_NODE: if (calcsize) { indent(12, cfile); - fprintf(cfile, "calcsize(n->%s.%s);\n", + fprintf(cfile, "calcsize(n->%s.%s, result);\n", sp->tag, fp->name); } else { indent(12, cfile); - fprintf(cfile, "new->%s.%s = copynode(n->%s.%s);\n", + fprintf(cfile, "new->%s.%s = copynode(n->%s.%s, state);\n", sp->tag, fp->name, sp->tag, fp->name); } break; case T_NODELIST: if (calcsize) { indent(12, cfile); - fprintf(cfile, "sizenodelist(n->%s.%s);\n", + fprintf(cfile, "sizenodelist(n->%s.%s, result);\n", sp->tag, fp->name); } else { indent(12, cfile); - fprintf(cfile, "new->%s.%s = copynodelist(n->%s.%s);\n", + fprintf(cfile, "new->%s.%s = copynodelist(n->%s.%s, state);\n", sp->tag, fp->name, sp->tag, fp->name); } break; case T_STRING: if (calcsize) { indent(12, cfile); - fprintf(cfile, "funcstringsize += strlen(n->%s.%s) + 1;\n", + fprintf(cfile, "result->stringsize += strlen(n->%s.%s) + 1;\n", sp->tag, fp->name); } else { indent(12, cfile); - fprintf(cfile, "new->%s.%s = nodesavestr(n->%s.%s);\n", + fprintf(cfile, "new->%s.%s = nodesavestr(n->%s.%s, state);\n", sp->tag, fp->name, sp->tag, fp->name); } break; Modified: head/bin/sh/nodes.c.pat ============================================================================== --- head/bin/sh/nodes.c.pat Tue Nov 24 19:55:11 2015 (r291266) +++ head/bin/sh/nodes.c.pat Tue Nov 24 22:47:19 2015 (r291267) @@ -46,19 +46,24 @@ #include "mystring.h" -static int funcblocksize; /* size of structures in function */ -static int funcstringsize; /* size of strings in node */ -static pointer funcblock; /* block to allocate function from */ -static char *funcstring; /* block to allocate strings from */ +struct nodesize { + int blocksize; /* size of structures in function */ + int stringsize; /* size of strings in node */ +}; + +struct nodecopystate { + pointer block; /* block to allocate function from */ + char *string; /* block to allocate strings from */ +}; %SIZES -static void calcsize(union node *); -static void sizenodelist(struct nodelist *); -static union node *copynode(union node *); -static struct nodelist *copynodelist(struct nodelist *); -static char *nodesavestr(const char *); +static void calcsize(union node *, struct nodesize *); +static void sizenodelist(struct nodelist *, struct nodesize *); +static union node *copynode(union node *, struct nodecopystate *); +static struct nodelist *copynodelist(struct nodelist *, struct nodecopystate *); +static char *nodesavestr(const char *, struct nodecopystate *); struct funcdef { @@ -73,18 +78,20 @@ struct funcdef { struct funcdef * copyfunc(union node *n) { + struct nodesize sz; + struct nodecopystate st; struct funcdef *fn; if (n == NULL) return NULL; - funcblocksize = offsetof(struct funcdef, n); - funcstringsize = 0; - calcsize(n); - fn = ckmalloc(funcblocksize + funcstringsize); + sz.blocksize = offsetof(struct funcdef, n); + sz.stringsize = 0; + calcsize(n, &sz); + fn = ckmalloc(sz.blocksize + sz.stringsize); fn->refcount = 1; - funcblock = (char *)fn + offsetof(struct funcdef, n); - funcstring = (char *)fn + funcblocksize; - copynode(n); + st.block = (char *)fn + offsetof(struct funcdef, n); + st.string = (char *)fn + sz.blocksize; + copynode(n, &st); return fn; } @@ -97,7 +104,7 @@ getfuncnode(struct funcdef *fn) static void -calcsize(union node *n) +calcsize(union node *n, struct nodesize *result) { %CALCSIZE } @@ -105,11 +112,11 @@ calcsize(union node *n) static void -sizenodelist(struct nodelist *lp) +sizenodelist(struct nodelist *lp, struct nodesize *result) { while (lp) { - funcblocksize += ALIGN(sizeof(struct nodelist)); - calcsize(lp->n); + result->blocksize += ALIGN(sizeof(struct nodelist)); + calcsize(lp->n, result); lp = lp->next; } } @@ -117,7 +124,7 @@ sizenodelist(struct nodelist *lp) static union node * -copynode(union node *n) +copynode(union node *n, struct nodecopystate *state) { union node *new; @@ -127,16 +134,17 @@ copynode(union node *n) static struct nodelist * -copynodelist(struct nodelist *lp) +copynodelist(struct nodelist *lp, struct nodecopystate *state) { struct nodelist *start; struct nodelist **lpp; lpp = &start; while (lp) { - *lpp = funcblock; - funcblock = (char *)funcblock + ALIGN(sizeof(struct nodelist)); - (*lpp)->n = copynode(lp->n); + *lpp = state->block; + state->block = (char *)state->block + + ALIGN(sizeof(struct nodelist)); + (*lpp)->n = copynode(lp->n, state); lp = lp->next; lpp = &(*lpp)->next; } @@ -147,15 +155,15 @@ copynodelist(struct nodelist *lp) static char * -nodesavestr(const char *s) +nodesavestr(const char *s, struct nodecopystate *state) { const char *p = s; - char *q = funcstring; - char *rtn = funcstring; + char *q = state->string; + char *rtn = state->string; while ((*q++ = *p++) != '\0') continue; - funcstring = q; + state->string = q; return rtn; }