summaryrefslogtreecommitdiff
path: root/usr.bin/lex
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2015-11-19 23:20:35 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2015-11-19 23:20:35 +0000
commitc5173a2b4670bf712f6cf5ae35baf6f749393eb6 (patch)
tree0b2e1f0d39194acd4a1f42f83bdf939b119654e0 /usr.bin/lex
parentf6bbde5af99b6ea1b326e9f1c8951f69a7e23d1f (diff)
flex_alloc and flex_free are nothing more than malloc and free, so replace
them with the real functions so as to not trick people into thinking they are special
Diffstat (limited to 'usr.bin/lex')
-rw-r--r--usr.bin/lex/buf.c16
-rw-r--r--usr.bin/lex/dfa.c6
-rw-r--r--usr.bin/lex/filter.c24
-rw-r--r--usr.bin/lex/flexdef.h6
-rw-r--r--usr.bin/lex/gen.c4
-rw-r--r--usr.bin/lex/initscan.c27
-rw-r--r--usr.bin/lex/main.c4
-rw-r--r--usr.bin/lex/misc.c14
-rw-r--r--usr.bin/lex/regex.c8
-rw-r--r--usr.bin/lex/scan.l26
-rw-r--r--usr.bin/lex/scanflags.c6
-rw-r--r--usr.bin/lex/sym.c4
12 files changed, 48 insertions, 97 deletions
diff --git a/usr.bin/lex/buf.c b/usr.bin/lex/buf.c
index 4ccb1d4e830..2bd05234bc9 100644
--- a/usr.bin/lex/buf.c
+++ b/usr.bin/lex/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.3 2015/11/19 22:52:40 tedu Exp $ */
+/* $OpenBSD: buf.c,v 1.4 2015/11/19 23:20:34 tedu Exp $ */
/* flex - tool to generate fast lexical analyzers */
@@ -78,12 +78,12 @@ buf_prints(struct Buf * buf, const char *fmt, const char *s)
char *t;
size_t tsz;
- t = flex_alloc(tsz = strlen(fmt) + strlen(s) + 1);
+ t = malloc(tsz = strlen(fmt) + strlen(s) + 1);
if (!t)
flexfatal(_("Allocation of buffer to print string failed"));
snprintf(t, tsz, fmt, s);
buf = buf_strappend(buf, t);
- flex_free(t);
+ free(t);
return buf;
}
@@ -100,7 +100,7 @@ buf_linedir(struct Buf * buf, const char *filename, int lineno)
char *dst, *t;
size_t tsz;
- t = flex_alloc(tsz = strlen("#line \"\"\n") + /* constant parts */
+ t = malloc(tsz = strlen("#line \"\"\n") + /* constant parts */
2 * strlen(filename) + /* filename with possibly all
* backslashes escaped */
(int) (1 + log10(abs(lineno))) + /* line number */
@@ -114,7 +114,7 @@ buf_linedir(struct Buf * buf, const char *filename, int lineno)
*dst++ = '\n';
*dst = '\0';
buf = buf_strappend(buf, t);
- flex_free(t);
+ free(t);
return buf;
}
@@ -186,7 +186,7 @@ buf_m4_define(struct Buf * buf, const char *def, const char *val)
size_t strsz;
val = val ? val : "";
- str = (char *) flex_alloc(strsz = strlen(fmt) + strlen(def) + strlen(val) + 2);
+ str = (char *) malloc(strsz = strlen(fmt) + strlen(def) + strlen(val) + 2);
if (!str)
flexfatal(_("Allocation of buffer for m4 def failed"));
@@ -207,7 +207,7 @@ buf_m4_undefine(struct Buf * buf, const char *def)
char *str;
size_t strsz;
- str = (char *) flex_alloc(strsz = strlen(fmt) + strlen(def) + 2);
+ str = (char *) malloc(strsz = strlen(fmt) + strlen(def) + 2);
if (!str)
flexfatal(_("Allocation of buffer for m4 undef failed"));
@@ -234,7 +234,7 @@ buf_destroy(buf)
struct Buf *buf;
{
if (buf && buf->elts)
- flex_free(buf->elts);
+ free(buf->elts);
buf->elts = (void *) 0;
}
diff --git a/usr.bin/lex/dfa.c b/usr.bin/lex/dfa.c
index 316a36bc6de..b986787fa1b 100644
--- a/usr.bin/lex/dfa.c
+++ b/usr.bin/lex/dfa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dfa.c,v 1.7 2015/11/19 19:43:40 tedu Exp $ */
+/* $OpenBSD: dfa.c,v 1.8 2015/11/19 23:20:34 tedu Exp $ */
/* dfa - DFA construction routines */
@@ -807,8 +807,8 @@ void ntod ()
mkdeftbl ();
}
- flex_free ((void *) accset);
- flex_free ((void *) nset);
+ free ((void *) accset);
+ free ((void *) nset);
}
diff --git a/usr.bin/lex/filter.c b/usr.bin/lex/filter.c
index 77f62f239a1..a7a1141d041 100644
--- a/usr.bin/lex/filter.c
+++ b/usr.bin/lex/filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filter.c,v 1.4 2015/11/19 22:52:40 tedu Exp $ */
+/* $OpenBSD: filter.c,v 1.5 2015/11/19 23:20:34 tedu Exp $ */
/* filter - postprocessing of flex output through filters */
@@ -50,9 +50,9 @@ filter_create_ext(struct filter * chain, const char *cmd,
va_list ap;
/* allocate and initialize new filter */
- f = (struct filter *) flex_alloc(sizeof(struct filter));
+ f = (struct filter *) malloc(sizeof(struct filter));
if (!f)
- flexerror(_("flex_alloc failed (f) in filter_create_ext"));
+ flexerror(_("malloc failed (f) in filter_create_ext"));
memset(f, 0, sizeof(*f));
f->filter_func = NULL;
f->extra = NULL;
@@ -67,16 +67,16 @@ filter_create_ext(struct filter * chain, const char *cmd,
}
/* allocate argv, and populate it with the argument list. */
max_args = 8;
- f->argv = flex_alloc(sizeof(char *) * (max_args + 1));
+ f->argv = malloc(sizeof(char *) * (max_args + 1));
if (!f->argv)
- flexerror(_("flex_alloc failed (f->argv) in filter_create_ext"));
+ flexerror(_("malloc failed (f->argv) in filter_create_ext"));
f->argv[f->argc++] = cmd;
va_start(ap, cmd);
while ((s = va_arg(ap, const char *)) != NULL) {
if (f->argc >= max_args) {
max_args += 8;
- f->argv = flex_realloc(f->argv,
+ f->argv = realloc(f->argv,
sizeof(char *) * (max_args + 1));
}
f->argv[f->argc++] = s;
@@ -103,9 +103,9 @@ filter_create_int(struct filter * chain,
struct filter *f;
/* allocate and initialize new filter */
- f = (struct filter *) flex_alloc(sizeof(struct filter));
+ f = (struct filter *) malloc(sizeof(struct filter));
if (!f)
- flexerror(_("flex_alloc failed in filter_create_int"));
+ flexerror(_("malloc failed in filter_create_int"));
memset(f, 0, sizeof(*f));
f->next = NULL;
f->argc = 0;
@@ -293,9 +293,9 @@ filter_tee_header(struct filter * chain)
fprintf(to_c, "m4_define( [[M4_YY_OUTFILE_NAME]],[[%s]])m4_dnl\n",
outfilename ? outfilename : "<stdout>");
- buf = (char *) flex_alloc(readsz);
+ buf = (char *) malloc(readsz);
if (!buf)
- flexerror(_("flex_alloc failed in filter_tee_header"));
+ flexerror(_("malloc failed in filter_tee_header"));
while (fgets(buf, readsz, stdin)) {
fputs(buf, to_c);
if (write_header)
@@ -357,9 +357,9 @@ filter_fix_linedirs(struct filter * chain)
if (!chain)
return 0;
- buf = (char *) flex_alloc(readsz);
+ buf = (char *) malloc(readsz);
if (!buf)
- flexerror(_("flex_alloc failed in filter_fix_linedirs"));
+ flexerror(_("malloc failed in filter_fix_linedirs"));
while (fgets(buf, readsz, stdin)) {
diff --git a/usr.bin/lex/flexdef.h b/usr.bin/lex/flexdef.h
index 9a946437f37..106255cf749 100644
--- a/usr.bin/lex/flexdef.h
+++ b/usr.bin/lex/flexdef.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: flexdef.h,v 1.11 2015/11/19 23:04:51 tedu Exp $ */
+/* $OpenBSD: flexdef.h,v 1.12 2015/11/19 23:20:34 tedu Exp $ */
/* flexdef - definitions file for flex */
@@ -666,10 +666,6 @@ extern int num_backing_up, bol_needed;
void *allocate_array PROTO ((int, size_t));
void *reallocate_array PROTO ((void *, int, size_t));
-void *flex_alloc PROTO ((size_t));
-void *flex_realloc PROTO ((void *, size_t));
-void flex_free PROTO ((void *));
-
#define allocate_integer_array(size) \
(int *) allocate_array( size, sizeof( int ) )
diff --git a/usr.bin/lex/gen.c b/usr.bin/lex/gen.c
index 1cb5d0c5c45..59b4235c8fa 100644
--- a/usr.bin/lex/gen.c
+++ b/usr.bin/lex/gen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gen.c,v 1.13 2015/11/19 22:52:40 tedu Exp $ */
+/* $OpenBSD: gen.c,v 1.14 2015/11/19 23:20:34 tedu Exp $ */
/* gen - actual generation (writing) of flex scanners */
@@ -1479,7 +1479,7 @@ gentabs()
}
/* End generating yy_chk */
- flex_free((void *) acc_array);
+ free((void *) acc_array);
}
diff --git a/usr.bin/lex/initscan.c b/usr.bin/lex/initscan.c
index e7ede080592..c154f29b97f 100644
--- a/usr.bin/lex/initscan.c
+++ b/usr.bin/lex/initscan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: initscan.c,v 1.15 2015/11/19 19:43:40 tedu Exp $ */
+/* $OpenBSD: initscan.c,v 1.16 2015/11/19 23:20:34 tedu Exp $ */
#line 3 "scan.c"
@@ -2537,7 +2537,7 @@ case 36:
YY_RULE_SETUP
#line 233 "scan.l"
{
- flex_free( (void *) infilename );
+ free( (void *) infilename );
infilename = copy_string( yytext + 1 );
infilename[strlen( infilename ) - 1] = '\0';
}
@@ -5179,26 +5179,3 @@ char *file;
linenum = 1;
}
-
-/* Wrapper routines for accessing the scanner's malloc routines. */
-
-void *flex_alloc( size )
-size_t size;
- {
- return (void *) malloc( size );
- }
-
-void *flex_realloc( ptr, size )
-void *ptr;
-size_t size;
- {
- return (void *) realloc( ptr, size );
- }
-
-void flex_free( ptr )
-void *ptr;
- {
- if ( ptr )
- free( ptr );
- }
-
diff --git a/usr.bin/lex/main.c b/usr.bin/lex/main.c
index 3e3845a4396..61ef8ed5ee1 100644
--- a/usr.bin/lex/main.c
+++ b/usr.bin/lex/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.19 2015/11/19 22:58:59 tedu Exp $ */
+/* $OpenBSD: main.c,v 1.20 2015/11/19 23:20:34 tedu Exp $ */
/* flex - tool to generate fast lexical analyzers */
@@ -438,7 +438,7 @@ check_options()
char *str, *fmt = "#define %s %d\n";
size_t strsz;
- str = (char *) flex_alloc(strsz = strlen(fmt) + strlen(scname[i]) + (int) (1 + log10(i)) + 2);
+ str = (char *) malloc(strsz = strlen(fmt) + strlen(scname[i]) + (int) (1 + log10(i)) + 2);
if (!str)
flexfatal(_("allocation of macro definition failed"));
snprintf(str, strsz, fmt, scname[i], i - 1);
diff --git a/usr.bin/lex/misc.c b/usr.bin/lex/misc.c
index beb46d69148..6dec7c09294 100644
--- a/usr.bin/lex/misc.c
+++ b/usr.bin/lex/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.17 2015/11/19 23:04:51 tedu Exp $ */
+/* $OpenBSD: misc.c,v 1.18 2015/11/19 23:20:34 tedu Exp $ */
/* misc - miscellaneous flex routines */
@@ -63,14 +63,14 @@ sko_push(bool dc)
{
if (!sko_stack) {
sko_sz = 1;
- sko_stack = (struct sko_state *) flex_alloc(sizeof(struct sko_state) * sko_sz);
+ sko_stack = malloc(sizeof(struct sko_state) * sko_sz);
if (!sko_stack)
flexfatal(_("allocation of sko_stack failed"));
sko_len = 0;
}
if (sko_len >= sko_sz) {
sko_sz *= 2;
- sko_stack = (struct sko_state *) flex_realloc(sko_stack, sizeof(struct sko_state) * sko_sz);
+ sko_stack = realloc(sko_stack, sizeof(struct sko_state) * sko_sz);
}
/* initialize to zero and push */
sko_stack[sko_len].dc = dc;
@@ -179,7 +179,7 @@ allocate_array(size, element_size)
void *mem;
size_t num_bytes = element_size * size;
- mem = flex_alloc(num_bytes);
+ mem = malloc(num_bytes);
if (!mem)
flexfatal(_
("memory allocation failed in allocate_array()"));
@@ -276,7 +276,7 @@ copy_string(str)
size = (c1 - str + 1) * sizeof(char);
- copy = (char *) flex_alloc(size);
+ copy = (char *) malloc(size);
if (copy == NULL)
flexfatal(_("dynamic memory failure in copy_string()"));
@@ -839,7 +839,7 @@ reallocate_array(array, size, element_size)
void *new_array;
size_t num_bytes = element_size * size;
- new_array = flex_realloc(array, num_bytes);
+ new_array = realloc(array, num_bytes);
if (!new_array)
flexfatal(_("attempt to increase array size failed"));
@@ -999,7 +999,7 @@ void *
yy_flex_xmalloc(size)
int size;
{
- void *result = flex_alloc((size_t) size);
+ void *result = malloc((size_t) size);
if (!result)
flexfatal(_
diff --git a/usr.bin/lex/regex.c b/usr.bin/lex/regex.c
index 2b3b80a2b1a..5cba19db725 100644
--- a/usr.bin/lex/regex.c
+++ b/usr.bin/lex/regex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: regex.c,v 1.2 2015/11/19 22:16:43 tedu Exp $ */
+/* $OpenBSD: regex.c,v 1.3 2015/11/19 23:20:34 tedu Exp $ */
/** regex - regular expression functions related to POSIX regex lib. */
@@ -59,10 +59,10 @@ void flex_regcomp(regex_t *preg, const char *regex, int cflags)
const int errbuf_sz = 200;
char *errbuf, *rxerr;
- errbuf = (char*)flex_alloc(errbuf_sz *sizeof(char));
+ errbuf = (char*)malloc(errbuf_sz *sizeof(char));
if (!errbuf)
flexfatal(_("Unable to allocate buffer to report regcomp"));
- rxerr = (char*)flex_alloc(errbuf_sz *sizeof(char));
+ rxerr = (char*)malloc(errbuf_sz *sizeof(char));
if (!rxerr)
flexfatal(_("Unable to allocate buffer for regerror"));
regerror (err, preg, rxerr, errbuf_sz);
@@ -87,7 +87,7 @@ char *regmatch_dup (regmatch_t * m, const char *src)
if (m == NULL || m->rm_so < 0)
return NULL;
len = m->rm_eo - m->rm_so;
- str = (char *) flex_alloc ((len + 1) * sizeof (char));
+ str = (char *) malloc ((len + 1) * sizeof (char));
if (!str)
flexfatal(_("Unable to allocate a copy of the match"));
strncpy (str, src + m->rm_so, len);
diff --git a/usr.bin/lex/scan.l b/usr.bin/lex/scan.l
index 6c84a80f73c..dfd8b8b3a5d 100644
--- a/usr.bin/lex/scan.l
+++ b/usr.bin/lex/scan.l
@@ -1,4 +1,4 @@
-/* $OpenBSD: scan.l,v 1.10 2015/11/19 19:43:40 tedu Exp $ */
+/* $OpenBSD: scan.l,v 1.11 2015/11/19 23:20:34 tedu Exp $ */
/* scan.l - scanner for flex input -*-C-*- */
@@ -233,7 +233,7 @@ M4QEND "]]"
[[:digit:]]+ linenum = myctoi( yytext );
\"[^"\n]*\" {
- flex_free( (void *) infilename );
+ free( (void *) infilename );
infilename = copy_string( yytext + 1 );
infilename[strlen( infilename ) - 1] = '\0';
}
@@ -1008,25 +1008,3 @@ char *file;
linenum = 1;
}
-
-/* Wrapper routines for accessing the scanner's malloc routines. */
-
-void *flex_alloc( size )
-size_t size;
- {
- return (void *) malloc( size );
- }
-
-void *flex_realloc( ptr, size )
-void *ptr;
-size_t size;
- {
- return (void *) realloc( ptr, size );
- }
-
-void flex_free( ptr )
-void *ptr;
- {
- if ( ptr )
- free( ptr );
- }
diff --git a/usr.bin/lex/scanflags.c b/usr.bin/lex/scanflags.c
index 7d0d4525710..fbda7ae8fb3 100644
--- a/usr.bin/lex/scanflags.c
+++ b/usr.bin/lex/scanflags.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scanflags.c,v 1.2 2015/11/19 22:16:43 tedu Exp $ */
+/* $OpenBSD: scanflags.c,v 1.3 2015/11/19 23:20:34 tedu Exp $ */
/* scanflags - flags used by scanning. */
@@ -42,7 +42,7 @@ void
sf_push (void)
{
if (_sf_top_ix + 1 >= _sf_max)
- _sf_stk = (scanflags_t*) flex_realloc ( (void*) _sf_stk, sizeof(scanflags_t) * (_sf_max += 32));
+ _sf_stk = (scanflags_t*) realloc ( (void*) _sf_stk, sizeof(scanflags_t) * (_sf_max += 32));
// copy the top element
_sf_stk[_sf_top_ix + 1] = _sf_stk[_sf_top_ix];
@@ -61,7 +61,7 @@ void
sf_init (void)
{
assert(_sf_stk == NULL);
- _sf_stk = (scanflags_t*) flex_alloc ( sizeof(scanflags_t) * (_sf_max = 32));
+ _sf_stk = (scanflags_t*) malloc ( sizeof(scanflags_t) * (_sf_max = 32));
if (!_sf_stk)
lerrsf_fatal(_("Unable to allocate %ld of stack"),
(void *)sizeof(scanflags_t));
diff --git a/usr.bin/lex/sym.c b/usr.bin/lex/sym.c
index 0a9e08491ec..b000e807e99 100644
--- a/usr.bin/lex/sym.c
+++ b/usr.bin/lex/sym.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sym.c,v 1.7 2015/11/19 19:43:40 tedu Exp $ */
+/* $OpenBSD: sym.c,v 1.8 2015/11/19 23:20:34 tedu Exp $ */
/* sym - symbol table routines */
@@ -96,7 +96,7 @@ static int addsym (sym, str_def, int_def, table, table_size)
/* create new entry */
new_entry = (struct hash_entry *)
- flex_alloc (sizeof (struct hash_entry));
+ malloc (sizeof (struct hash_entry));
if (new_entry == NULL)
flexfatal (_("symbol table memory allocation failed"));