mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-30 15:38:06 +01:00
sh: Remove global state from nodes.c.
No functional change is intended.
This commit is contained in:
parent
2a8a46b161
commit
a83f6e1ad9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=291267
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user