summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-02-05 17:30:11 +0800
committerJSDurand <mmemmew@gmail.com>2022-02-05 17:30:11 +0800
commit510b10b96b546fcc6c6b6be85050305ddd192a41 (patch)
tree997d6c3f2c0a1ad6e27127d54a94655527e57864 /src/util.h
parent3fb5430080199a6d92a63f8259fe4a88df9b83ba (diff)
replace some hash table usage by tuples
Previously I used hash tables, which consume too much memory. Now the critical parts are replaced by a new hand-written library called "tuple.h". Now we can easily parse larger inputs. I haven't tested its limits, though.
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index d83e40c..88aee89 100644
--- a/src/util.h
+++ b/src/util.h
@@ -46,6 +46,14 @@ typedef unsigned char BOOL;
} \
} while (0)
+#define SAFE_CALLOC(TYPE, VAR, LEN, CLEAN) do { \
+ VAR = calloc((LEN), sizeof (TYPE)); \
+ if (VAR == NULL) { \
+ fleprintf0("Fail to calloc\n"); \
+ { CLEAN }; \
+ } \
+ } while (0)
+
#define SAFE_REALLOC(TYPE, VAR, LEN, CLEAN) do { \
TYPE *macro_new_var = \
realloc(VAR, sizeof (TYPE) * (LEN)); \
@@ -57,6 +65,16 @@ typedef unsigned char BOOL;
} \
} while (0)
+/* very convenient macro */
+#define PASTER2(X, Y, Z) X ## Y ## Z
+#define PASTER(X, Y, Z) PASTER2(X, Y, Z)
+
BOOL read_entire_file(const char *file_name, char **str, NUM *len);
+/* The purpose of this macro is to be used at the end of a macro
+ defining a function, so that we can add a semicolon when calling
+ that macro. I was using the keyword _Static_assert, but that
+ requires C11, which sounds kind of absurd to me. */
+#define MY_Static_MES(MES) struct STATIC_STRUCT_s
+
#endif