From 1daee5bac49977331c74c797a3f6bd575ec1872d Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 5 Mar 2017 23:43:27 -0500 Subject: [PATCH] windows-port iterate --- c/Makefile.no-autoconfig | 2 ++ c/experimental/getlines.c | 1 + c/input/line_readers.c | 1 + c/lib/mlr_arch.c | 10 +++++++--- c/todo.txt | 4 ++-- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/c/Makefile.no-autoconfig b/c/Makefile.no-autoconfig index b61cfec23..f51b01f4b 100644 --- a/c/Makefile.no-autoconfig +++ b/c/Makefile.no-autoconfig @@ -339,11 +339,13 @@ TEST_JOIN_BUCKET_KEEPER_SRCS = \ EXPERIMENTAL_READER_SRCS = \ lib/mlrutil.c \ + lib/mlrdatetime.c \ lib/mlr_arch.c \ lib/mtrand.c \ lib/mlrescape.c \ lib/mlrregex.c \ lib/mlr_globals.c \ + lib/string_array.c \ lib/string_builder.c \ input/stdio_byte_reader.c \ input/file_reader_mmap.c \ diff --git a/c/experimental/getlines.c b/c/experimental/getlines.c index c6476ef7c..f1ae5483c 100644 --- a/c/experimental/getlines.c +++ b/c/experimental/getlines.c @@ -3,6 +3,7 @@ #include "lib/mlr_globals.h" #include "lib/mlr_arch.h" #include "lib/mlrutil.h" +#include "lib/mlrdatetime.h" #include "input/file_reader_stdio.h" #include "input/file_reader_mmap.h" #include "input/lrec_readers.h" diff --git a/c/input/line_readers.c b/c/input/line_readers.c index e997123e2..d4dc68aa1 100644 --- a/c/input/line_readers.c +++ b/c/input/line_readers.c @@ -65,6 +65,7 @@ char* mlr_get_cline2(FILE* fp, char irs) { if (p == line) eof = TRUE; *p = 0; + p++; break; } else { *(p++) = c; diff --git a/c/lib/mlr_arch.c b/c/lib/mlr_arch.c index c4e17ff4b..4b453c96f 100644 --- a/c/lib/mlr_arch.c +++ b/c/lib/mlr_arch.c @@ -3,6 +3,7 @@ #include #include "mlr_globals.h" #include "mlr_arch.h" +#include "mlrutil.h" // ---------------------------------------------------------------- int mlr_arch_setenv(const char *name, const char *value) { @@ -35,7 +36,10 @@ char * mlr_arch_strsep(char **pstring, const char *delim) { // ---------------------------------------------------------------- #ifdef MLR_ON_MSYS2 -static int mlr_arch_getdelim(char** restrict pline, size_t* restrict plinecap, int delimiter, FILE* restrict stream) { + +// Use powers of two exclusively, to help avoid heap fragmentation +#define INITIAL_SIZE 128 +static int local_getdelim(char** restrict pline, size_t* restrict plinecap, int delimiter, FILE* restrict stream) { size_t linecap = INITIAL_SIZE; char* restrict line = mlr_malloc_or_die(INITIAL_SIZE); char* restrict p = line; @@ -52,6 +56,7 @@ static int mlr_arch_getdelim(char** restrict pline, size_t* restrict plinecap, i c = mlr_arch_getc(stream); if (c == delimiter) { *p = 0; + p++; break; } else if (c == EOF) { if (p == line) @@ -67,7 +72,7 @@ static int mlr_arch_getdelim(char** restrict pline, size_t* restrict plinecap, i free(line); *pline = NULL; *plinecap = 0; - return 0; + return -1; } else { *pline = line; *plinecap = linecap; @@ -81,7 +86,6 @@ ssize_t mlr_arch_getdelim(char** restrict pline, size_t* restrict plinecap, int #ifndef MLR_ON_MSYS2 return getdelim(pline, plinecap, delimiter, stream); #else - char* retval = mlr_get_cline2(stream, delimiter); return local_getdelim(pline, plinecap, delimiter, stream); #endif } diff --git a/c/todo.txt b/c/todo.txt index c5189bdc3..071e9d786 100644 --- a/c/todo.txt +++ b/c/todo.txt @@ -39,9 +39,9 @@ MSYS2 TO-DO ! msys2 / pacman -S / etc @ appveyor -! getdelim +~ getdelim -! strsep +~ strsep k get_unlocked / getc: k @ mlr_arch.h: ifdef MSYS2 define getc_unlocked(x) getc(x)