Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint lint: clean up memory management for string bu...



details:   https://anonhg.NetBSD.org/src/rev/7a763dd8671e
branches:  trunk
changeset: 362046:7a763dd8671e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 27 07:50:09 2022 +0000

description:
lint: clean up memory management for string buffers

There is no reason to duplicate all the work that is already done by the
memory allocator.

No functional change.

diffstat:

 usr.bin/xlint/Makefile.inc  |   3 +-
 usr.bin/xlint/lint1/lex.c   |  52 ++++++--------------------------------------
 usr.bin/xlint/lint1/lint1.h |   3 +-
 3 files changed, 9 insertions(+), 49 deletions(-)

diffs (152 lines):

diff -r 1d3073630e73 -r 7a763dd8671e usr.bin/xlint/Makefile.inc
--- a/usr.bin/xlint/Makefile.inc        Sun Feb 27 07:38:54 2022 +0000
+++ b/usr.bin/xlint/Makefile.inc        Sun Feb 27 07:50:09 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.19 2022/02/26 18:35:01 rillig Exp $
+#      $NetBSD: Makefile.inc,v 1.20 2022/02/27 07:50:09 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -16,7 +16,6 @@
 
 CPPFLAGS+=     -I${.CURDIR}/../arch/${ARCHSUBDIR}
 CPPFLAGS+=     -I${.CURDIR}/../common
-CPPFLAGS+=     -DBLKDEBUG
 
 CLEANFILES+=   *.gcno *.gcda *.gcov
 
diff -r 1d3073630e73 -r 7a763dd8671e usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Feb 27 07:38:54 2022 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Feb 27 07:50:09 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.99 2022/02/27 07:38:54 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.100 2022/02/27 07:50:09 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.99 2022/02/27 07:38:54 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.100 2022/02/27 07:50:09 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -67,8 +67,6 @@
 bool in_gcc_attribute;
 bool in_system_header;
 
-static sbuf_t *allocsb(void);
-static void    freesb(sbuf_t *);
 static int     inpc(void);
 static unsigned int hash(const char *);
 static sym_t * search(sbuf_t *);
@@ -258,8 +256,6 @@
 /* Symbol table */
 static sym_t   *symtab[HSHSIZ1];
 
-static sbuf_t   *sbuf_free_list;
-
 /* type of next expected symbol */
 symt_t symtyp;
 
@@ -342,40 +338,6 @@
 }
 
 /*
- * Get a free sbuf structure, if possible from the free list
- */
-static sbuf_t *
-allocsb(void)
-{
-       sbuf_t  *sb;
-
-       if ((sb = sbuf_free_list) != NULL) {
-               sbuf_free_list = sb->sb_next;
-#ifdef BLKDEBUG
-               (void)memset(sb, 0, sizeof(*sb));
-#else
-               sb->sb_next = NULL;
-#endif
-       } else {
-               sb = xmalloc(sizeof(*sb));
-               (void)memset(sb, 0, sizeof(*sb));
-       }
-       return sb;
-}
-
-/*
- * Put a sbuf structure to the free list
- */
-static void
-freesb(sbuf_t *sb)
-{
-
-       (void)memset(sb, 0xa5, sizeof(*sb));
-       sb->sb_next = sbuf_free_list;
-       sbuf_free_list = sb;
-}
-
-/*
  * Read a character and ensure that it is positive (except EOF).
  * Increment line count(s) if necessary.
  */
@@ -429,11 +391,11 @@
        sym_t   *sym;
        int     tok;
 
-       sb = allocsb();
+       sb = xmalloc(sizeof(*sb));
        sb->sb_name = yytext;
        sb->sb_len = yyleng;
        if ((sym = search(sb)) != NULL && sym->s_keyword != NULL) {
-               freesb(sb);
+               free(sb);
                return keyw(sym);
        }
 
@@ -1382,7 +1344,7 @@
        if (sym != NULL) {
                lint_assert(sym->s_kind == symtyp);
                symtyp = FVFT;
-               freesb(sb);
+               free(sb);
                return sym;
        }
 
@@ -1417,7 +1379,7 @@
        *di->d_ldlsym = sym;
        di->d_ldlsym = &sym->s_dlnxt;
 
-       freesb(sb);
+       free(sb);
        return sym;
 }
 
@@ -1563,7 +1525,7 @@
 {
        if (tok == T_NAME || tok == T_TYPENAME) {
                sbuf_t *sb = *(sbuf_t **)sp;
-               freesb(sb);
+               free(sb);
        } else if (tok == T_CON) {
                val_t *val = *(val_t **)sp;
                free(val);
diff -r 1d3073630e73 -r 7a763dd8671e usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sun Feb 27 07:38:54 2022 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sun Feb 27 07:50:09 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.137 2022/02/27 07:38:54 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.138 2022/02/27 07:50:09 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -294,7 +294,6 @@
        const   char *sb_name;          /* name of symbol */
        size_t  sb_len;                 /* length (without '\0') */
        sym_t   *sb_sym;                /* symbol table entry */
-       struct  sbuf *sb_next;          /* for freelist */
 } sbuf_t;
 
 



Home | Main Index | Thread Index | Old Index