set up gmp and bdwgc

This commit is contained in:
Rachel Lambda Samuelsson 2021-12-19 12:47:39 +01:00
parent 75f49ac9cb
commit a30700ff0d
4 changed files with 34 additions and 6 deletions

View File

@ -1,14 +1,14 @@
.POSIX:
.PHONY: all debug run clean
DEPS=src/main.o src/util.o
LIBS=-lgc -lgmp
DEPS=src/main.o src/util.o src/gmp_setup.o
LIBS=-static -l:libgmp.a -l:libgc.a -l:libpthread.a
DBGFLAGS=-Og -g
DBGBIN=secd_debug
all: secd
secd: $(DEPS)
$(CC) $(LIBS) $(CFLAGS) $(DEPS) -o secd
$(CC) $(CFLAGS) $(DEPS) $(LIBS) -o secd
$(DBGBIN): $(DEPS)
$(CC) $(LIBS) $(DBGFLAGS) -DENABLE_DBG_H -o secd_debug
@ -23,4 +23,4 @@ clean:
.SUFFIXES: .c .o
.c.o:
$(CC) -c $(CFLAGS) $< -o $@
$(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@

17
src/gmp_setup.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdlib.h>
#include <stdio.h>
#include <gc.h>
#include <gmp.h>
void gmp_free(void* p, size_t s) {
GC_FREE(p); // TODO: see if this performs better than a NOP
}
void* gmp_realloc(void* p, size_t o, size_t n) {
return GC_REALLOC(p, n);
}
void gmp_init(void) {
mp_set_memory_functions(GC_malloc, gmp_realloc, gmp_free);
}

6
src/gmp_setup.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef _GMP_SETUP_H
#define _GMP_SETUP_H
void gmp_init(void);
#endif

View File

@ -1,15 +1,19 @@
#include <gc.h>
#include <gmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <gc.h>
#include "dbg.h"
#include "util.h"
#include "gmp_setup.h"
int main(int argc, char** argv) {
GC_INIT();
gmp_init();
if (argc < 2) {
die("Not enough args");
}
@ -20,4 +24,5 @@ int main(int argc, char** argv) {
buf = readFile(argv[1], &size);
fwrite(buf, 1, size, stdout);
}