]> granicus.if.org Git - flex/commitdiff
Removed flex_alloc; cleaned up style.
authorMichael McConville <mmcconville@mykolab.com>
Wed, 9 Dec 2015 02:00:39 +0000 (21:00 -0500)
committerWill Estes <westes575@gmail.com>
Wed, 9 Dec 2015 14:48:39 +0000 (09:48 -0500)
The function flex_alloc() was just a wrapper around malloc(). Since this only added unclarity, and the flex_alloc() function is likely a legacy of olden times, remove it in favor of calls to malloc() directly.

Style elements cleaned up:

 * superfluous spacing around parentheses
 * non-constant initialization in variable declarations
 * needless casts
 * almost all uses of assignments as subexpressions

12 files changed:
src/buf.c
src/filter.c
src/flexdef.h
src/main.c
src/misc.c
src/regex.c
src/scan.l
src/scanflags.c
src/sym.c
to.do/unicode/flexdef.h
to.do/unicode/misc.c
to.do/unicode/scan.l

index a1c917bb019ce69af0c68ff79a384c5047e1eca2..521330338bf7d2eacc0c659a55775c48597289a2 100644 (file)
--- a/src/buf.c
+++ b/src/buf.c
@@ -73,7 +73,8 @@ struct Buf *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);
+       tsz = strlen(fmt) + strlen(s) + 1;
+       t = malloc(tsz);
        if (!t)
            flexfatal (_("Allocation of buffer to print string failed"));
        snprintf (t, tsz, fmt, s);
@@ -93,7 +94,7 @@ struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno)
     char *dst, *t;
     const char *src;
 
-    t = flex_alloc (strlen ("#line \"\"\n")          +   /* constant parts */
+    t = malloc(strlen("#line \"\"\n")          +   /* constant parts */
                     2 * strlen (filename)            +   /* filename with possibly all backslashes escaped */
                     (int) (1 + log10 (abs (lineno))) +   /* line number */
                     1);                                  /* NUL */
@@ -165,7 +166,8 @@ struct Buf *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);
+    strsz = strlen(fmt) + strlen(def) + strlen(val) + 2;
+    str = malloc(strsz);
     if (!str)
         flexfatal (_("Allocation of buffer for m4 def failed"));
 
@@ -185,7 +187,8 @@ struct Buf *buf_m4_undefine (struct Buf *buf, const char* def)
     char * str;
     size_t strsz;
 
-    str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + 2);
+    strsz = strlen(fmt) + strlen(def) + 2;
+    str = malloc(strsz);
     if (!str)
         flexfatal (_("Allocation of buffer for m4 undef failed"));
 
index 987366aece83ddf79fae3ff8aa0311b639ae1588..ac2f799a7bae2cb57386026c7159dd9eafd683de 100644 (file)
@@ -47,9 +47,9 @@ struct filter *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 = 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;
@@ -66,11 +66,9 @@ struct filter *filter_create_ext (struct filter *chain, const char *cmd,
 
        /* allocate argv, and populate it with the argument list. */
        max_args = 8;
-       f->argv =
-               (const char **) 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);
@@ -107,9 +105,9 @@ struct filter *filter_create_int (struct filter *chain,
        struct filter *f;
 
        /* allocate and initialize new filter */
-       f = (struct filter *) flex_alloc (sizeof (struct filter));
+       f = 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;
@@ -288,9 +286,9 @@ int 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 = 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)
@@ -349,9 +347,9 @@ int filter_fix_linedirs (struct filter *chain)
        if (!chain)
                return 0;
 
-       buf = (char *) flex_alloc (readsz);
+       buf = malloc(readsz);
        if (!buf)
-               flexerror (_("flex_alloc failed in filter_fix_linedirs"));
+               flexerror(_("malloc failed in filter_fix_linedirs"));
 
        while (fgets (buf, readsz, stdin)) {
 
index b61c072754773ffb9d426bb7cf4bfbcd9ac10108..227ba9f086bc02362b28bb12773a540ce8c6c6ee 100644 (file)
@@ -677,7 +677,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 *));
 
index ceaef71836e7c3e5e4e65e348c9423e9c26a5081..4caf8d620ddb7afa15379c9f2f8a10927a7d5e37 100644 (file)
@@ -448,7 +448,8 @@ void check_options (void)
              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);
+             strsz = strlen(fmt) + strlen(scname[i]) + (int)(1 + log10(i)) + 2;
+             str = malloc(strsz);
              if (!str)
                flexfatal(_("allocation of macro definition failed"));
              snprintf(str, strsz, fmt,      scname[i], i - 1);
