From bf9681ebf45c475c8243810d33378b986b758fa7 Mon Sep 17 00:00:00 2001 From: badasahog <52379863+badasahog@users.noreply.github.com> Date: Mon, 11 Aug 2025 03:13:59 -0400 Subject: [PATCH 1/3] renamed parser functions --- src/fread.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fread.c b/src/fread.c index 9ceaae2c74..65c59d540f 100644 --- a/src/fread.c +++ b/src/fread.c @@ -635,12 +635,12 @@ static void str_to_i32_core(const char **pch, int32_t *target, bool parse_date) } } -static void StrtoI32(FieldParseContext *ctx) +static void parse_i32(FieldParseContext *ctx) { str_to_i32_core(ctx->ch, (int32_t*) ctx->targets[sizeof(int32_t)], false); } -static void StrtoI64(FieldParseContext *ctx) +static void parse_i64(FieldParseContext *ctx) { const char *ch = *ctx->ch; int64_t *target = ctx->targets[sizeof(int64_t)]; @@ -1123,7 +1123,7 @@ static void parse_empty(FieldParseContext *ctx) } /* Parse numbers 0 | 1 as boolean and ,, as NA (fwrite's default) */ -static void parse_bool_numeric(FieldParseContext *ctx) +static void parse_bool_10(FieldParseContext *ctx) { const char *ch = *ctx->ch; int8_t *target = ctx->targets[sizeof(int8_t)]; @@ -1189,7 +1189,7 @@ static void parse_bool_lowercase(FieldParseContext *ctx) } /* Parse Y | y | N | n as boolean */ -static void parse_bool_yesno(FieldParseContext *ctx) +static void parse_bool_yn(FieldParseContext *ctx) { const char *ch = *ctx->ch; int8_t *target = ctx->targets[sizeof(int8_t)]; @@ -1215,13 +1215,13 @@ typedef void (*reader_fun_t)(FieldParseContext *ctx); static reader_fun_t fun[NUMTYPE] = { &Field, // CT_DROP &parse_empty, // CT_EMPTY - &parse_bool_numeric, + &parse_bool_10, &parse_bool_uppercase, &parse_bool_titlecase, &parse_bool_lowercase, - &parse_bool_yesno, - &StrtoI32, - &StrtoI64, + &parse_bool_yn, + &parse_i32, + &parse_i64, &parse_double_regular, &parse_double_extended, &parse_double_hexadecimal, From ec0aa0bada473d2e223a6ce52b5097cb5fa848ba Mon Sep 17 00:00:00 2001 From: badasahog <52379863+badasahog@users.noreply.github.com> Date: Mon, 11 Aug 2025 03:20:02 -0400 Subject: [PATCH 2/3] make parser function table const --- src/fread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fread.c b/src/fread.c index 65c59d540f..0b3bda39a6 100644 --- a/src/fread.c +++ b/src/fread.c @@ -1212,7 +1212,7 @@ static void parse_bool_yn(FieldParseContext *ctx) * (5) Extend typeSxp, typeRName, typeEnum in freadR.c as appropriate */ typedef void (*reader_fun_t)(FieldParseContext *ctx); -static reader_fun_t fun[NUMTYPE] = { +static const reader_fun_t fun[NUMTYPE] = { &Field, // CT_DROP &parse_empty, // CT_EMPTY &parse_bool_10, From 98e2196fc32cc9cfcdaff5fd6fbb92f21cccde51 Mon Sep 17 00:00:00 2001 From: badasahog <52379863+badasahog@users.noreply.github.com> Date: Mon, 11 Aug 2025 03:26:17 -0400 Subject: [PATCH 3/3] also renamed the parser array itself. 'fun' is not very descriptive --- src/fread.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/fread.c b/src/fread.c index 0b3bda39a6..8be7a3c14c 100644 --- a/src/fread.c +++ b/src/fread.c @@ -1206,13 +1206,13 @@ static void parse_bool_yn(FieldParseContext *ctx) /* How to register a new parser * (1) Write the parser - * (2) Add it to fun array here + * (2) Add it to parser_funs array here * (3) Extend disabled_parsers, typeName, and typeSize here as appropriate * (4) Extend colType typdef in fread.h as appropriate * (5) Extend typeSxp, typeRName, typeEnum in freadR.c as appropriate */ typedef void (*reader_fun_t)(FieldParseContext *ctx); -static const reader_fun_t fun[NUMTYPE] = { +static const reader_fun_t parser_funs[NUMTYPE] = { &Field, // CT_DROP &parse_empty, // CT_EMPTY &parse_bool_10, @@ -1260,11 +1260,11 @@ static int detect_types(const char **pch, int ncol, bool *bumped) dec = '.'; } - fun[tmpType[field]](&fctx); + parser_funs[tmpType[field]](&fctx); if (end_of_field(ch)) break; skip_white(&ch); if (end_of_field(ch)) break; - ch = end_NA_string(fieldStart); // fieldStart here is correct (already after skip_white above); fun[]() may have part processed field so not ch + ch = end_NA_string(fieldStart); // fieldStart here is correct (already after skip_white above); parser_funs[]() may have part processed field so not ch skip_white(&ch); if (end_of_field(ch)) break; ch = fieldStart; @@ -1275,7 +1275,7 @@ static int detect_types(const char **pch, int ncol, bool *bumped) } if (*ch == quote && quote) { // && quote to exclude quote='\0' (user passed quote="") ch++; - fun[tmpType[field]](&fctx); + parser_funs[tmpType[field]](&fctx); if (*ch == quote) { ch++; skip_white(&ch); @@ -2459,7 +2459,7 @@ int freadMain(freadMainArgs _args) // DTPRINT(_("Field %d: '%.10s' as type %d (tch=%p)\n"), j+1, tch, type[j], tch); fieldStart = tch; int8_t thisType = type[j]; // fetch shared type once. Cannot read half-written byte is one reason type's type is single byte to avoid atomic read here. - fun[IGNORE_BUMP(thisType)](&fctx); + parser_funs[IGNORE_BUMP(thisType)](&fctx); if (*tch != sep) break; int8_t thisSize = size[j]; if (thisSize) ((char**) targets)[thisSize] += thisSize; // 'if' for when rereading to avoid undefined NULL+0 @@ -2523,7 +2523,7 @@ int freadMain(freadMainArgs _args) if (!end_of_field(tch)) tch = afterSpace; // else it is the field_end, we're on closing sep|eol and we'll let processor write appropriate NA as if field was empty if (*tch == quote && quote) { quoted = true; tch++; } } // else Field() handles NA inside it unlike other processors e.g. ,, is interpreted as "" or NA depending on option read inside Field() - fun[IGNORE_BUMP(thisType)](&fctx); + parser_funs[IGNORE_BUMP(thisType)](&fctx); bool typeBump = false; if (quoted) { // quoted was only set to true with '&& quote' above (=> quote!='\0' now)