scc

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

commit 818f368daded1b80748ab4fbbb1df718e65984ca
parent acdc0f7bf35277e027f354e14752b00c1879741d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 22 Aug 2019 23:03:09 +0100

[libmach] Add read method to Obj

Diffstat:
Minclude/scc/scc/mach.h | 2+-
Msrc/cmd/addr2line.c | 2+-
Msrc/cmd/ld/pass1.c | 2+-
Msrc/cmd/nm.c | 2+-
Msrc/cmd/ranlib.c | 2+-
Msrc/cmd/size.c | 2+-
Msrc/cmd/strip.c | 2+-
Msrc/libmach/Makefile | 1-
Msrc/libmach/coff32/coff32.c | 1+
Msrc/libmach/coff32/coff32.h | 1+
Msrc/libmach/libmach.h | 2+-
Msrc/libmach/objnew.c | 1+
Dsrc/libmach/objread.c | 24------------------------
13 files changed, 11 insertions(+), 33 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -55,6 +55,7 @@ struct obj { void *data; int (*new)(Obj *obj); + int (*read)(Obj *obj, FILE *fp); }; @@ -65,7 +66,6 @@ extern int formember(FILE *fp, extern int objtype(FILE *fp, char **name); extern Obj *objnew(int type); extern void objdel(Obj *obj); -extern int objread(Obj *obj, FILE *fp); extern Objsym *objlookup(Obj *obj, char *name, int install); extern int objstrip(Obj *obj); extern int objwrite(Obj *obj, FILE *fp); diff --git a/src/cmd/addr2line.c b/src/cmd/addr2line.c @@ -93,7 +93,7 @@ loadexe(char *fname) return NULL; } - if (!objread(obj, fp)) { + if ((*obj->read)(obj, fp) < 0) { error("file corrupted"); return NULL; } diff --git a/src/cmd/ld/pass1.c b/src/cmd/ld/pass1.c @@ -184,7 +184,7 @@ newobject(FILE *fp, int type, int inlib) } bintype = type; - if (objread(obj, fp) < 0) { + if ((*obj->read)(obj, fp) < 0) { error("object file corrupted"); goto delete; } diff --git a/src/cmd/nm.c b/src/cmd/nm.c @@ -153,7 +153,7 @@ newobject(FILE *fp, int type) return; } - if (objread(obj, fp) < 0) + if ((*obj->read)(obj, fp) < 0) goto error; for (sym = obj->syms; sym; sym = sym->next) diff --git a/src/cmd/ranlib.c b/src/cmd/ranlib.c @@ -146,7 +146,7 @@ newmember(FILE *fp, char *nam, void *data) } namidx = obj->index; - if (objread(obj, fp) < 0) { + if ((*obj->read)(obj, fp) < 0) { error("file corrupted"); goto error; } diff --git a/src/cmd/size.c b/src/cmd/size.c @@ -50,7 +50,7 @@ newobject(FILE *fp, int type) return; } - if (objread(obj, fp) < 0) { + if ((*obj->read)(obj, fp) < 0) { error("file corrupted"); goto err; } diff --git a/src/cmd/strip.c b/src/cmd/strip.c @@ -46,7 +46,7 @@ strip(char *fname) error("out of memory"); goto err3; } - if (objread(obj, fp) < 0) { + if ((*obj->read)(obj, fp) < 0) { error("file corrupted"); goto err3; } diff --git a/src/libmach/Makefile b/src/libmach/Makefile @@ -7,7 +7,6 @@ TARGET = $(LIBDIR)/libmach.a OBJS = mach.o \ objnew.o \ objpos.o \ - objread.o \ objfree.o \ objstrip.o \ objdel.o \ diff --git a/src/libmach/coff32/coff32.c b/src/libmach/coff32/coff32.c @@ -7,4 +7,5 @@ struct objfmt coff32 = { .new = coff32new, + .read = coff32read, }; diff --git a/src/libmach/coff32/coff32.h b/src/libmach/coff32/coff32.h @@ -25,3 +25,4 @@ struct coff32 { }; extern int coff32new(Obj *obj); +extern int coff32read(Obj *obj, FILE *fp); diff --git a/src/libmach/libmach.h b/src/libmach/libmach.h @@ -30,6 +30,7 @@ enum deltype { struct objfmt { int (*new)(Obj *obj); + int (*read)(Obj *obj, FILE *fp); }; /* common functions */ @@ -41,7 +42,6 @@ extern int objfree(Obj *obj, int what); /* TODO: Move this functions to a coff32 files */ extern long coff32index(int type, long nsyms, Objsymdef *head, FILE *fp); extern void coff32del(Obj *obj); -extern int coff32read(Obj *obj, FILE *fp); extern int coff32write(Obj *obj, FILE *fp); extern void coff32strip(Obj *obj); extern int coff32probe(unsigned char *buf, char **name); diff --git a/src/libmach/objnew.c b/src/libmach/objnew.c @@ -29,6 +29,7 @@ objnew(int type) op = objfmts[fmt]; obj->new = op->new; + obj->read = op->read; if ((*obj->new)(obj) < 0) { free(obj); diff --git a/src/libmach/objread.c b/src/libmach/objread.c @@ -1,24 +0,0 @@ -#include <stdio.h> - -#include <scc/mach.h> - -#include "libmach.h" - -static int (*freadv[])(Obj *, FILE *) = { - [COFF32] = coff32read, -}; - -int -objread(Obj *obj, FILE *fp) -{ - int fmt; - - fmt = FORMAT(obj->type); - if (fmt >= NFORMATS) - return -1; - - if ((*freadv[fmt])(obj, fp) < 0) - return -1; - - return 0; -}