diff options
author | JSDurand <mmemmew@gmail.com> | 2022-02-05 17:30:11 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2022-02-05 17:30:11 +0800 |
commit | 510b10b96b546fcc6c6b6be85050305ddd192a41 (patch) | |
tree | 997d6c3f2c0a1ad6e27127d54a94655527e57864 /src/util.h | |
parent | 3fb5430080199a6d92a63f8259fe4a88df9b83ba (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.h | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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 |