From ce0829de33b7a40086f9def3364ec984c3ddd42f Mon Sep 17 00:00:00 2001
From: Dan Hirsch <thequux@upstandinghackers.com>
Date: Fri, 1 Nov 2013 12:39:01 -0400
Subject: [PATCH] Made test-suite work on its own

---
 src/hammer.h     | 2 +-
 src/pprint.c     | 9 ++-------
 src/test_suite.h | 3 ++-
 3 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/hammer.h b/src/hammer.h
index 67fb8e4b..487fa970 100644
--- a/src/hammer.h
+++ b/src/hammer.h
@@ -565,7 +565,7 @@ HAMMER_FN_DECL(void, h_parse_result_free, HParseResult *result);
  * Format token into a compact unambiguous form. Useful for parser test cases.
  * Caller is responsible for freeing the result.
  */
-HAMMER_FN_DECL(char*, h_write_result_unamb, const HParsedToken* tok);
+char* h_write_result_unamb(const HParsedToken* tok);
 /**
  * Format token to the given output stream. Indent starting at
  * [indent] spaces, with [delta] spaces between levels.
diff --git a/src/pprint.c b/src/pprint.c
index d8b22e2d..58576bee 100644
--- a/src/pprint.c
+++ b/src/pprint.c
@@ -80,14 +80,13 @@ void h_pprint(FILE* stream, const HParsedToken* tok, int indent, int delta) {
 
 struct result_buf {
   char* output;
-  HAllocator *mm__;
   size_t len;
   size_t capacity;
 };
 
 static inline void ensure_capacity(struct result_buf *buf, int amt) {
   while (buf->len + amt >= buf->capacity)
-    buf->output = buf->mm__->realloc(buf->mm__, buf->output, buf->capacity *= 2);
+    buf->output = realloc(buf->output, buf->capacity *= 2);
 }
 
 static inline void append_buf(struct result_buf *buf, const char* input, int len) {
@@ -160,13 +159,9 @@ static void unamb_sub(const HParsedToken* tok, struct result_buf *buf) {
   
 
 char* h_write_result_unamb(const HParsedToken* tok) {
-  return h_write_result_unamb__m(&system_allocator, tok);
-}
-char* h_write_result_unamb__m(HAllocator* mm__, const HParsedToken* tok) {
   struct result_buf buf = {
-    .output = mm__->alloc(mm__, 16),
+    .output = malloc(16),
     .len = 0,
-    .mm__ = mm__,
     .capacity = 16
   };
   unamb_sub(tok, &buf);
diff --git a/src/test_suite.h b/src/test_suite.h
index fc008e7f..57dcda5d 100644
--- a/src/test_suite.h
+++ b/src/test_suite.h
@@ -109,7 +109,7 @@
     } else {								\
       char* cres = h_write_result_unamb(res->ast);			\
       g_check_string(cres, ==, result);					\
-      system_allocator.free(&system_allocator, cres);			\
+      free(cres);							\
       HArenaStats stats;						\
       h_allocator_stats(res->arena, &stats);				\
       g_test_message("Parse used %zd bytes, wasted %zd bytes. "		\
@@ -161,6 +161,7 @@
   } while(0)
 
 
+// This stuff needs to be made internal-only; it has no use in user-level test suites
 #define g_check_terminal(grammar, parser) \
   g_check_hashtable_absent(grammar->nts, h_desugar(&system_allocator, NULL, parser))
 
-- 
GitLab