diff options
| author | 2025-12-15 22:39:52 +0100 | |
|---|---|---|
| committer | 2025-12-15 22:39:52 +0100 | |
| commit | 302e24671942051d70707586cf8c605a5815edac (patch) | |
| tree | 51e25fb6cd7e828c82ce5f17ffc775117121acee /obj/obj.c | |
| parent | c6c0f2ef35175075e91169113cfe856f29b3eb9a (diff) | |
create distinct interned string type
Interned strings are used pervasively, so it's a good idea to add a
layer of type safety to differentiate them from general cstrs and avoid
potential bugs from comparing non-interned and interned strings. Not
that that's happened so far that I can remember, but it could.
I'm 90% sure it's legal to alias `struct {char c;}` pointers with `char`
pointers. This specific typedef gives type safety but with a simple
one-way `internstr -> const char *` typecast (with `&istr->c`).
Converting the other way around is more intentional: a straight up cast
`(internstr)cstr` which sticks out as unchecked and probably wrong, or
calling the intern(cstr) function, which is the right way.
Diffstat (limited to 'obj/obj.c')
| -rw-r--r-- | obj/obj.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -6,9 +6,9 @@ void elfinit(void); -enum section elfhassym(const char *, uint *value); -void elfaddsym(const char *, int info, enum section, uvlong value, uvlong size); -void elfreloc(const char *sym, enum relockind, enum section, uint off, vlong addend); +enum section elfhassym(internstr , uint *value); +void elfaddsym(internstr , int info, enum section, uvlong value, uvlong size); +void elfreloc(internstr sym, enum relockind, enum section, uint off, vlong addend); void elffini(struct wbuf *); struct objfile objout; @@ -30,7 +30,7 @@ objini(const char *infile, const char *outfile) } void -objdeffunc(const char *nam, bool globl, uint off, uint siz) +objdeffunc(internstr nam, bool globl, uint off, uint siz) { switch (mctarg->objkind) { case OBJELF: @@ -40,13 +40,13 @@ objdeffunc(const char *nam, bool globl, uint off, uint siz) } enum section -objhassym(const char *name, uint *off) +objhassym(internstr name, uint *off) { return elfhassym(name, off); } uint -objnewdat(const char *name, enum section sec, bool globl, uint siz, uint align) +objnewdat(internstr name, enum section sec, bool globl, uint siz, uint align) { struct objfile *o = &objout; uint off; @@ -90,7 +90,7 @@ objnewdat(const char *name, enum section sec, bool globl, uint siz, uint align) } void -objreloc(const char *sym, enum relockind reloc, enum section section, uint off, vlong addend) +objreloc(internstr sym, enum relockind reloc, enum section section, uint off, vlong addend) { switch (mctarg->objkind) { case OBJELF: |