summaryrefslogtreecommitdiff
path: root/src/1.h
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-12-27 03:05:05 +0000
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2026-02-16 19:11:24 +0000
commit8d4b47298b6c9eeb9a3f79a5b80d894f80ed4a45 (patch)
tree63a8ea6f645b997fd7943a58a002e66244fa49ac /src/1.h
parente7943fb834cbcaec585ed68e67b5f17ceda504f7 (diff)
downloadsst-8d4b47298b6c9eeb9a3f79a5b80d894f80ed4a45.tar.gz
sst-8d4b47298b6c9eeb9a3f79a5b80d894f80ed4a45.zip
Do away with memcpy/memset/memcmp
Now everything is either explicitly a rep thing, or explicitly some other small run of reasonably efficient instructions. No library calls or function call overhead of any kind. Code size remains nice and small. Ban a few other bad libc functions while we're at it. More can be added later if we decide that's a useful idea. This will require some discipline and workarounds to cope with Clang's tendency to shove mem* calls in places you don't want them even when you tell it not to. Well, c'est la vie. I'm a little nervous that the __builtin_memmove() usage in shuntvars() could still one day emit actual library calls. It appears we're not importing memmove() from anywhere at the moment, though. So I guess it's good enough for now. Also I had to get rid of alloca() in con_.c but that was kind of bad anyway, so that's fine.
Diffstat (limited to 'src/1.h')
-rw-r--r--src/1.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/1.h b/src/1.h
new file mode 100644
index 0000000..f356bc3
--- /dev/null
+++ b/src/1.h
@@ -0,0 +1,37 @@
+/* This file is dedicated to the public domain. */
+
+// This is a special header force-included in every source file.
+// Currently it's just used to ban certain functions from the codebase.
+// Ideally this could be done using the poison thing but that triggers a bunch
+// of anger when including Windows.h. Of course. So we just use #defines.
+
+#ifndef SST_DBG // we wrap these in debug mode, so leave them unbanned there.
+// These should not be used explicitly. Use mem_copy, mem_set and mem_cmp from
+// mem.h instead. Those are optimised for both code size and speed on x86.
+#define memcpy please_use_mem_copy_from_mem_dot_h_instead_of_memcpy
+#define memset please_use_mem_set_from_mem_dot_h_instead_of_memset
+#define memcmp please_use_mem_cmp_from_mem_dot_h_instead_of_memcmp
+#endif
+
+// TODO(opt): implement this if and when we ever need it (unlikely really)
+#define memmove sorry_memmove_needs_an_equivalent_in_mem_dot_h_not_done_yet
+
+// These functions are impossible to use correctly and probably have better
+// alternatives already within the codebase. Or, if not, then better
+// alternatives can be written easily.
+#define strcpy strcpy_is_broken_and_should_never_be_used
+#define strcat strcat_is_broken_and_should_never_be_used
+#define strncpy strncpy_is_broken_and_should_never_be_used
+#define strncat strncat_is_broken_and_should_never_be_used
+#define strtok strtok_is_broken_and_slow_and_should_never_be_used
+#define strtok_r strtok_r_is_broken_and_slow_and_should_never_be_used
+// Windows headers throw a fit when redefining these, lol. The following two
+// effectively prevent their use anyway since they're inline functions in
+// stdio.h. Dunno about on Linux, but we compile first on Windows anyway innit.
+//#define sprintf sprintf_is_dangerous_and_slow_and_should_never_be_used
+//#define snprintf snprintf_is_dangerous_and_slow_and_should_never_be_used
+#define vsprintf vsprintf_is_dangerous_and_slow_and_should_never_be_used
+// XXX: have some straggling vsnprintf usage I'd like to get rid of...
+//#define vsnprintf vsnprintf_is_dangerous_and_slow_and_should_never_be_used
+
+// vi: sw=4 ts=4 noet tw=80 cc=80