mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-21 16:32:25 +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
|
else
|
||||||
fputs(" return NULL;\n", cfile);
|
fputs(" return NULL;\n", cfile);
|
||||||
if (calcsize)
|
if (calcsize)
|
||||||
fputs(" funcblocksize += nodesize[n->type];\n", cfile);
|
fputs(" result->blocksize += nodesize[n->type];\n", cfile);
|
||||||
else {
|
else {
|
||||||
fputs(" new = funcblock;\n", cfile);
|
fputs(" new = state->block;\n", cfile);
|
||||||
fputs(" funcblock = (char *)funcblock + nodesize[n->type];\n", cfile);
|
fputs(" state->block = (char *)state->block + nodesize[n->type];\n", cfile);
|
||||||
}
|
}
|
||||||
fputs(" switch (n->type) {\n", cfile);
|
fputs(" switch (n->type) {\n", cfile);
|
||||||
for (sp = str ; sp < &str[nstr] ; sp++) {
|
for (sp = str ; sp < &str[nstr] ; sp++) {
|
||||||
@ -313,33 +313,33 @@ outfunc(FILE *cfile, int calcsize)
|
|||||||
case T_NODE:
|
case T_NODE:
|
||||||
if (calcsize) {
|
if (calcsize) {
|
||||||
indent(12, cfile);
|
indent(12, cfile);
|
||||||
fprintf(cfile, "calcsize(n->%s.%s);\n",
|
fprintf(cfile, "calcsize(n->%s.%s, result);\n",
|
||||||
sp->tag, fp->name);
|
sp->tag, fp->name);
|
||||||
} else {
|
} else {
|
||||||
indent(12, cfile);
|
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);
|
sp->tag, fp->name, sp->tag, fp->name);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case T_NODELIST:
|
case T_NODELIST:
|
||||||
if (calcsize) {
|
if (calcsize) {
|
||||||
indent(12, cfile);
|
indent(12, cfile);
|
||||||
fprintf(cfile, "sizenodelist(n->%s.%s);\n",
|
fprintf(cfile, "sizenodelist(n->%s.%s, result);\n",
|
||||||
sp->tag, fp->name);
|
sp->tag, fp->name);
|
||||||
} else {
|
} else {
|
||||||
indent(12, cfile);
|
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);
|
sp->tag, fp->name, sp->tag, fp->name);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
if (calcsize) {
|
if (calcsize) {
|
||||||
indent(12, cfile);
|
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);
|
sp->tag, fp->name);
|
||||||
} else {
|
} else {
|
||||||
indent(12, cfile);
|
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);
|
sp->tag, fp->name, sp->tag, fp->name);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -46,19 +46,24 @@
|
|||||||
#include "mystring.h"
|
#include "mystring.h"
|
||||||
|
|
||||||
|
|
||||||
static int funcblocksize; /* size of structures in function */
|
struct nodesize {
|
||||||
static int funcstringsize; /* size of strings in node */
|
int blocksize; /* size of structures in function */
|
||||||
static pointer funcblock; /* block to allocate function from */
|
int stringsize; /* size of strings in node */
|
||||||
static char *funcstring; /* block to allocate strings from */
|
};
|
||||||
|
|
||||||
|
struct nodecopystate {
|
||||||
|
pointer block; /* block to allocate function from */
|
||||||
|
char *string; /* block to allocate strings from */
|
||||||
|
};
|
||||||
|
|
||||||
%SIZES
|
%SIZES
|
||||||
|
|
||||||
|
|
||||||
static void calcsize(union node *);
|
static void calcsize(union node *, struct nodesize *);
|
||||||
static void sizenodelist(struct nodelist *);
|
static void sizenodelist(struct nodelist *, struct nodesize *);
|
||||||
static union node *copynode(union node *);
|
static union node *copynode(union node *, struct nodecopystate *);
|
||||||
static struct nodelist *copynodelist(struct nodelist *);
|
static struct nodelist *copynodelist(struct nodelist *, struct nodecopystate *);
|
||||||
static char *nodesavestr(const char *);
|
static char *nodesavestr(const char *, struct nodecopystate *);
|
||||||
|
|
||||||
|
|
||||||
struct funcdef {
|
struct funcdef {
|
||||||
@ -73,18 +78,20 @@ struct funcdef {
|
|||||||
struct funcdef *
|
struct funcdef *
|
||||||
copyfunc(union node *n)
|
copyfunc(union node *n)
|
||||||
{
|
{
|
||||||
|
struct nodesize sz;
|
||||||
|
struct nodecopystate st;
|
||||||
struct funcdef *fn;
|
struct funcdef *fn;
|
||||||
|
|
||||||
if (n == NULL)
|
if (n == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
funcblocksize = offsetof(struct funcdef, n);
|
sz.blocksize = offsetof(struct funcdef, n);
|
||||||
funcstringsize = 0;
|
sz.stringsize = 0;
|
||||||
calcsize(n);
|
calcsize(n, &sz);
|
||||||
fn = ckmalloc(funcblocksize + funcstringsize);
|
fn = ckmalloc(sz.blocksize + sz.stringsize);
|
||||||
fn->refcount = 1;
|
fn->refcount = 1;
|
||||||
funcblock = (char *)fn + offsetof(struct funcdef, n);
|
st.block = (char *)fn + offsetof(struct funcdef, n);
|
||||||
funcstring = (char *)fn + funcblocksize;
|
st.string = (char *)fn + sz.blocksize;
|
||||||
copynode(n);
|
copynode(n, &st);
|
||||||
return fn;
|
return fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +104,7 @@ getfuncnode(struct funcdef *fn)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
calcsize(union node *n)
|
calcsize(union node *n, struct nodesize *result)
|
||||||
{
|
{
|
||||||
%CALCSIZE
|
%CALCSIZE
|
||||||
}
|
}
|
||||||
@ -105,11 +112,11 @@ calcsize(union node *n)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sizenodelist(struct nodelist *lp)
|
sizenodelist(struct nodelist *lp, struct nodesize *result)
|
||||||
{
|
{
|
||||||
while (lp) {
|
while (lp) {
|
||||||
funcblocksize += ALIGN(sizeof(struct nodelist));
|
result->blocksize += ALIGN(sizeof(struct nodelist));
|
||||||
calcsize(lp->n);
|
calcsize(lp->n, result);
|
||||||
lp = lp->next;
|
lp = lp->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +124,7 @@ sizenodelist(struct nodelist *lp)
|
|||||||
|
|
||||||
|
|
||||||
static union node *
|
static union node *
|
||||||
copynode(union node *n)
|
copynode(union node *n, struct nodecopystate *state)
|
||||||
{
|
{
|
||||||
union node *new;
|
union node *new;
|
||||||
|
|
||||||
@ -127,16 +134,17 @@ copynode(union node *n)
|
|||||||
|
|
||||||
|
|
||||||
static struct nodelist *
|
static struct nodelist *
|
||||||
copynodelist(struct nodelist *lp)
|
copynodelist(struct nodelist *lp, struct nodecopystate *state)
|
||||||
{
|
{
|
||||||
struct nodelist *start;
|
struct nodelist *start;
|
||||||
struct nodelist **lpp;
|
struct nodelist **lpp;
|
||||||
|
|
||||||
lpp = &start;
|
lpp = &start;
|
||||||
while (lp) {
|
while (lp) {
|
||||||
*lpp = funcblock;
|
*lpp = state->block;
|
||||||
funcblock = (char *)funcblock + ALIGN(sizeof(struct nodelist));
|
state->block = (char *)state->block +
|
||||||
(*lpp)->n = copynode(lp->n);
|
ALIGN(sizeof(struct nodelist));
|
||||||
|
(*lpp)->n = copynode(lp->n, state);
|
||||||
lp = lp->next;
|
lp = lp->next;
|
||||||
lpp = &(*lpp)->next;
|
lpp = &(*lpp)->next;
|
||||||
}
|
}
|
||||||
@ -147,15 +155,15 @@ copynodelist(struct nodelist *lp)
|
|||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
nodesavestr(const char *s)
|
nodesavestr(const char *s, struct nodecopystate *state)
|
||||||
{
|
{
|
||||||
const char *p = s;
|
const char *p = s;
|
||||||
char *q = funcstring;
|
char *q = state->string;
|
||||||
char *rtn = funcstring;
|
char *rtn = state->string;
|
||||||
|
|
||||||
while ((*q++ = *p++) != '\0')
|
while ((*q++ = *p++) != '\0')
|
||||||
continue;
|
continue;
|
||||||
funcstring = q;
|
state->string = q;
|
||||||
return rtn;
|
return rtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user