diff options
author | Haibo Huang <hhb@google.com> | 2020-10-28 22:26:43 -0700 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2020-10-28 22:26:43 -0700 |
commit | bdceef906196699a86d84e3a6f09cdfed69912fa (patch) | |
tree | 97abbea8299b2b48adabe7b0e3d9024f80d8bc67 | |
parent | 17b2964166ce94951753c80dad4111e39921cd68 (diff) | |
parent | 3b42cfaf73fbe63c1332f9cf2c8e4d90ab686f05 (diff) | |
download | one-true-awk-bdceef906196699a86d84e3a6f09cdfed69912fa.tar.gz |
Upgrade one-true-awk to 3b42cfaf73fbe63c1332f9cf2c8e4d90ab686f05
Test: make
Change-Id: Ibd96ade0e53207f9fe5675e6179cc448fceac0b4
-rw-r--r-- | FIXES | 4 | ||||
-rw-r--r-- | METADATA | 6 | ||||
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | b.c | 34 | ||||
-rw-r--r-- | lex.c | 6 | ||||
-rw-r--r-- | lib.c | 18 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | makefile | 2 | ||||
-rw-r--r-- | parse.c | 2 | ||||
-rw-r--r-- | run.c | 26 | ||||
-rw-r--r-- | tran.c | 16 |
11 files changed, 68 insertions, 58 deletions
@@ -25,6 +25,10 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the AWK book was sent to the printers in August, 1987. +October 13, 2020: + Add casts before all the calls to malloc/calloc/realloc in order + to get it to compile with g++. Thanks to Arnold Robbins. + August 16, 2020: Additional fixes for DJGPP. Thanks to Eli Zaretskii for the testing. @@ -5,11 +5,11 @@ third_party { type: GIT value: "https://github.com/onetrueawk/awk.git" } - version: "9804285af0866f90731a6e0ce767ab0e7b23b6c6" + version: "3b42cfaf73fbe63c1332f9cf2c8e4d90ab686f05" license_type: NOTICE last_upgrade_date { year: 2020 - month: 9 - day: 9 + month: 10 + day: 28 } } @@ -99,6 +99,9 @@ welcome. This compiles without change on Macintosh OS X using `gcc` and the standard developer tools. +You can also use `make CC=g++` to build with the GNU C++ compiler, +should you choose to do so. + The version of `malloc` that comes with some systems is sometimes astonishly slow. If `awk` seems slow, you might try fixing that. More generally, turning on optimization can significantly improve @@ -112,8 +115,9 @@ as we can. Unfortunately, however, keeping this program going is not at the top of our priority list. _If_ you (yes, you!) are interested in taking over active maintenance of -`awk`, please open an issue to indicate that fact, give a little bit of +`awk`, please open an issue to indicate that fact, and give us a little bit of your background and some idea of your plans and dreams. Thanks! #### Last Updated -Thu Jul 2 21:39:31 IDT 2020 + +Tue Oct 13 20:00:09 IDT 2020 @@ -83,7 +83,7 @@ int nfatab = 0; /* entries in fatab */ static int * intalloc(size_t n, const char *f) { - void *p = calloc(n, sizeof(int)); + int *p = (int *) calloc(n, sizeof(int)); if (p == NULL) overflo(f); return p; @@ -96,8 +96,8 @@ resizesetvec(const char *f) maxsetvec = MAXLIN; else maxsetvec *= 4; - setvec = realloc(setvec, maxsetvec * sizeof(*setvec)); - tmpset = realloc(tmpset, maxsetvec * sizeof(*tmpset)); + setvec = (int *) realloc(setvec, maxsetvec * sizeof(*setvec)); + tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(*tmpset)); if (setvec == NULL || tmpset == NULL) overflo(f); } @@ -105,7 +105,9 @@ resizesetvec(const char *f) static void resize_state(fa *f, int state) { - void *p; + unsigned int **p; + uschar *p2; + int **p3; int i, new_count; if (++state < f->state_count) @@ -113,23 +115,23 @@ resize_state(fa *f, int state) new_count = state + 10; /* needs to be tuned */ - p = realloc(f->gototab, new_count * sizeof(f->gototab[0])); + p = (unsigned int **) realloc(f->gototab, new_count * sizeof(f->gototab[0])); if (p == NULL) goto out; f->gototab = p; - p = realloc(f->out, new_count * sizeof(f->out[0])); - if (p == NULL) + p2 = (uschar *) realloc(f->out, new_count * sizeof(f->out[0])); + if (p2 == NULL) goto out; - f->out = p; + f->out = p2; - p = realloc(f->posns, new_count * sizeof(f->posns[0])); - if (p == NULL) + p3 = (int **) realloc(f->posns, new_count * sizeof(f->posns[0])); + if (p3 == NULL) goto out; - f->posns = p; + f->posns = p3; for (i = f->state_count; i < new_count; ++i) { - f->gototab[i] = calloc(NCHARS, sizeof(**f->gototab)); + f->gototab[i] = (unsigned int *) calloc(NCHARS, sizeof(**f->gototab)); if (f->gototab[i] == NULL) goto out; f->out[i] = 0; @@ -195,7 +197,7 @@ fa *mkdfa(const char *s, bool anchor) /* does the real work of making a dfa */ poscnt = 0; penter(p1); /* enter parent pointers and leaf indices */ - if ((f = calloc(1, sizeof(fa) + poscnt * sizeof(rrow))) == NULL) + if ((f = (fa *) calloc(1, sizeof(fa) + poscnt * sizeof(rrow))) == NULL) overflo(__func__); f->accept = poscnt-1; /* penter has computed number of positions in re */ cfoll(f, p1); /* set up follow sets */ @@ -365,7 +367,7 @@ char *cclenter(const char *argp) /* add a character class */ static int bufsz = 100; op = p; - if (buf == NULL && (buf = malloc(bufsz)) == NULL) + if (buf == NULL && (buf = (uschar *) malloc(bufsz)) == NULL) FATAL("out of space for character class [%.10s...] 1", p); bp = buf; for (i = 0; (c = *p++) != 0; ) { @@ -937,7 +939,7 @@ replace_repeat(const uschar *reptok, int reptoklen, const uschar *atom, } else if (special_case == REPEAT_ZERO) { size += 2; /* just a null ERE: () */ } - if ((buf = malloc(size + 1)) == NULL) + if ((buf = (uschar *) malloc(size + 1)) == NULL) FATAL("out of space in reg expr %.10s..", lastre); memcpy(buf, basestr, prefix_length); /* copy prefix */ j = prefix_length; @@ -1065,7 +1067,7 @@ rescan: rlxval = c; return CHAR; case '[': - if (buf == NULL && (buf = malloc(bufsz)) == NULL) + if (buf == NULL && (buf = (uschar *) malloc(bufsz)) == NULL) FATAL("out of space in reg expr %.10s..", lastre); bp = buf; if (*prestr == '^') { @@ -173,7 +173,7 @@ int yylex(void) static char *buf = NULL; static int bufsize = 5; /* BUG: setting this small causes core dump! */ - if (buf == NULL && (buf = malloc(bufsize)) == NULL) + if (buf == NULL && (buf = (char *) malloc(bufsize)) == NULL) FATAL( "out of space in yylex" ); if (sc) { sc = false; @@ -370,7 +370,7 @@ int string(void) static char *buf = NULL; static int bufsz = 500; - if (buf == NULL && (buf = malloc(bufsz)) == NULL) + if (buf == NULL && (buf = (char *) malloc(bufsz)) == NULL) FATAL("out of space for strings"); for (bp = buf; (c = input()) != '"'; ) { if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, "string")) @@ -519,7 +519,7 @@ int regexpr(void) static int bufsz = 500; char *bp; - if (buf == NULL && (buf = malloc(bufsz)) == NULL) + if (buf == NULL && (buf = (char *) malloc(bufsz)) == NULL) FATAL("out of space for rex expr"); bp = buf; for ( ; (c = input()) != '/' && c != 0; ) { @@ -60,10 +60,10 @@ static Cell dollar1 = { OCELL, CFLD, NULL, EMPTY, 0.0, FLD|STR|DONTFREE, NULL, N void recinit(unsigned int n) { - if ( (record = malloc(n)) == NULL - || (fields = malloc(n+1)) == NULL - || (fldtab = calloc(nfields+2, sizeof(*fldtab))) == NULL - || (fldtab[0] = malloc(sizeof(**fldtab))) == NULL) + if ( (record = (char *) malloc(n)) == NULL + || (fields = (char *) malloc(n+1)) == NULL + || (fldtab = (Cell **) calloc(nfields+2, sizeof(*fldtab))) == NULL + || (fldtab[0] = (Cell *) malloc(sizeof(**fldtab))) == NULL) FATAL("out of space for $0 and fields"); *record = '\0'; *fldtab[0] = dollar0; @@ -78,7 +78,7 @@ void makefields(int n1, int n2) /* create $n1..$n2 inclusive */ int i; for (i = n1; i <= n2; i++) { - fldtab[i] = malloc(sizeof(**fldtab)); + fldtab[i] = (Cell *) malloc(sizeof(**fldtab)); if (fldtab[i] == NULL) FATAL("out of space in makefields %d", i); *fldtab[i] = dollar1; @@ -127,7 +127,7 @@ void savefs(void) } len_inputFS = len + 1; - inputFS = realloc(inputFS, len_inputFS); + inputFS = (char *) realloc(inputFS, len_inputFS); if (inputFS == NULL) FATAL("field separator %.10s... is too long", *FS); memcpy(inputFS, *FS, len_inputFS); @@ -325,7 +325,7 @@ void fldbld(void) /* create fields from current record */ n = strlen(r); if (n > fieldssize) { xfree(fields); - if ((fields = malloc(n+2)) == NULL) /* possibly 2 final \0s */ + if ((fields = (char *) malloc(n+2)) == NULL) /* possibly 2 final \0s */ FATAL("out of space for fields in fldbld %d", n); fieldssize = n; } @@ -474,7 +474,7 @@ void growfldtab(int n) /* make new fields up to at least $n */ nf = n; s = (nf+1) * (sizeof (struct Cell *)); /* freebsd: how much do we need? */ if (s / sizeof(struct Cell *) - 1 == (size_t)nf) /* didn't overflow */ - fldtab = realloc(fldtab, s); + fldtab = (Cell **) realloc(fldtab, s); else /* overflow sizeof int */ xfree(fldtab); /* make it null */ if (fldtab == NULL) @@ -494,7 +494,7 @@ int refldbld(const char *rec, const char *fs) /* build fields from reg expr in F n = strlen(rec); if (n > fieldssize) { xfree(fields); - if ((fields = malloc(n+1)) == NULL) + if ((fields = (char *) malloc(n+1)) == NULL) FATAL("out of space for fields in refldbld %d", n); fieldssize = n; } @@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ****************************************************************/ -const char *version = "version 20200816"; +const char *version = "version 20201013"; #define DEBUG #include <stdio.h> @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) fn = getarg(&argc, &argv, "no program filename"); if (npfile >= maxpfile) { maxpfile += 20; - pfile = realloc(pfile, maxpfile * sizeof(*pfile)); + pfile = (char **) realloc(pfile, maxpfile * sizeof(*pfile)); if (pfile == NULL) FATAL("error allocating space for -f options"); } @@ -104,7 +104,7 @@ cleaner: testclean # This is a bit of a band-aid until we can invest some more time # in the test suite. testclean: - cd testdir; rm -fr arnold-fixes beebe echo foo* \ + cd testdir; rm -fr arnold-fixes beebe devnull echo foo* \ glop glop1 glop2 lilly.diff tempbig tempsmall time # For the habits of GNU maintainers: @@ -33,7 +33,7 @@ Node *nodealloc(int n) { Node *x; - x = malloc(sizeof(*x) + (n-1) * sizeof(x)); + x = (Node *) malloc(sizeof(*x) + (n-1) * sizeof(x)); if (x == NULL) FATAL("out of space in nodealloc"); x->nnext = NULL; @@ -118,7 +118,7 @@ int adjbuf(char **pbuf, int *psiz, int minlen, int quantum, char **pbptr, /* round up to next multiple of quantum */ if (rminlen) minlen += quantum - rminlen; - tbuf = realloc(*pbuf, minlen); + tbuf = (char *) realloc(*pbuf, minlen); DPRINTF("adjbuf %s: %d %d (pbuf=%p, tbuf=%p)\n", whatrtn, *psiz, minlen, (void*)*pbuf, (void*)tbuf); if (tbuf == NULL) { if (whatrtn) @@ -240,7 +240,7 @@ Cell *call(Node **a, int n) /* function call. very kludgy and fragile */ if (!isfcn(fcn)) FATAL("calling undefined function %s", s); if (frame == NULL) { - frp = frame = calloc(nframe += 100, sizeof(*frame)); + frp = frame = (struct Frame *) calloc(nframe += 100, sizeof(*frame)); if (frame == NULL) FATAL("out of space for stack frames calling %s", s); } @@ -274,7 +274,7 @@ Cell *call(Node **a, int n) /* function call. very kludgy and fragile */ frp++; /* now ok to up frame */ if (frp >= frame + nframe) { int dfp = frp - frame; /* old index */ - frame = realloc(frame, (nframe += 100) * sizeof(*frame)); + frame = (struct Frame *) realloc(frame, (nframe += 100) * sizeof(*frame)); if (frame == NULL) FATAL("out of space for stack frames in %s", s); frp = frame + dfp; @@ -408,7 +408,7 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */ int mode; bool newflag; - if ((buf = malloc(bufsize)) == NULL) + if ((buf = (char *) malloc(bufsize)) == NULL) FATAL("out of memory in getline"); fflush(stdout); /* in case someone is waiting for a prompt */ @@ -474,7 +474,7 @@ makearraystring(Node *p, const char *func) int bufsz = recsize; size_t blen; - if ((buf = malloc(bufsz)) == NULL) { + if ((buf = (char *) malloc(bufsz)) == NULL) { FATAL("%s: out of memory", func); } @@ -701,7 +701,7 @@ Cell *gettemp(void) /* get a tempcell */ Cell *x; if (!tmps) { - tmps = calloc(100, sizeof(*tmps)); + tmps = (Cell *) calloc(100, sizeof(*tmps)); if (!tmps) FATAL("out of space for temporaries"); for (i = 1; i < 100; i++) @@ -839,7 +839,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co os = s; p = buf; - if ((fmt = malloc(fmtsz)) == NULL) + if ((fmt = (char *) malloc(fmtsz)) == NULL) FATAL("out of memory in format()"); while (*s) { adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format1"); @@ -982,7 +982,7 @@ Cell *awksprintf(Node **a, int n) /* sprintf(a[0]) */ char *buf; int bufsz=3*recsize; - if ((buf = malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) FATAL("out of memory in awksprintf"); y = a[0]->nnext; x = execute(a[0]); @@ -1005,7 +1005,7 @@ Cell *awkprintf(Node **a, int n) /* printf */ int len; int bufsz=3*recsize; - if ((buf = malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) FATAL("out of memory in awkprintf"); y = a[0]->nnext; x = execute(a[0]); @@ -1772,7 +1772,7 @@ size_t nfiles; static void stdinit(void) /* in case stdin, etc., are not constants */ { nfiles = FOPEN_MAX; - files = calloc(nfiles, sizeof(*files)); + files = (struct files *) calloc(nfiles, sizeof(*files)); if (files == NULL) FATAL("can't allocate file memory for %zu files", nfiles); files[0].fp = stdin; @@ -1812,7 +1812,7 @@ FILE *openfile(int a, const char *us, bool *pnewflag) if (i >= nfiles) { struct files *nf; size_t nnf = nfiles + FOPEN_MAX; - nf = realloc(files, nnf * sizeof(*nf)); + nf = (struct files *) realloc(files, nnf * sizeof(*nf)); if (nf == NULL) FATAL("cannot grow files for %s and %zu files", s, nnf); memset(&nf[nfiles], 0, FOPEN_MAX * sizeof(*nf)); @@ -1933,7 +1933,7 @@ Cell *sub(Node **a, int nnn) /* substitute command */ fa *pfa; int bufsz = recsize; - if ((buf = malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) FATAL("out of memory in sub"); x = execute(a[3]); /* target string */ t = getsval(x); @@ -1995,7 +1995,7 @@ Cell *gsub(Node **a, int nnn) /* global substitute */ int mflag, tempstat, num; int bufsz = recsize; - if ((buf = malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) FATAL("out of memory in gsub"); mflag = 0; /* if mflag == 0, can replace empty string */ num = 0; @@ -166,8 +166,8 @@ Array *makesymtab(int n) /* make a new symbol table */ Array *ap; Cell **tp; - ap = malloc(sizeof(*ap)); - tp = calloc(n, sizeof(*tp)); + ap = (Array *) malloc(sizeof(*ap)); + tp = (Cell **) calloc(n, sizeof(*tp)); if (ap == NULL || tp == NULL) FATAL("out of space in makesymtab"); ap->nelem = 0; @@ -237,7 +237,7 @@ Cell *setsymtab(const char *n, const char *s, Awkfloat f, unsigned t, Array *tp) (void*)p, NN(p->nval), NN(p->sval), p->fval, p->tval); return(p); } - p = malloc(sizeof(*p)); + p = (Cell *) malloc(sizeof(*p)); if (p == NULL) FATAL("out of space for symbol table at %s", n); p->nval = tostring(n); @@ -272,7 +272,7 @@ void rehash(Array *tp) /* rehash items in small table into big one */ Cell *cp, *op, **np; nsz = GROWTAB * tp->size; - np = calloc(nsz, sizeof(*np)); + np = (Cell **) calloc(nsz, sizeof(*np)); if (np == NULL) /* can't do it, but can keep running. */ return; /* someone else will run out later. */ for (i = 0; i < tp->size; i++) { @@ -519,7 +519,7 @@ char *tostringN(const char *s, size_t n) /* make a copy of string s */ { char *p; - p = malloc(n); + p = (char *) malloc(n); if (p == NULL) FATAL("out of space in tostring on %s", s); strcpy(p, s); @@ -533,13 +533,13 @@ Cell *catstr(Cell *a, Cell *b) /* concatenate a and b */ char *sa = getsval(a); char *sb = getsval(b); size_t l = strlen(sa) + strlen(sb) + 1; - p = malloc(l); + p = (char *) malloc(l); if (p == NULL) FATAL("out of space concatenating %s and %s", sa, sb); snprintf(p, l, "%s%s", sa, sb); l++; // add room for ' ' - char *newbuf = malloc(l); + char *newbuf = (char *) malloc(l); if (newbuf == NULL) FATAL("out of space concatenating %s and %s", sa, sb); // See string() in lex.c; a string "xx" is stored in the symbol @@ -558,7 +558,7 @@ char *qstring(const char *is, int delim) /* collect string up to next delim */ const uschar *s = (const uschar *) is; uschar *buf, *bp; - if ((buf = malloc(strlen(is)+3)) == NULL) + if ((buf = (uschar *) malloc(strlen(is)+3)) == NULL) FATAL( "out of space in qstring(%s)", s); for (bp = buf; (c = *s) != delim; s++) { if (c == '\n') |