Module Name: src Committed By: rillig Date: Sun Feb 27 07:50:09 UTC 2022
Modified Files: src/usr.bin/xlint: Makefile.inc src/usr.bin/xlint/lint1: lex.c lint1.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.bin/xlint/Makefile.inc cvs rdiff -u -r1.99 -r1.100 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.137 -r1.138 src/usr.bin/xlint/lint1/lint1.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/Makefile.inc diff -u src/usr.bin/xlint/Makefile.inc:1.19 src/usr.bin/xlint/Makefile.inc:1.20 --- src/usr.bin/xlint/Makefile.inc:1.19 Sat Feb 26 18:35:01 2022 +++ src/usr.bin/xlint/Makefile.inc Sun Feb 27 07:50:09 2022 @@ -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 @@ ARCHSUBDIR= ${MACHINE_CPU} CPPFLAGS+= -I${.CURDIR}/../arch/${ARCHSUBDIR} CPPFLAGS+= -I${.CURDIR}/../common -CPPFLAGS+= -DBLKDEBUG CLEANFILES+= *.gcno *.gcda *.gcov Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.99 src/usr.bin/xlint/lint1/lex.c:1.100 --- src/usr.bin/xlint/lint1/lex.c:1.99 Sun Feb 27 07:38:54 2022 +++ src/usr.bin/xlint/lint1/lex.c Sun Feb 27 07:50:09 2022 @@ -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 @@ pos_t csrc_pos = { "", 1, 0 }; 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 @@ static struct keyword { /* 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 @@ initscan(void) } /* - * 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 @@ lex_name(const char *yytext, size_t yyle 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 @@ getsym(sbuf_t *sb) if (sym != NULL) { lint_assert(sym->s_kind == symtyp); symtyp = FVFT; - freesb(sb); + free(sb); return sym; } @@ -1417,7 +1379,7 @@ getsym(sbuf_t *sb) *di->d_ldlsym = sym; di->d_ldlsym = &sym->s_dlnxt; - freesb(sb); + free(sb); return sym; } @@ -1563,7 +1525,7 @@ freeyyv(void *sp, int tok) { 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); Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.137 src/usr.bin/xlint/lint1/lint1.h:1.138 --- src/usr.bin/xlint/lint1/lint1.h:1.137 Sun Feb 27 07:38:54 2022 +++ src/usr.bin/xlint/lint1/lint1.h Sun Feb 27 07:50:09 2022 @@ -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 @@ typedef struct sbuf { 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;