aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2022-10-31 17:13:46 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2022-10-31 17:13:46 -0500
commit628f816a236c0c3336e6e95ae237cf4953cc897e (patch)
tree20e7354817d35a3416eeb9fdce4b0fa4954634d2
parent71528a24e09abf1e77a7756db38490d892b4603f (diff)
downloadqidx-628f816a236c0c3336e6e95ae237cf4953cc897e.tar.xz
qidx-628f816a236c0c3336e6e95ae237cf4953cc897e.zip
add debug opts to makefile, fix munmap error
-rw-r--r--makefile10
-rw-r--r--qidx.c11
2 files changed, 13 insertions, 8 deletions
diff --git a/makefile b/makefile
index 8f28203..7bef8d1 100644
--- a/makefile
+++ b/makefile
@@ -15,10 +15,16 @@ so_minor := 1
CC=gcc
-CFLAGS = -Wall -pedantic $(debug)
+CFLAGS = -Wall -pedantic $(debug) $(opt)
LDFLAGS := -lhts -lm -fPIC
-# debug = -fsanitize=address -O2 -g
+
+ifeq ($(DEBUG),"1")
+ debug = -fsanitize=address -g
+else
+ opt = -O2
+endif
+
SRC_EXT:=%.c
_STD_BUILD=$(CC) $(CFLAGS) $(filter $(SRC_EXT) %.o, $^) -o $@
diff --git a/qidx.c b/qidx.c
index acad8e9..16da3a7 100644
--- a/qidx.c
+++ b/qidx.c
@@ -612,11 +612,6 @@ qidx_err_t qidx_create(qidx_fp_t ** _fp, int fd, uint32_t _n_buckets, uint32_t m
off += max_bucket_size;
}
- // REVISIT
- for(size_t i = n_buckets - 1; i > 0; i--) {
- fp->htab->rb_start[fp->htab->buckets[i].offset] = '\1';
- }
-
return QIDX_OK;
}
@@ -629,12 +624,16 @@ qidx_err_t qidx_close(qidx_fp_t * fp) {
fp->buckets[i].n_bytes = htole32(htab->buckets[i].n_bytes);
fp->buckets[i].offset = htole64(htab->buckets[i].offset);
}
+
+ if(msync(fp->map, fp->len, MS_SYNC) == -1) {
+ return QIDX_MAP_FAIL;
+ }
}
free(htab->buckets);
free(htab);
- if(munmap(fp->map, fp->len) != -1) {
+ if(munmap(fp->map, fp->len) == -1) {
return QIDX_MAP_FAIL;
}