From 68a116c380130aeb15ac50e7f687ba12777e3b64 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 23 Jan 2023 19:00:18 +0000 Subject: [PATCH] FST writer does not flush valpos_mem on Windows. Issue #596 --- NEWS.md | 2 ++ thirdparty/fstapi.c | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 90ac7d5d..57df44a3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,6 @@ ## Unreleased changes +- Initial signal values for certain types were not dumped correctly in + FST files on Windows (#596). ## Version 1.8.0 - 2023-01-22 - The `--disable-opt` and `--native` elaborate options which were diff --git a/thirdparty/fstapi.c b/thirdparty/fstapi.c index 93d4f78b..1ac39631 100644 --- a/thirdparty/fstapi.c +++ b/thirdparty/fstapi.c @@ -1042,9 +1042,6 @@ static void fstDestroyMmaps(struct fstWriterContext *xc, int is_closing) (void)is_closing; #endif -fstMunmap(xc->valpos_mem, xc->maxhandle * 4 * sizeof(uint32_t)); -xc->valpos_mem = NULL; - #if defined __CYGWIN__ || defined __MINGW32__ if(xc->curval_mem) { @@ -1056,6 +1053,24 @@ if(xc->curval_mem) size_t i; size_t __len = xc->maxvalpos; + lseek(__fd, 0, SEEK_SET); + for(i=0;i<__len;i+=SSIZE_MAX) + { + write(__fd, pnt + i, ((__len - i) >= SSIZE_MAX) ? SSIZE_MAX : (__len - i)); + } + lseek(__fd, cur_offs, SEEK_SET); + } + } + if(xc->valpos_mem) + { + if(!is_closing) /* need to flush out for next emulated mmap() read */ + { + char *pnt = (char *)xc->valpos_mem; + int __fd = fileno(xc->valpos_handle); + fst_off_t cur_offs = lseek(__fd, 0, SEEK_CUR); + size_t i; + size_t __len = xc->maxhandle * 4 * sizeof(uint32_t); + lseek(__fd, 0, SEEK_SET); for(i=0;i<__len;i+=SSIZE_MAX) { @@ -1066,6 +1081,9 @@ if(xc->curval_mem) } #endif +fstMunmap(xc->valpos_mem, xc->maxhandle * 4 * sizeof(uint32_t)); +xc->valpos_mem = NULL; + fstMunmap(xc->curval_mem, xc->maxvalpos); xc->curval_mem = NULL; } -- 2.39.2