index 2bea688c29897f98eef287c9decb0bca570eea18..a67adbe186e49f8dca2ee197c59d4ca854a5233f 100644 (file)
@@ -60,7 +60,7 @@ static void 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;
@@ -168,7 +168,7 @@ void   *allocate_array (int size, size_t 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()"));
@@ -889,11 +889,14 @@ void transition_struct_out (element_v, element_n)
 
 /* The following is only needed when building flex's parser using certain
  * broken versions of bison.
+ *
+ * XXX: this is should go soon
  */
 void   *yy_flex_xmalloc (int size)
 {
-       void   *result = flex_alloc ((size_t) size);
+       void   *result;
 
+       result = malloc(size);
        if (!result)
                flexfatal (_
                           ("memory allocation failed in yy_flex_xmalloc()"));
index 2bb580e984a1096df87dee668b831c887ed6973e..84f0e9eeba101aa1b9883d1745a97878f7155890 100644 (file)
@@ -57,10 +57,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 = malloc(errbuf_sz * sizeof(char));
                if (!errbuf)
                        flexfatal(_("Unable to allocate buffer to report regcomp"));
-               rxerr = (char*)flex_alloc(errbuf_sz *sizeof(char));
+               rxerr = malloc(errbuf_sz * sizeof(char));
                if (!rxerr)
                        flexfatal(_("Unable to allocate buffer for regerror"));
                regerror (err, preg, rxerr, errbuf_sz);
@@ -85,7 +85,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 = malloc((len + 1) * sizeof(char));
        if (!str)
                flexfatal(_("Unable to allocate a copy of the match"));
        strncpy (str, src + m->rm_so, len);
index 5c63a4cf8fac8284bed1ac73dee3455c4f564473..8407fea39e6837897988129ea942ec7b2463b914 100644 (file)
@@ -1013,11 +1013,6 @@ void set_input_file( char *file )
 
 /* Wrapper routines for accessing the scanner's malloc routines. */
 
-void *flex_alloc( size_t size )
-       {
-       return malloc(size);
-       }
-
 void *flex_realloc( void *ptr, size_t size )
        {
        return realloc(ptr, size);
index 5beb24ac3eb9afb35ea9ac2382bb75cbd60906e7..ccdb8ff4e41db83c4033fe754113d38f2c34a588 100644 (file)
@@ -59,7 +59,8 @@ void
 sf_init (void)
 {
     assert(_sf_stk == NULL);
-    _sf_stk = (scanflags_t*) flex_alloc ( sizeof(scanflags_t) * (_sf_max = 32));
+    _sf_max = 32;
+    _sf_stk = malloc(sizeof(scanflags_t) * _sf_max);
     if (!_sf_stk)
         lerr_fatal(_("Unable to allocate %zu of stack"), sizeof(scanflags_t));
     _sf_stk[_sf_top_ix] = 0;
index 8b08c9fc7f480cee71a6711f072f4987d14655d7..970d719fd94f4e74488f52c4f9057e033f2f6ff0 100644 (file)
--- a/src/sym.c
+++ b/src/sym.c
@@ -88,8 +88,7 @@ static int addsym (char sym[], char *str_def, int int_def, hash_table table, int
        }
 
        /* create new entry */
-       new_entry = (struct hash_entry *)
-               flex_alloc (sizeof (struct hash_entry));
+       new_entry = malloc(sizeof(struct hash_entry));
 
        if (new_entry == NULL)
                flexfatal (_("symbol table memory allocation failed"));
index 8efa775bb8ce637a04f7c61d02ee6cec53cd8f55..72d8156ef8e3bad28e3e8aa61d2cf005d7d06ee6 100644 (file)
@@ -663,7 +663,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*));
 
index d56d8115b67d167191518aa38789b4948c146e68..c0f382817129620553ef046df43a4d4ba12fee01 100644 (file)
@@ -85,7 +85,7 @@ size_t element_size;
        register 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()" ) );
@@ -815,8 +815,9 @@ int element_v, element_n;
 void *yy_flex_xmalloc( size )
 int size;
        {
-       void *result = flex_alloc( (size_t) size );
+       void *result;
 
+       result = malloc(size);
        if ( ! result  )
                flexfatal(
                        _( "memory allocation failed in yy_flex_xmalloc()" ) );
index c7e6828a36a1e6bfcfa1d166ed2c07a1f5df3ed6..1214490ca26c087636a8f69f2547cd290c461953 100644 (file)
@@ -689,12 +689,6 @@ char *file;
 
 /* Wrapper routines for accessing the scanner's malloc routines. */
 
-void *flex_alloc( size )
-size_t size;
-       {
-       return malloc(size);
-       }
-
 void *flex_realloc( ptr, size )
 void *ptr;
 size_t size;