aboutsummaryrefslogtreecommitdiffhomepage
path: root/obj/obj.h
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-12-15 22:39:52 +0100
committerlemon <lsof@mailbox.org>2025-12-15 22:39:52 +0100
commit302e24671942051d70707586cf8c605a5815edac (patch)
tree51e25fb6cd7e828c82ce5f17ffc775117121acee /obj/obj.h
parentc6c0f2ef35175075e91169113cfe856f29b3eb9a (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.h')
-rw-r--r--obj/obj.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/obj/obj.h b/obj/obj.h
index 59769ff..77da99a 100644
--- a/obj/obj.h
+++ b/obj/obj.h
@@ -22,10 +22,10 @@ enum relockind {
enum section { Snone, Stext, Srodata, Sdata, Sbss };
void objini(const char *infile, const char *outfile);
-void objdeffunc(const char *nam, bool globl, uint off, uint siz);
-enum section objhassym(const char *name, uint *off);
-uint objnewdat(const char *name, enum section, bool globl, uint siz, uint align);
-void objreloc(const char *sym, enum relockind, enum section, uint off, vlong addend);
+void objdeffunc(internstr nam, bool globl, uint off, uint siz);
+enum section objhassym(internstr name, uint *off);
+uint objnewdat(internstr name, enum section, bool globl, uint siz, uint align);
+void objreloc(internstr sym, enum relockind, enum section, uint off, vlong addend);
void objfini(void);
/* vim:set ts=3 sw=3 expandtab: */