From 347fa1a7a595669de6868095e1e0904051dc89bf Mon Sep 17 00:00:00 2001 From: Ambroz Bizjak Date: Sat, 9 May 2015 00:01:49 +0200 Subject: [PATCH] ncd: Store the NCDStingIndex pointer in NCDValMem. This cuts down on the boilerplate especially with ncd_make_boolean(). --- examples/ncd_value_parser_test.c | 10 ++++- examples/ncdval_test.c | 8 ++-- examples/ncdvalcons_test.c | 11 ++++- ncd-request/ncd-request.c | 12 +++++- ncd/NCDEvaluator.c | 6 +-- ncd/NCDVal.c | 60 ++++++++++---------------- ncd/NCDVal.h | 27 ++++-------- ncd/NCDVal_types.h | 1 + ncd/extra/NCDRequestClient.c | 6 ++- ncd/extra/NCDRequestClient.h | 4 +- ncd/extra/value_utils.c | 10 ++--- ncd/extra/value_utils.h | 4 +- ncd/modules/arithmetic.c | 4 +- ncd/modules/assert.c | 4 +- ncd/modules/basic_functions.c | 14 +++--- ncd/modules/blocker.c | 2 +- ncd/modules/file.c | 2 +- ncd/modules/file_open.c | 4 +- ncd/modules/foreach.c | 4 +- ncd/modules/from_string.c | 2 +- ncd/modules/getenv.c | 2 +- ncd/modules/list.c | 8 ++-- ncd/modules/log.c | 11 +++-- ncd/modules/logical.c | 2 +- ncd/modules/net_ipv4_addr_in_network.c | 2 +- ncd/modules/net_ipv4_arp_probe.c | 2 +- ncd/modules/net_ipv6_addr_in_network.c | 2 +- ncd/modules/objref.c | 2 +- ncd/modules/parse.c | 8 ++-- ncd/modules/process_manager.c | 2 +- ncd/modules/regex_match.c | 2 +- ncd/modules/sleep.c | 4 +- ncd/modules/socket.c | 6 +-- ncd/modules/strcmp.c | 2 +- ncd/modules/sys_request_client.c | 2 +- ncd/modules/sys_request_server.c | 2 +- ncd/modules/sys_start_process.c | 12 +++--- ncd/modules/try.c | 2 +- ncd/modules/value.c | 10 ++--- ncd/modules/valuemetic.c | 2 +- ncd/modules/var.c | 4 +- 41 files changed, 142 insertions(+), 142 deletions(-) diff --git a/examples/ncd_value_parser_test.c b/examples/ncd_value_parser_test.c index 0e0fb40cc..5eca59c44 100644 --- a/examples/ncd_value_parser_test.c +++ b/examples/ncd_value_parser_test.c @@ -47,8 +47,14 @@ int main (int argc, char *argv[]) BLog_InitStdout(); + NCDStringIndex string_index; + if (!NCDStringIndex_Init(&string_index)) { + DEBUG("NCDStringIndex_Init failed"); + goto fail01; + } + NCDValMem mem; - NCDValMem_Init(&mem); + NCDValMem_Init(&mem, &string_index); // parse NCDValRef val; @@ -72,6 +78,8 @@ int main (int argc, char *argv[]) free(str); fail1: NCDValMem_Free(&mem); + NCDStringIndex_Free(&string_index); +fail01: BLog_Free(); fail0: return res; diff --git a/examples/ncdval_test.c b/examples/ncdval_test.c index b69dd1502..94234de9c 100644 --- a/examples/ncdval_test.c +++ b/examples/ncdval_test.c @@ -119,7 +119,7 @@ int main () // Some basic usage of values. NCDValMem mem; - NCDValMem_Init(&mem); + NCDValMem_Init(&mem, &string_index); NCDValRef s1 = NCDVal_NewString(&mem, "Hello World"); test_string(s1, "Hello World", 11); @@ -160,7 +160,7 @@ int main () ASSERT( NCDVal_MapGetValue(m1, "K2").idx == v2.idx ) ASSERT( NCDVal_IsInvalid(NCDVal_MapGetValue(m1, "K3")) ) - NCDValRef ids1 = NCDVal_NewIdString(&mem, NCD_STRING_ARG1, &string_index); + NCDValRef ids1 = NCDVal_NewIdString(&mem, NCD_STRING_ARG1); test_string(ids1, "_arg1", 5); ASSERT( !memcmp(NCDVal_StringData(ids1), "_arg1", 5) ) ASSERT( NCDVal_StringLength(ids1) == 5 ) @@ -169,7 +169,7 @@ int main () ASSERT( NCDVal_Type(ids1) == NCDVAL_STRING ) ASSERT( NCDVal_IsIdString(ids1) ) - NCDValRef ids2 = NCDVal_NewIdString(&mem, NCD_STRING_ARG2, &string_index); + NCDValRef ids2 = NCDVal_NewIdString(&mem, NCD_STRING_ARG2); test_string(ids2, "_arg2", 5); ASSERT( !memcmp(NCDVal_StringData(ids2), "_arg2", 5) ) ASSERT( NCDVal_StringLength(ids2) == 5 ) @@ -198,7 +198,7 @@ int main () // an uninitialized string using NCDVal_NewStringUninitialized() and // then copyng the data. - NCDValMem_Init(&mem); + NCDValMem_Init(&mem, &string_index); NCDValRef s[100]; diff --git a/examples/ncdvalcons_test.c b/examples/ncdvalcons_test.c index 7a876ed1d..c09faf365 100644 --- a/examples/ncdvalcons_test.c +++ b/examples/ncdvalcons_test.c @@ -34,6 +34,7 @@ #include #include +static NCDStringIndex string_index; static NCDValMem mem; static NCDValCons cons; @@ -87,9 +88,14 @@ static NCDValRef complete (NCDValConsVal cval) int main () { - NCDValMem_Init(&mem); + int res; - int res = NCDValCons_Init(&cons, &mem); + res = NCDStringIndex_Init(&string_index); + ASSERT_FORCE(res) + + NCDValMem_Init(&mem, &string_index); + + res = NCDValCons_Init(&cons, &mem); ASSERT_FORCE(res) NCDValRef val1 = complete(list_prepend(list_prepend(list_prepend(make_list(), make_string("hello")), make_string("world")), make_list())); @@ -107,5 +113,6 @@ int main () NCDValCons_Free(&cons); NCDValMem_Free(&mem); + NCDStringIndex_Free(&string_index); return 0; } diff --git a/ncd-request/ncd-request.c b/ncd-request/ncd-request.c index ff04a507a..dbf6f2748 100644 --- a/ncd-request/ncd-request.c +++ b/ncd-request/ncd-request.c @@ -52,6 +52,7 @@ static void request_handler_finished (void *user, int is_error); static int write_all (int fd, const uint8_t *data, size_t len); static int make_connect_addr (const char *str, struct BConnection_addr *out_addr); +NCDStringIndex string_index; NCDValMem request_mem; NCDValRef request_value; BReactor reactor; @@ -75,7 +76,12 @@ int main (int argc, char *argv[]) BTime_Init(); - NCDValMem_Init(&request_mem); + if (!NCDStringIndex_Init(&string_index)) { + BLog(BLOG_ERROR, "NCDStringIndex_Init failed"); + goto fail01; + } + + NCDValMem_Init(&request_mem, &string_index); if (!NCDValParser_Parse(MemRef_MakeCstr(request_payload_string), &request_mem, &request_value)) { BLog(BLOG_ERROR, "BReactor_Init failed"); @@ -97,7 +103,7 @@ int main (int argc, char *argv[]) goto fail2; } - if (!NCDRequestClient_Init(&client, addr, &reactor, NULL, client_handler_error, client_handler_connected)) { + if (!NCDRequestClient_Init(&client, addr, &reactor, &string_index, NULL, client_handler_error, client_handler_connected)) { BLog(BLOG_ERROR, "NCDRequestClient_Init failed"); goto fail2; } @@ -114,6 +120,8 @@ int main (int argc, char *argv[]) BReactor_Free(&reactor); fail1: NCDValMem_Free(&request_mem); + NCDStringIndex_Free(&string_index); +fail01: BLog_Free(); fail0: DebugObjectGlobal_Finish(); diff --git a/ncd/NCDEvaluator.c b/ncd/NCDEvaluator.c index 1e5ead090..b93b379e1 100644 --- a/ncd/NCDEvaluator.c +++ b/ncd/NCDEvaluator.c @@ -65,7 +65,7 @@ static int expr_init (struct NCDEvaluator__Expr *o, NCDEvaluator *eval, NCDValue { ASSERT((NCDValue_Type(value), 1)) - NCDValMem_Init(&o->mem); + NCDValMem_Init(&o->mem, eval->string_index); NCDValRef ref; if (!add_expr_recurser(eval, value, &o->mem, &ref)) { @@ -110,7 +110,7 @@ static int expr_eval (struct NCDEvaluator__Expr *o, struct NCDEvaluator__eval_co *out_val = NCDVal_FromSafe(out_newmem, o->ref); } else { - NCDValMem_Init(out_newmem); + NCDValMem_Init(out_newmem, context->eval->string_index); NCDValRef ref; if (!replace_placeholders_callback((void *)context, NCDVal_GetSafeRefPlaceholderId(o->ref), out_newmem, &ref) || NCDVal_IsInvalid(ref)) { @@ -141,7 +141,7 @@ static int add_expr_recurser (NCDEvaluator *o, NCDValue *value, NCDValMem *mem, goto fail; } - *out = NCDVal_NewIdString(mem, string_id, o->string_index); + *out = NCDVal_NewIdString(mem, string_id); if (NCDVal_IsInvalid(*out)) { goto fail; } diff --git a/ncd/NCDVal.c b/ncd/NCDVal.c index 7feb19e73..dc5d588e0 100644 --- a/ncd/NCDVal.c +++ b/ncd/NCDVal.c @@ -87,7 +87,6 @@ struct NCDVal__mapelem { struct NCDVal__idstring { int type; NCD_string_id_t string_id; - NCDStringIndex *string_index; }; struct NCDVal__externalstring { @@ -232,6 +231,7 @@ static NCDValRef NCDVal__Ref (NCDValMem *mem, NCDVal__idx idx) static void NCDVal__AssertMem (NCDValMem *mem) { ASSERT(mem) + ASSERT(mem->string_index) ASSERT(mem->size == NCDVAL_FASTBUF_SIZE || mem->size >= NCDVAL_FIRST_SIZE) ASSERT(mem->used >= 0) ASSERT(mem->used <= mem->size) @@ -289,7 +289,6 @@ static void NCDVal__AssertValOnly (NCDValMem *mem, NCDVal__idx idx) ASSERT(idx + sizeof(struct NCDVal__idstring) <= mem->used) struct NCDVal__idstring *ids_e = NCDValMem__BufAt(mem, idx); ASSERT(ids_e->string_id >= 0) - ASSERT(ids_e->string_index) } break; case EXTERNALSTRING_TYPE: { ASSERT(idx + sizeof(struct NCDVal__externalstring) <= mem->used) @@ -370,8 +369,11 @@ static void NCDValMem__RegisterRef (NCDValMem *o, NCDVal__idx refidx, struct NCD #include "NCDVal_maptree.h" #include -void NCDValMem_Init (NCDValMem *o) +void NCDValMem_Init (NCDValMem *o, NCDStringIndex *string_index) { + ASSERT(string_index) + + o->string_index = string_index; o->size = NCDVAL_FASTBUF_SIZE; o->used = 0; o->first_ref = -1; @@ -398,6 +400,7 @@ int NCDValMem_InitCopy (NCDValMem *o, NCDValMem *other) { NCDVal__AssertMem(other); + o->string_index = other->string_index; o->size = other->size; o->used = other->used; o->first_ref = other->first_ref; @@ -438,6 +441,13 @@ fail1:; return 0; } +NCDStringIndex * NCDValMem_StringIndex (NCDValMem *o) +{ + NCDVal__AssertMem(o); + + return o->string_index; +} + void NCDVal_Assert (NCDValRef val) { ASSERT(val.idx == -1 || (NCDVal__AssertVal(val), 1)) @@ -839,11 +849,10 @@ NCDValRef NCDVal_NewStringUninitialized (NCDValMem *mem, size_t len) return NCDVal_NewInvalid(); } -NCDValRef NCDVal_NewIdString (NCDValMem *mem, NCD_string_id_t string_id, NCDStringIndex *string_index) +NCDValRef NCDVal_NewIdString (NCDValMem *mem, NCD_string_id_t string_id) { NCDVal__AssertMem(mem); ASSERT(string_id >= 0) - ASSERT(string_index) NCDVal__idx size = sizeof(struct NCDVal__idstring); NCDVal__idx idx = NCDValMem__Alloc(mem, size, __alignof(struct NCDVal__idstring)); @@ -854,7 +863,6 @@ NCDValRef NCDVal_NewIdString (NCDValMem *mem, NCD_string_id_t string_id, NCDStri struct NCDVal__idstring *ids_e = NCDValMem__BufAt(mem, idx); ids_e->type = make_type(IDSTRING_TYPE, 0); ids_e->string_id = string_id; - ids_e->string_index = string_index; return NCDVal__Ref(mem, idx); @@ -911,7 +919,7 @@ const char * NCDVal_StringData (NCDValRef string) case IDSTRING_TYPE: { struct NCDVal__idstring *ids_e = ptr; - const char *value = NCDStringIndex_Value(ids_e->string_index, ids_e->string_id).ptr; + const char *value = NCDStringIndex_Value(string.mem->string_index, ids_e->string_id).ptr; return value; } break; @@ -940,7 +948,7 @@ size_t NCDVal_StringLength (NCDValRef string) case IDSTRING_TYPE: { struct NCDVal__idstring *ids_e = ptr; - return NCDStringIndex_Value(ids_e->string_index, ids_e->string_id).len; + return NCDStringIndex_Value(string.mem->string_index, ids_e->string_id).len; } break; case EXTERNALSTRING_TYPE: { @@ -968,7 +976,7 @@ MemRef NCDVal_StringMemRef (NCDValRef string) case IDSTRING_TYPE: { struct NCDVal__idstring *ids_e = ptr; - return NCDStringIndex_Value(ids_e->string_index, ids_e->string_id); + return NCDStringIndex_Value(string.mem->string_index, ids_e->string_id); } break; case EXTERNALSTRING_TYPE: { @@ -1000,7 +1008,7 @@ int NCDVal_StringNullTerminate (NCDValRef string, NCDValNullTermString *out) case IDSTRING_TYPE: { struct NCDVal__idstring *ids_e = ptr; - out->data = (char *)NCDStringIndex_Value(ids_e->string_index, ids_e->string_id).ptr; + out->data = (char *)NCDStringIndex_Value(string.mem->string_index, ids_e->string_id).ptr; out->is_allocated = 0; return 1; } break; @@ -1039,18 +1047,6 @@ void NCDValNullTermString_Free (NCDValNullTermString *o) } } -void NCDVal_IdStringGet (NCDValRef idstring, NCD_string_id_t *out_string_id, - NCDStringIndex **out_string_index) -{ - ASSERT(NCDVal_IsIdString(idstring)) - ASSERT(out_string_id) - ASSERT(out_string_index) - - struct NCDVal__idstring *ids_e = NCDValMem__BufAt(idstring.mem, idstring.idx); - *out_string_id = ids_e->string_id; - *out_string_index = ids_e->string_index; -} - NCD_string_id_t NCDVal_IdStringId (NCDValRef idstring) { ASSERT(NCDVal_IsIdString(idstring)) @@ -1059,14 +1055,6 @@ NCD_string_id_t NCDVal_IdStringId (NCDValRef idstring) return ids_e->string_id; } -NCDStringIndex * NCDVal_IdStringStringIndex (NCDValRef idstring) -{ - ASSERT(NCDVal_IsIdString(idstring)) - - struct NCDVal__idstring *ids_e = NCDValMem__BufAt(idstring.mem, idstring.idx); - return ids_e->string_index; -} - BRefTarget * NCDVal_ExternalStringTarget (NCDValRef externalstring) { ASSERT(NCDVal_IsExternalString(externalstring)) @@ -1084,7 +1072,7 @@ int NCDVal_StringHasNulls (NCDValRef string) switch (get_internal_type(*(int *)ptr)) { case IDSTRING_TYPE: { struct NCDVal__idstring *ids_e = ptr; - return NCDStringIndex_HasNulls(ids_e->string_index, ids_e->string_id); + return NCDStringIndex_HasNulls(string.mem->string_index, ids_e->string_id); } break; case STOREDSTRING_TYPE: @@ -1108,30 +1096,27 @@ int NCDVal_StringEquals (NCDValRef string, const char *data) return NCDVal_StringLength(string) == data_len && NCDVal_StringRegionEquals(string, 0, data_len, data); } -int NCDVal_StringEqualsId (NCDValRef string, NCD_string_id_t string_id, - NCDStringIndex *string_index) +int NCDVal_StringEqualsId (NCDValRef string, NCD_string_id_t string_id) { ASSERT(NCDVal_IsString(string)) ASSERT(string_id >= 0) - ASSERT(string_index) void *ptr = NCDValMem__BufAt(string.mem, string.idx); switch (get_internal_type(*(int *)ptr)) { case STOREDSTRING_TYPE: { struct NCDVal__string *str_e = ptr; - return MemRef_Equal(NCDStringIndex_Value(string_index, string_id), MemRef_Make(str_e->data, str_e->length)); + return MemRef_Equal(NCDStringIndex_Value(string.mem->string_index, string_id), MemRef_Make(str_e->data, str_e->length)); } break; case IDSTRING_TYPE: { struct NCDVal__idstring *ids_e = ptr; - ASSERT(ids_e->string_index == string_index) return ids_e->string_id == string_id; } break; case EXTERNALSTRING_TYPE: { struct NCDVal__externalstring *exs_e = ptr; - return MemRef_Equal(NCDStringIndex_Value(string_index, string_id), MemRef_Make(exs_e->data, exs_e->length)); + return MemRef_Equal(NCDStringIndex_Value(string.mem->string_index, string_id), MemRef_Make(exs_e->data, exs_e->length)); } break; default: @@ -1524,6 +1509,7 @@ NCDValRef NCDVal_MapGetValue (NCDValRef map, const char *key_str) ASSERT(key_str) NCDValMem mem; + mem.string_index = map.mem->string_index; mem.size = NCDVAL_FASTBUF_SIZE; mem.used = sizeof(struct NCDVal__externalstring); mem.first_ref = -1; diff --git a/ncd/NCDVal.h b/ncd/NCDVal.h index 8be2b1789..a2cedd350 100644 --- a/ncd/NCDVal.h +++ b/ncd/NCDVal.h @@ -64,7 +64,7 @@ * embedded data structure with relativepointers. For example, map values use an * embedded AVL tree. */ -void NCDValMem_Init (NCDValMem *o); +void NCDValMem_Init (NCDValMem *o, NCDStringIndex *string_index); /** * Frees a value memory object. @@ -83,6 +83,11 @@ void NCDValMem_Free (NCDValMem *o); */ int NCDValMem_InitCopy (NCDValMem *o, NCDValMem *other) WARN_UNUSED; +/** + * Get the string index of a value memory object. + */ +NCDStringIndex * NCDValMem_StringIndex (NCDValMem *o); + /** * Does nothing. * The value reference object must either point to a valid value within a valid @@ -252,8 +257,7 @@ NCDValRef NCDVal_NewStringUninitialized (NCDValMem *mem, size_t len); * An IdString is a kind of String which is represented efficiently as a string * identifier via {@link NCDStringIndex}. */ -NCDValRef NCDVal_NewIdString (NCDValMem *mem, NCD_string_id_t string_id, - NCDStringIndex *string_index); +NCDValRef NCDVal_NewIdString (NCDValMem *mem, NCD_string_id_t string_id); /** * Builds a new ExternalString, pointing to the given external data. A reference to @@ -317,23 +321,11 @@ NCDValNullTermString NCDValNullTermString_NewDummy (void); */ void NCDValNullTermString_Free (NCDValNullTermString *o); -/** - * Returns the string ID and the string index of an IdString. - * Both the \a out_string_id and \a out_string_index pointers must be non-NULL. - */ -void NCDVal_IdStringGet (NCDValRef idstring, NCD_string_id_t *out_string_id, - NCDStringIndex **out_string_index); - /** * Returns the string ID of an IdString. */ NCD_string_id_t NCDVal_IdStringId (NCDValRef idstring); -/** - * Returns the string index of an IdString. - */ -NCDStringIndex * NCDVal_IdStringStringIndex (NCDValRef idstring); - /** * Returns the reference target of an ExternalString. This may be NULL * if the external string is not associated with a reference target. @@ -355,11 +347,8 @@ int NCDVal_StringEquals (NCDValRef string, const char *data); /** * Determines if the String is equal to the given string represented * by an {@link NCDStringIndex} identifier. - * NOTE: \a string_index must be equal to the string_index of every ID-string - * that exist within this memory object. */ -int NCDVal_StringEqualsId (NCDValRef string, NCD_string_id_t string_id, - NCDStringIndex *string_index); +int NCDVal_StringEqualsId (NCDValRef string, NCD_string_id_t string_id); /** * Compares two String's in a manner similar to memcmp(). diff --git a/ncd/NCDVal_types.h b/ncd/NCDVal_types.h index 099034f45..59c840df6 100644 --- a/ncd/NCDVal_types.h +++ b/ncd/NCDVal_types.h @@ -42,6 +42,7 @@ typedef int NCDVal__idx; typedef struct { + NCDStringIndex *string_index; NCDVal__idx size; NCDVal__idx used; NCDVal__idx first_ref; diff --git a/ncd/extra/NCDRequestClient.c b/ncd/extra/NCDRequestClient.c index d7d063206..cba9f7ae1 100644 --- a/ncd/extra/NCDRequestClient.c +++ b/ncd/extra/NCDRequestClient.c @@ -217,7 +217,7 @@ static void recv_if_handler_send (NCDRequestClient *o, uint8_t *data, int data_l case RSTATE_READY: { // init memory NCDValMem mem; - NCDValMem_Init(&mem); + NCDValMem_Init(&mem, o->string_index); // parse payload NCDValRef payload_value; @@ -467,7 +467,8 @@ static void req_qflow_send_iface_handler_done (struct NCDRequestClient_req *req) } } -int NCDRequestClient_Init (NCDRequestClient *o, struct BConnection_addr addr, BReactor *reactor, void *user, +int NCDRequestClient_Init (NCDRequestClient *o, struct BConnection_addr addr, BReactor *reactor, NCDStringIndex *string_index, + void *user, NCDRequestClient_handler_error handler_error, NCDRequestClient_handler_connected handler_connected) { @@ -476,6 +477,7 @@ int NCDRequestClient_Init (NCDRequestClient *o, struct BConnection_addr addr, BR // init arguments o->reactor = reactor; + o->string_index = string_index; o->user = user; o->handler_error = handler_error; o->handler_connected = handler_connected; diff --git a/ncd/extra/NCDRequestClient.h b/ncd/extra/NCDRequestClient.h index 7e0a6d5e3..b591727fb 100644 --- a/ncd/extra/NCDRequestClient.h +++ b/ncd/extra/NCDRequestClient.h @@ -55,6 +55,7 @@ typedef void (*NCDRequestClientRequest_handler_finished) (void *user, int is_err typedef struct { BReactor *reactor; + NCDStringIndex *string_index; void *user; NCDRequestClient_handler_error handler_error; NCDRequestClient_handler_connected handler_connected; @@ -96,7 +97,8 @@ struct NCDRequestClient_req { int state; }; -int NCDRequestClient_Init (NCDRequestClient *o, struct BConnection_addr addr, BReactor *reactor, void *user, +int NCDRequestClient_Init (NCDRequestClient *o, struct BConnection_addr addr, BReactor *reactor, NCDStringIndex *string_index, + void *user, NCDRequestClient_handler_error handler_error, NCDRequestClient_handler_connected handler_connected) WARN_UNUSED; void NCDRequestClient_Free (NCDRequestClient *o); diff --git a/ncd/extra/value_utils.c b/ncd/extra/value_utils.c index 18e0b9ba9..11765a8e2 100644 --- a/ncd/extra/value_utils.c +++ b/ncd/extra/value_utils.c @@ -54,13 +54,12 @@ int ncd_is_none (NCDValRef string) } } -NCDValRef ncd_make_boolean (NCDValMem *mem, int value, NCDStringIndex *string_index) +NCDValRef ncd_make_boolean (NCDValMem *mem, int value) { ASSERT(mem) - ASSERT(string_index) NCD_string_id_t str_id = (value ? NCD_STRING_TRUE : NCD_STRING_FALSE); - return NCDVal_NewIdString(mem, str_id, string_index); + return NCDVal_NewIdString(mem, str_id); } int ncd_read_boolean (NCDValRef val, int *out) @@ -106,16 +105,15 @@ int ncd_read_time (NCDValRef val, btime_t *out) return 1; } -NCD_string_id_t ncd_get_string_id (NCDValRef string, NCDStringIndex *string_index) +NCD_string_id_t ncd_get_string_id (NCDValRef string) { ASSERT(NCDVal_IsString(string)) - ASSERT(string_index) if (NCDVal_IsIdString(string)) { return NCDVal_IdStringId(string); } - return NCDStringIndex_GetBinMr(string_index, NCDVal_StringMemRef(string)); + return NCDStringIndex_GetBinMr(NCDValMem_StringIndex(string.mem), NCDVal_StringMemRef(string)); } NCDValRef ncd_make_uintmax (NCDValMem *mem, uintmax_t value) diff --git a/ncd/extra/value_utils.h b/ncd/extra/value_utils.h index 924b20fb0..01062791d 100644 --- a/ncd/extra/value_utils.h +++ b/ncd/extra/value_utils.h @@ -39,11 +39,11 @@ #include int ncd_is_none (NCDValRef val); -NCDValRef ncd_make_boolean (NCDValMem *mem, int value, NCDStringIndex *string_index); +NCDValRef ncd_make_boolean (NCDValMem *mem, int value); int ncd_read_boolean (NCDValRef val, int *out) WARN_UNUSED; int ncd_read_uintmax (NCDValRef string, uintmax_t *out) WARN_UNUSED; int ncd_read_time (NCDValRef string, btime_t *out) WARN_UNUSED; -NCD_string_id_t ncd_get_string_id (NCDValRef string, NCDStringIndex *string_index); +NCD_string_id_t ncd_get_string_id (NCDValRef string); NCDValRef ncd_make_uintmax (NCDValMem *mem, uintmax_t value); char * ncd_strdup (NCDValRef stringnonulls); int ncd_eval_func_args_ext (NCDCall const *call, size_t start, size_t count, NCDValMem *mem, NCDValRef *out) WARN_UNUSED; diff --git a/ncd/modules/arithmetic.c b/ncd/modules/arithmetic.c index 59b41e99c..50a5c8de2 100644 --- a/ncd/modules/arithmetic.c +++ b/ncd/modules/arithmetic.c @@ -207,7 +207,7 @@ static int boolean_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, struct boolean_instance *o = vo; if (name == NCD_STRING_EMPTY) { - *out = ncd_make_boolean(mem, o->value, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->value); return 1; } @@ -252,7 +252,7 @@ static int number_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, struct number_instance *o = vo; if (name == NCD_STRING_IS_ERROR) { - *out = ncd_make_boolean(mem, !!o->error, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, !!o->error); return 1; } diff --git a/ncd/modules/assert.c b/ncd/modules/assert.c index 95348c42a..295b2f244 100644 --- a/ncd/modules/assert.c +++ b/ncd/modules/assert.c @@ -62,8 +62,8 @@ static void func_new_common (NCDModuleInst *i, const struct NCDModuleInst_new_pa NCDModuleInst_Backend_Up(i); // if failed, initiate exit (before up!) - if ((!is_false && !NCDVal_StringEqualsId(cond_arg, NCD_STRING_TRUE, i->params->iparams->string_index)) || - (is_false && !NCDVal_StringEqualsId(cond_arg, NCD_STRING_FALSE, i->params->iparams->string_index)) + if ((!is_false && !NCDVal_StringEqualsId(cond_arg, NCD_STRING_TRUE)) || + (is_false && !NCDVal_StringEqualsId(cond_arg, NCD_STRING_FALSE)) ) { ModuleLog(i, BLOG_ERROR, "assertion failed"); NCDModuleInst_Backend_InterpExit(i, 1); diff --git a/ncd/modules/basic_functions.c b/ncd/modules/basic_functions.c index f6ab885d2..3d7ff6ea7 100644 --- a/ncd/modules/basic_functions.c +++ b/ncd/modules/basic_functions.c @@ -124,7 +124,7 @@ static void bool_not_eval (NCDCall call, int negate, char const *name) return FunctionLog(&call, BLOG_ERROR, "%s: bad argument", name); } int res = (arg_val != negate); - NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res, NCDCall_Iparams(&call)->string_index)); + NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res)); } static void bool_eval (NCDCall call) { return bool_not_eval(call, 0, "bool"); } @@ -148,7 +148,7 @@ static void and_or_eval (NCDCall call, int is_and, char const *name) break; } } - NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res, NCDCall_Iparams(&call)->string_index)); + NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res)); } static void and_eval (NCDCall call) { return and_or_eval(call, 1, "and"); } @@ -174,7 +174,7 @@ static void imp_eval (NCDCall call) break; } } - NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res, NCDCall_Iparams(&call)->string_index)); + NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res)); } @@ -195,7 +195,7 @@ static void value_compare_eval (NCDCall call, value_compare_func func) } } int res = func(NCDVal_Compare(vals[0], vals[1])); - NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res, NCDCall_Iparams(&call)->string_index)); + NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res)); } #define DEFINE_VALUE_COMPARE(name, expr) \ @@ -316,7 +316,7 @@ static void integer_compare_eval (NCDCall call, integer_compare_func func) } } int res = func(ints[0], ints[1]); - NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res, NCDCall_Iparams(&call)->string_index)); + NCDCall_SetResult(&call, ncd_make_boolean(NCDCall_ResMem(&call), res)); } #define DEFINE_INT_COMPARE(name, expr) \ @@ -406,7 +406,7 @@ static void decode_value_eval (NCDCall call) // Otherwise the ResMem could get resized while we're // parsing a string within it, and boom. NCDValMem temp_mem; - NCDValMem_Init(&temp_mem); + NCDValMem_Init(&temp_mem, NCDCall_Iparams(&call)->string_index); NCDValRef arg = NCDCall_EvalArg(&call, 0, &temp_mem); if (NCDVal_IsInvalid(arg)) { goto fail1; @@ -604,7 +604,7 @@ static void struct_decode_eval (NCDCall call) } // Evaluate the data string to temp mem, so the pointer doesn't change. NCDValMem temp_mem; - NCDValMem_Init(&temp_mem); + NCDValMem_Init(&temp_mem, NCDCall_Iparams(&call)->string_index); NCDValRef data_arg = NCDCall_EvalArg(&call, 1, &temp_mem); if (NCDVal_IsInvalid(data_arg)) { goto fail1; diff --git a/ncd/modules/blocker.c b/ncd/modules/blocker.c index 64fbe5be7..3afda21e5 100644 --- a/ncd/modules/blocker.c +++ b/ncd/modules/blocker.c @@ -179,7 +179,7 @@ static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValR struct instance *o = vo; if (name == NCD_STRING_EMPTY) { - *out = ncd_make_boolean(mem, o->up, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->up); return 1; } diff --git a/ncd/modules/file.c b/ncd/modules/file.c index 45d101497..b37262174 100644 --- a/ncd/modules/file.c +++ b/ncd/modules/file.c @@ -266,7 +266,7 @@ static int stat_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NC struct stat_instance *o = vo; if (name == NCD_STRING_SUCCEEDED) { - *out = ncd_make_boolean(mem, o->succeeded, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->succeeded); return 1; } diff --git a/ncd/modules/file_open.c b/ncd/modules/file_open.c index 5c72174d0..d63c7405c 100644 --- a/ncd/modules/file_open.c +++ b/ncd/modules/file_open.c @@ -287,7 +287,7 @@ static int open_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, NCD struct open_instance *o = vo; if (name == NCD_STRING_IS_ERROR) { - *out = ncd_make_boolean(mem, !o->fh, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, !o->fh); return 1; } @@ -374,7 +374,7 @@ static int read_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, NCD } if (name == NCD_STRING_NOT_EOF) { - *out = ncd_make_boolean(mem, (o->length != 0), o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, (o->length != 0)); return 1; } diff --git a/ncd/modules/foreach.c b/ncd/modules/foreach.c index 5e71423ca..82823e251 100644 --- a/ncd/modules/foreach.c +++ b/ncd/modules/foreach.c @@ -620,7 +620,7 @@ static void func_new_foreach_emb (void *vo, NCDModuleInst *i, const struct NCDMo goto fail0; } - NCD_string_id_t name1 = ncd_get_string_id(arg_name1, i->params->iparams->string_index); + NCD_string_id_t name1 = ncd_get_string_id(arg_name1); if (name1 < 0) { ModuleLog(i, BLOG_ERROR, "ncd_get_string_id failed"); goto fail0; @@ -628,7 +628,7 @@ static void func_new_foreach_emb (void *vo, NCDModuleInst *i, const struct NCDMo NCD_string_id_t name2 = -1; if (!NCDVal_IsInvalid(arg_name2)) { - name2 = ncd_get_string_id(arg_name2, i->params->iparams->string_index); + name2 = ncd_get_string_id(arg_name2); if (name2 < 0) { ModuleLog(i, BLOG_ERROR, "ncd_get_string_id failed"); goto fail0; diff --git a/ncd/modules/from_string.c b/ncd/modules/from_string.c index 6dd395fa6..05d330d54 100644 --- a/ncd/modules/from_string.c +++ b/ncd/modules/from_string.c @@ -66,7 +66,7 @@ static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new } // init mem - NCDValMem_Init(&o->mem); + NCDValMem_Init(&o->mem, i->params->iparams->string_index); // parse value string if (!NCDValParser_Parse(NCDVal_StringMemRef(str_arg), &o->mem, &o->val)) { diff --git a/ncd/modules/getenv.c b/ncd/modules/getenv.c index 10a454c62..08b4e7779 100644 --- a/ncd/modules/getenv.c +++ b/ncd/modules/getenv.c @@ -124,7 +124,7 @@ static int func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRe } if (name == ModuleString(o->i, STRING_EXISTS)) { - *out = ncd_make_boolean(mem, !!o->value, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, !!o->value); return 1; } diff --git a/ncd/modules/list.c b/ncd/modules/list.c index a7228fc94..67f667ff6 100644 --- a/ncd/modules/list.c +++ b/ncd/modules/list.c @@ -149,7 +149,7 @@ static struct elem * insert_value (NCDModuleInst *i, struct instance *o, NCDValR goto fail0; } - NCDValMem_Init(&e->mem); + NCDValMem_Init(&e->mem, i->params->iparams->string_index); e->val = NCDVal_NewCopy(&e->mem, val); if (NCDVal_IsInvalid(e->val)) { @@ -517,7 +517,7 @@ static void get_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst struct elem *e = get_elem_at(mo, index); // init mem - NCDValMem_Init(&o->mem); + NCDValMem_Init(&o->mem, i->params->iparams->string_index); // copy value o->val = NCDVal_NewCopy(&o->mem, e->val); @@ -623,7 +623,7 @@ static int contains_func_getvar (void *vo, const char *name, NCDValMem *mem, NCD struct contains_instance *o = vo; if (!strcmp(name, "")) { - *out = ncd_make_boolean(mem, o->contains, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->contains); return 1; } @@ -687,7 +687,7 @@ static int find_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValR } if (!strcmp(name, "found")) { - *out = ncd_make_boolean(mem, o->is_found, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->is_found); return 1; } diff --git a/ncd/modules/log.c b/ncd/modules/log.c index 452115cfe..89f8b45d0 100644 --- a/ncd/modules/log.c +++ b/ncd/modules/log.c @@ -116,22 +116,21 @@ static int parse_level (NCDModuleInst *i, NCDValRef level_arg, int *out_level) { int found = 0; if (NCDVal_IsString(level_arg)) { - NCDStringIndex *string_index = i->params->iparams->string_index; found = 1; - if (NCDVal_StringEqualsId(level_arg, ModuleString(i, STRING_ERROR), string_index)) { + if (NCDVal_StringEqualsId(level_arg, ModuleString(i, STRING_ERROR))) { *out_level = BLOG_ERROR; } - else if (NCDVal_StringEqualsId(level_arg, ModuleString(i, STRING_WARNING), string_index)) { + else if (NCDVal_StringEqualsId(level_arg, ModuleString(i, STRING_WARNING))) { *out_level = BLOG_WARNING; } - else if (NCDVal_StringEqualsId(level_arg, ModuleString(i, STRING_NOTICE), string_index)) { + else if (NCDVal_StringEqualsId(level_arg, ModuleString(i, STRING_NOTICE))) { *out_level = BLOG_NOTICE; } - else if (NCDVal_StringEqualsId(level_arg, ModuleString(i, STRING_INFO), string_index)) { + else if (NCDVal_StringEqualsId(level_arg, ModuleString(i, STRING_INFO))) { *out_level = BLOG_INFO; } - else if (NCDVal_StringEqualsId(level_arg, ModuleString(i, STRING_DEBUG), string_index)) { + else if (NCDVal_StringEqualsId(level_arg, ModuleString(i, STRING_DEBUG))) { *out_level = BLOG_DEBUG; } else { diff --git a/ncd/modules/logical.c b/ncd/modules/logical.c index 7a0a79a3b..d7cea6451 100644 --- a/ncd/modules/logical.c +++ b/ncd/modules/logical.c @@ -124,7 +124,7 @@ static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValR struct instance *o = vo; if (name == NCD_STRING_EMPTY) { - *out = ncd_make_boolean(mem, o->value, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->value); return 1; } diff --git a/ncd/modules/net_ipv4_addr_in_network.c b/ncd/modules/net_ipv4_addr_in_network.c index 58e3ea69a..516b6815f 100644 --- a/ncd/modules/net_ipv4_addr_in_network.c +++ b/ncd/modules/net_ipv4_addr_in_network.c @@ -138,7 +138,7 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o struct instance *o = vo; if (!strcmp(name, "")) { - *out = ncd_make_boolean(mem, o->value, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->value); return 1; } diff --git a/ncd/modules/net_ipv4_arp_probe.c b/ncd/modules/net_ipv4_arp_probe.c index 7f9bde8fc..15146419a 100644 --- a/ncd/modules/net_ipv4_arp_probe.c +++ b/ncd/modules/net_ipv4_arp_probe.c @@ -186,7 +186,7 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o ASSERT(o->state == STATE_EXIST || o->state == STATE_NOEXIST) if (!strcmp(name, "exists")) { - *out = ncd_make_boolean(mem, o->state == STATE_EXIST, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->state == STATE_EXIST); return 1; } diff --git a/ncd/modules/net_ipv6_addr_in_network.c b/ncd/modules/net_ipv6_addr_in_network.c index 4728a9d0f..3090a3bdc 100644 --- a/ncd/modules/net_ipv6_addr_in_network.c +++ b/ncd/modules/net_ipv6_addr_in_network.c @@ -138,7 +138,7 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o struct instance *o = vo; if (!strcmp(name, "")) { - *out = ncd_make_boolean(mem, o->value, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->value); return 1; } diff --git a/ncd/modules/objref.c b/ncd/modules/objref.c index ca2d3a2dc..cdccbeaf6 100644 --- a/ncd/modules/objref.c +++ b/ncd/modules/objref.c @@ -89,7 +89,7 @@ static void func_new_common (void *vo, NCDModuleInst *i, const struct NCDModuleI goto fail1; } - NCD_string_id_t name_id = ncd_get_string_id(name_val, i->params->iparams->string_index); + NCD_string_id_t name_id = ncd_get_string_id(name_val); if (name_id < 0) { ModuleLog(i, BLOG_ERROR, "ncd_get_string_id failed"); goto fail1; diff --git a/ncd/modules/parse.c b/ncd/modules/parse.c index 5237332e1..6c808041d 100644 --- a/ncd/modules/parse.c +++ b/ncd/modules/parse.c @@ -187,7 +187,7 @@ static void new_templ (void *vo, NCDModuleInst *i, const struct NCDModuleInst_ne } // init mem - NCDValMem_Init(&o->mem); + NCDValMem_Init(&o->mem, i->params->iparams->string_index); // parse o->succeeded = pfunc(i, NCDVal_StringMemRef(str_arg), &o->mem, &o->value); @@ -215,7 +215,7 @@ static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValR struct instance *o = vo; if (name == NCD_STRING_SUCCEEDED) { - *out = ncd_make_boolean(mem, o->succeeded, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->succeeded); return 1; } @@ -281,7 +281,7 @@ static int ipv4_cidr_addr_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMe struct ipv4_cidr_instance *o = vo; if (name == NCD_STRING_SUCCEEDED) { - *out = ncd_make_boolean(mem, o->succeeded, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->succeeded); return 1; } @@ -337,7 +337,7 @@ static int ipv6_cidr_addr_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMe struct ipv6_cidr_instance *o = vo; if (name == NCD_STRING_SUCCEEDED) { - *out = ncd_make_boolean(mem, o->succeeded, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->succeeded); return 1; } diff --git a/ncd/modules/process_manager.c b/ncd/modules/process_manager.c index 6bd786ce2..538266d00 100644 --- a/ncd/modules/process_manager.c +++ b/ncd/modules/process_manager.c @@ -162,7 +162,7 @@ static int process_new (struct instance *o, NCDValMem *mem, NCDValSafeRef name, BSmallTimer_Init(&p->retry_timer, process_retry_timer_handler); // init template name - p->template_name = ncd_get_string_id(NCDVal_FromSafe(mem, template_name), o->i->params->iparams->string_index); + p->template_name = ncd_get_string_id(NCDVal_FromSafe(mem, template_name)); if (p->template_name < 0) { ModuleLog(o->i, BLOG_ERROR, "ncd_get_string_id failed"); goto fail1; diff --git a/ncd/modules/regex_match.c b/ncd/modules/regex_match.c index ee01d58bb..747494e42 100644 --- a/ncd/modules/regex_match.c +++ b/ncd/modules/regex_match.c @@ -155,7 +155,7 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o struct instance *o = vo; if (!strcmp(name, "succeeded")) { - *out = ncd_make_boolean(mem, o->succeeded, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->succeeded); return 1; } diff --git a/ncd/modules/sleep.c b/ncd/modules/sleep.c index 91b1ea397..9f2f06ecc 100644 --- a/ncd/modules/sleep.c +++ b/ncd/modules/sleep.c @@ -89,7 +89,7 @@ static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new uintmax_t ms; btime_t ms_start; - if (NCDVal_IsString(ms_start_arg) && NCDVal_StringEqualsId(ms_start_arg, NCD_STRING_EMPTY, i->params->iparams->string_index)) { + if (NCDVal_IsString(ms_start_arg) && NCDVal_StringEqualsId(ms_start_arg, NCD_STRING_EMPTY)) { ms_start = -1; } else { if (!ncd_read_uintmax(ms_start_arg, &ms) || ms > INT64_MAX) { @@ -99,7 +99,7 @@ static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new ms_start = ms; } - if (NCDVal_IsInvalid(ms_stop_arg) || (NCDVal_IsString(ms_stop_arg) && NCDVal_StringEqualsId(ms_stop_arg, NCD_STRING_EMPTY, i->params->iparams->string_index))) { + if (NCDVal_IsInvalid(ms_stop_arg) || (NCDVal_IsString(ms_stop_arg) && NCDVal_StringEqualsId(ms_stop_arg, NCD_STRING_EMPTY))) { o->ms_stop = -1; } else { if (!ncd_read_uintmax(ms_stop_arg, &ms) || ms > INT64_MAX) { diff --git a/ncd/modules/socket.c b/ncd/modules/socket.c index 6491e8ad7..3daa3064c 100644 --- a/ncd/modules/socket.c +++ b/ncd/modules/socket.c @@ -767,7 +767,7 @@ static int connect_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, if (name == NCD_STRING_IS_ERROR) { int is_error = (o->state == CONNECTION_STATE_ERROR); - *out = ncd_make_boolean(mem, is_error, o->connect.i->params->iparams->string_index); + *out = ncd_make_boolean(mem, is_error); return 1; } @@ -859,7 +859,7 @@ static int read_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, NCD } if (name == NCD_STRING_EOF || name == NCD_STRING_NOT_EOF) { - *out = ncd_make_boolean(mem, (o->read_size == 0) == (name == NCD_STRING_EOF), o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, (o->read_size == 0) == (name == NCD_STRING_EOF)); return 1; } @@ -1065,7 +1065,7 @@ static int listen_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, N struct listen_instance *o = vo; if (name == NCD_STRING_IS_ERROR) { - *out = ncd_make_boolean(mem, o->have_error, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->have_error); return 1; } diff --git a/ncd/modules/strcmp.c b/ncd/modules/strcmp.c index 23a9af72d..f81417161 100644 --- a/ncd/modules/strcmp.c +++ b/ncd/modules/strcmp.c @@ -80,7 +80,7 @@ static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValR struct instance *o = vo; if (name == NCD_STRING_EMPTY) { - *out = ncd_make_boolean(mem, o->result, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->result); return 1; } diff --git a/ncd/modules/sys_request_client.c b/ncd/modules/sys_request_client.c index b1ee4f1bb..2e5847722 100644 --- a/ncd/modules/sys_request_client.c +++ b/ncd/modules/sys_request_client.c @@ -487,7 +487,7 @@ static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new } // init client - if (!NCDRequestClient_Init(&o->client, addr, i->params->iparams->reactor, o, + if (!NCDRequestClient_Init(&o->client, addr, i->params->iparams->reactor, i->params->iparams->string_index, o, (NCDRequestClient_handler_error)client_handler_error, (NCDRequestClient_handler_connected)client_handler_connected)) { ModuleLog(o->i, BLOG_ERROR, "NCDRequestClient_Init failed"); diff --git a/ncd/modules/sys_request_server.c b/ncd/modules/sys_request_server.c index c99d37aff..825db125d 100644 --- a/ncd/modules/sys_request_server.c +++ b/ncd/modules/sys_request_server.c @@ -380,7 +380,7 @@ static int request_init (struct connection *c, uint32_t request_id, const uint8_ LinkedList0_Prepend(&c->requests_list, &r->requests_list_node); - NCDValMem_Init(&r->request_data_mem); + NCDValMem_Init(&r->request_data_mem, o->i->params->iparams->string_index); if (!NCDValParser_Parse(MemRef_Make((const char *)data, data_len), &r->request_data_mem, &r->request_data)) { ModuleLog(o->i, BLOG_ERROR, "NCDValParser_Parse failed"); diff --git a/ncd/modules/sys_start_process.c b/ncd/modules/sys_start_process.c index 91bc7905d..7518584e9 100644 --- a/ncd/modules/sys_start_process.c +++ b/ncd/modules/sys_start_process.c @@ -324,7 +324,7 @@ static int opts_func_unknown (void *user, NCDValRef key, NCDValRef val) if (NCDVal_IsString(val) && NCDVal_StringEquals(val, "never")) { o->deinit_kill_time = -2; } - else if (NCDVal_IsString(val) && NCDVal_StringEqualsId(val, NCD_STRING_EMPTY, o->i->params->iparams->string_index)) { + else if (NCDVal_IsString(val) && NCDVal_StringEqualsId(val, NCD_STRING_EMPTY)) { o->deinit_kill_time = -1; } else if (!ncd_read_time(val, &o->deinit_kill_time)) { @@ -533,7 +533,7 @@ static int process_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, if (name == NCD_STRING_IS_ERROR) { int is_error = (o->state == PROCESS_STATE_ERROR); - *out = ncd_make_boolean(mem, is_error, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, is_error); return 1; } @@ -802,7 +802,7 @@ static int read_pipe_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem if (name == NCD_STRING_IS_ERROR) { int is_error = (o->state == READER_STATE_ERROR); - *out = ncd_make_boolean(mem, is_error, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, is_error); return 1; } @@ -903,14 +903,14 @@ static int read_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *mem, NCD if (o->read_size > 0) { *out = NCDVal_NewExternalString(mem, NCDBuf_Data(o->buf), o->read_size, NCDBuf_RefTarget(o->buf)); } else { - *out = NCDVal_NewIdString(mem, NCD_STRING_EMPTY, o->i->params->iparams->string_index); + *out = NCDVal_NewIdString(mem, NCD_STRING_EMPTY); } return 1; } if (name == NCD_STRING_NOT_EOF) { int not_eof = (o->read_size > 0); - *out = ncd_make_boolean(mem, not_eof, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, not_eof); return 1; } @@ -1067,7 +1067,7 @@ static int write_pipe_func_getvar (void *vo, NCD_string_id_t name, NCDValMem *me if (name == NCD_STRING_IS_ERROR) { int is_error = (o->state == WRITER_STATE_ERROR); - *out = ncd_make_boolean(mem, is_error, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, is_error); return 1; } diff --git a/ncd/modules/try.c b/ncd/modules/try.c index ab6816a68..c7e6bacb9 100644 --- a/ncd/modules/try.c +++ b/ncd/modules/try.c @@ -390,7 +390,7 @@ static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValR ASSERT(!o->dying) if (name == NCD_STRING_SUCCEEDED) { - *out = ncd_make_boolean(mem, o->succeeded, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->succeeded); return 1; } diff --git a/ncd/modules/value.c b/ncd/modules/value.c index 4c99ca40b..36590f5a1 100644 --- a/ncd/modules/value.c +++ b/ncd/modules/value.c @@ -709,7 +709,7 @@ static struct value * value_init_fromvalue (NCDModuleInst *i, NCDValRef value) switch (NCDVal_Type(value)) { case NCDVAL_STRING: { if (NCDVal_IsIdString(value)) { - v = value_init_idstring(i, NCDVal_IdStringId(value), NCDVal_IdStringStringIndex(value)); + v = value_init_idstring(i, NCDVal_IdStringId(value), NCDValMem_StringIndex(value.mem)); } else if (NCDVal_IsExternalString(value)) { v = value_init_externalstring(i, NCDVal_StringMemRef(value), NCDVal_ExternalStringTarget(value)); } else { @@ -750,7 +750,7 @@ static struct value * value_init_fromvalue (NCDModuleInst *i, NCDValRef value) NCDValRef eval = NCDVal_MapElemVal(value, e); NCDValMem key_mem; - NCDValMem_Init(&key_mem); + NCDValMem_Init(&key_mem, i->params->iparams->string_index); NCDValRef key = NCDVal_NewCopy(&key_mem, ekey); if (NCDVal_IsInvalid(key)) { @@ -799,7 +799,7 @@ static int value_to_value (NCDModuleInst *i, struct value *v, NCDValMem *mem, NC } break; case IDSTRING_TYPE: { - *out_value = NCDVal_NewIdString(mem, v->idstring.id, v->idstring.string_index); + *out_value = NCDVal_NewIdString(mem, v->idstring.id); if (NCDVal_IsInvalid(*out_value)) { goto fail; } @@ -985,7 +985,7 @@ static struct value * value_insert (NCDModuleInst *i, struct value *v, NCDValRef } NCDValMem key_mem; - NCDValMem_Init(&key_mem); + NCDValMem_Init(&key_mem, i->params->iparams->string_index); NCDValRef key = NCDVal_NewCopy(&key_mem, where); if (NCDVal_IsInvalid(key)) { @@ -1239,7 +1239,7 @@ static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValR struct value *v = valref_val(&o->ref); if (name == ModuleString(o->i, STRING_EXISTS)) { - *out = ncd_make_boolean(mem, !!v, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, !!v); return 1; } diff --git a/ncd/modules/valuemetic.c b/ncd/modules/valuemetic.c index 0ab76a712..66bee530e 100644 --- a/ncd/modules/valuemetic.c +++ b/ncd/modules/valuemetic.c @@ -131,7 +131,7 @@ static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValR struct instance *o = vo; if (name == NCD_STRING_EMPTY) { - *out = ncd_make_boolean(mem, o->result, o->i->params->iparams->string_index); + *out = ncd_make_boolean(mem, o->result); return 1; } diff --git a/ncd/modules/var.c b/ncd/modules/var.c index 3a277769a..ad46757b9 100644 --- a/ncd/modules/var.c +++ b/ncd/modules/var.c @@ -63,7 +63,7 @@ static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new } // init mem - NCDValMem_Init(&o->mem); + NCDValMem_Init(&o->mem, i->params->iparams->string_index); // copy value o->value = NCDVal_NewCopy(&o->mem, value_arg); @@ -117,7 +117,7 @@ static void set_func_new (void *unused, NCDModuleInst *i, const struct NCDModule // allocate new mem NCDValMem mem; - NCDValMem_Init(&mem); + NCDValMem_Init(&mem, i->params->iparams->string_index); // copy value NCDValRef copy = NCDVal_NewCopy(&mem, value_arg);