scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 38f01a438be0d354c4f8fae5a23e37a4d4d0ad7e
parent 65952ed9fa3d04aa7750d1cef19324b25ae95c8a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 11 Feb 2019 18:28:42 +0000

[libmach] Remove forsym()

This is overengineered.

Diffstat:
Minclude/scc/scc/mach.h | 4----
Msrc/cmd/ld.c | 6++++--
Msrc/cmd/nm.c | 8++++----
Msrc/cmd/ranlib.c | 9+++++----
Msrc/libmach/Makefile | 1-
Dsrc/libmach/forsym.c | 19-------------------
Msrc/libmach/libmach.h | 2+-
Msrc/libmach/objfree.c | 5++++-
8 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -53,10 +53,6 @@ extern int formember(FILE *fp, int (*fn)(FILE *, char *, void *), void *data); -extern int forsym(Obj *obj, - int (*fn)(Objsym *sym, void *data), - void *data); - extern int archive(FILE *fp); extern long armember(FILE *fp, char *member); extern int objtype(FILE *fp, char **name); diff --git a/src/cmd/ld.c b/src/cmd/ld.c @@ -164,7 +164,7 @@ define(Objsym *osym, Obj *obj) } static int -newsym(Objsym *osym, void *obj) +newsym(Objsym *osym, Obj *obj) { Symbol *sym; @@ -199,6 +199,7 @@ loadobj(Obj *obj) { int n; Objlst *lst; + Objsym *sym; Objsect *secp; if ((lst = malloc(sizeof(*lst))) == NULL) { @@ -221,7 +222,8 @@ loadobj(Obj *obj) else objlast = objlast->next = lst; - forsym(obj, newsym, obj); + for (sym = obj->symbols; sym; sym = sym->next) + newsym(sym, obj); return; diff --git a/src/cmd/nm.c b/src/cmd/nm.c @@ -114,9 +114,8 @@ printsyms(Objsym **syms, size_t nsym) } static int -newsym(Objsym *sym, void *data) +newsym(Objsym *sym, struct symtbl *tbl) { - struct symtbl *tbl = data; Objsym **p; size_t n, size; int type = sym->type; @@ -148,6 +147,7 @@ newobject(FILE *fp, int type) { int err = 1; Obj *obj; + Objsym *sym; struct symtbl tbl = {NULL, 0}; if ((obj = objnew(type)) == NULL) { @@ -158,8 +158,8 @@ newobject(FILE *fp, int type) if (objread(obj, fp) < 0) goto error; - if (!forsym(obj, newsym, &tbl)) - goto error; + for (sym = obj->symbols; sym; sym = sym->next) + newsym(sym, &tbl); printsyms(tbl.buf, tbl.nsyms); err = 0; diff --git a/src/cmd/ranlib.c b/src/cmd/ranlib.c @@ -83,7 +83,7 @@ lookup(char *name) } static int -newsymbol(Objsym *sym, void *data) +newsymbol(Objsym *sym) { Objsymdef *np; @@ -119,6 +119,7 @@ newmember(FILE *fp, char *nam, void *data) int t, ret = 0; Obj *obj; + Objsym *sym; if (artype == -1 && (!strcmp(nam, "/") || !strcmp(nam, "__.SYMDEF"))) return 1; @@ -148,9 +149,9 @@ newmember(FILE *fp, char *nam, void *data) goto error; } - if (!forsym(obj, newsymbol, NULL)) { - error("traversing object file"); - goto error; + for (sym = obj->symbols; sym; sym = sym->next) { + if (!newsymbol(sym)) + goto error; } ret = 1; diff --git a/src/libmach/Makefile b/src/libmach/Makefile @@ -18,7 +18,6 @@ OBJS = addr2line.o \ getindex.o \ setindex.o \ namindex.o \ - forsym.o \ formember.o \ objtype.o \ objwrite.o \ diff --git a/src/libmach/forsym.c b/src/libmach/forsym.c @@ -1,19 +0,0 @@ -#include <stdio.h> - -#include <scc/mach.h> - -#include "libmach.h" - -int -forsym(Obj *obj, int (*fn)(Objsym *, void *), void *data) -{ - int r; - Objsym *sym; - - for (sym = obj->symbols; sym; sym = sym->next) { - r = (*fn)(sym, data); - if (r <= 0) - return r; - } - return 1; -} diff --git a/src/libmach/libmach.h b/src/libmach/libmach.h @@ -43,7 +43,7 @@ typedef char *(*namidxfun_t)(void); extern int pack(int order, unsigned char *dst, char *fmt, ...); extern int unpack(int order, unsigned char *src, char *fmt, ...); extern int objpos(Obj *obj, FILE *fp, long pos); -extern void objfree(Obj *obj, int what); +extern int objfree(Obj *obj, int what); /* coff32 functions */ extern long coff32index(int type, long nsyms, Objsymdef *head, FILE *fp); diff --git a/src/libmach/objfree.c b/src/libmach/objfree.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <scc/mach.h> @@ -7,7 +8,7 @@ extern delfun_t delv[]; -void +int objfree(Obj *obj, int what) { int fmt; @@ -26,4 +27,6 @@ objfree(Obj *obj, int what) obj->symbols = NULL; memset(obj->htab, 0, sizeof(obj->htab)); } + + return 0; }