From 510b10b96b546fcc6c6b6be85050305ddd192a41 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 5 Feb 2022 17:30:11 +0800 Subject: 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. --- src/util.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/util.h') 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 -- cgit v1.2.3-18-g5258