Removed all glib functions from everything other than the test suite.
This commit is contained in:
parent
d5729efa1f
commit
158b2b3ba6
10 changed files with 28 additions and 14 deletions
|
|
@ -111,6 +111,8 @@ long long h_read_bits(HInputStream* state, int count, char signed_p) {
|
|||
|
||||
#ifdef INCLUDE_TESTS
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#define MK_INPUT_STREAM(buf,len,endianness_) \
|
||||
{ \
|
||||
.input = (uint8_t*)buf, \
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
#include "internal.h"
|
||||
#include "test_suite.h"
|
||||
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
|
||||
// This file provides the logical inverse of bitreader.c
|
||||
struct HBitWriter_ {
|
||||
uint8_t* buf;
|
||||
|
|
@ -109,6 +112,7 @@ void h_bit_writer_free(HBitWriter* w) {
|
|||
}
|
||||
|
||||
#ifdef INCLUDE_TESTS
|
||||
#include <glib.h>
|
||||
// TESTS BELOW HERE
|
||||
typedef struct {
|
||||
unsigned long long data;
|
||||
|
|
|
|||
12
src/hammer.c
12
src/hammer.c
|
|
@ -26,8 +26,8 @@
|
|||
#include "allocator.h"
|
||||
#include "parsers/parser_internal.h"
|
||||
|
||||
static guint djbhash(const uint8_t *buf, size_t len) {
|
||||
guint hash = 5381;
|
||||
static uint32_t djbhash(const uint8_t *buf, size_t len) {
|
||||
uint32_t hash = 5381;
|
||||
while (len--) {
|
||||
hash = hash * 33 + *buf++;
|
||||
}
|
||||
|
|
@ -116,7 +116,7 @@ void setupLR(const HParser *p, HParseState *state, HLeftRec *rec_detect) {
|
|||
HLeftRec *lr = state->lr_stack->head->elem;
|
||||
while (lr && lr->rule != p) {
|
||||
lr->head = rec_detect->head;
|
||||
h_slist_push(lr->head->involved_set, (gpointer)lr->rule);
|
||||
h_slist_push(lr->head->involved_set, (void*)lr->rule);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -230,10 +230,10 @@ typedef struct {
|
|||
} HTwoParsers;
|
||||
|
||||
|
||||
static guint cache_key_hash(gconstpointer key) {
|
||||
static uint32_t cache_key_hash(const void* key) {
|
||||
return djbhash(key, sizeof(HParserCacheKey));
|
||||
}
|
||||
static gboolean cache_key_equal(gconstpointer key1, gconstpointer key2) {
|
||||
static bool cache_key_equal(const void* key1, const void* key2) {
|
||||
return memcmp(key1, key2, sizeof(HParserCacheKey)) == 0;
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +274,9 @@ void h_parse_result_free(HParseResult *result) {
|
|||
|
||||
#ifdef INCLUDE_TESTS
|
||||
|
||||
#include <glib.h>
|
||||
#include "test_suite.h"
|
||||
|
||||
static void test_token(void) {
|
||||
const HParser *token_ = h_token((const uint8_t*)"95\xa2", 3);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#ifndef HAMMER_HAMMER__H
|
||||
#define HAMMER_HAMMER__H
|
||||
#include <glib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "allocator.h"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#ifndef HAMMER_INTERNAL__H
|
||||
#define HAMMER_INTERNAL__H
|
||||
#include <glib.h>
|
||||
#include <err.h>
|
||||
#include "hammer.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "parser_internal.h"
|
||||
|
||||
static HParseResult* parse_ch(void* env, HParseState *state) {
|
||||
uint8_t c = (uint8_t)GPOINTER_TO_UINT(env);
|
||||
uint8_t c = (uint8_t)(unsigned long)(env);
|
||||
uint8_t r = (uint8_t)h_read_bits(&state->input_stream, 8, false);
|
||||
if (c == r) {
|
||||
HParsedToken *tok = a_new(HParsedToken, 1);
|
||||
|
|
@ -22,6 +22,6 @@ const HParser* h_ch(const uint8_t c) {
|
|||
const HParser* h_ch__m(HAllocator* mm__, const uint8_t c) {
|
||||
HParser *ret = h_new(HParser, 1);
|
||||
ret->vtable = &ch_vt;
|
||||
ret->env = GUINT_TO_POINTER(c);
|
||||
ret->env = (void*)(unsigned long)(c);
|
||||
return (const HParser*)ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#include <stdarg.h>
|
||||
#include "parser_internal.h"
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#include <stdarg.h>
|
||||
#include "parser_internal.h"
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
15
src/pprint.c
15
src/pprint.c
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include "hammer.h"
|
||||
#include "internal.h"
|
||||
#include <malloc.h>
|
||||
|
||||
typedef struct pp_state {
|
||||
|
|
@ -69,20 +69,21 @@ void h_pprint(FILE* stream, const HParsedToken* tok, int indent, int delta) {
|
|||
fprintf(stream, "%*sUSER\n", indent, "");
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
assert_message(0, "Should not reach here.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 = g_realloc(buf->output, buf->capacity *= 2);
|
||||
buf->output = buf->mm__->realloc(buf->mm__, buf->output, buf->capacity *= 2);
|
||||
}
|
||||
|
||||
static inline void append_buf(struct result_buf *buf, const char* input, int len) {
|
||||
|
|
@ -149,15 +150,19 @@ static void unamb_sub(const HParsedToken* tok, struct result_buf *buf) {
|
|||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unexpected token type %d\n", tok->token_type);
|
||||
g_assert_not_reached();
|
||||
assert_message(0, "Should not reach here.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 = g_malloc0(16),
|
||||
.output = mm__->alloc(mm__, 16),
|
||||
.len = 0,
|
||||
.mm__ = mm__,
|
||||
.capacity = 16
|
||||
};
|
||||
unamb_sub(tok, &buf);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include "hammer.h"
|
||||
#include "test_suite.h"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue