Explorar o código

ncd: port some modules to func_getvar2

ambrop7 %!s(int64=13) %!d(string=hai) anos
pai
achega
f6a58006cc

+ 14 - 13
ncd/modules/arithmetic.c

@@ -71,6 +71,7 @@
 
 #include <misc/parse_number.h>
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_arithmetic.h>
 
@@ -209,11 +210,11 @@ fail0:
     NCDModuleInst_Backend_Dead(i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewString(mem, o->value);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
@@ -283,57 +284,57 @@ static struct NCDModule modules[] = {
     {
         .type = "num_lesser",
         .func_new2 = func_new_lesser,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "num_greater",
         .func_new2 = func_new_greater,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "num_lesser_equal",
         .func_new2 = func_new_lesser_equal,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "num_greater_equal",
         .func_new2 = func_new_greater_equal,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "num_equal",
         .func_new2 = func_new_equal,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "num_different",
         .func_new2 = func_new_different,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "num_add",
         .func_new2 = func_new_add,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "num_subtract",
         .func_new2 = func_new_subtract,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "num_multiply",
         .func_new2 = func_new_multiply,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "num_divide",
         .func_new2 = func_new_divide,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "num_modulo",
         .func_new2 = func_new_modulo,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 4 - 3
ncd/modules/choose.c

@@ -44,6 +44,7 @@
 #include <string.h>
 
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_choose.h>
 
@@ -116,11 +117,11 @@ fail0:
     NCDModuleInst_Backend_Dead(i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewCopy(mem, o->result);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewCopy failed");
@@ -135,7 +136,7 @@ static struct NCDModule modules[] = {
     {
         .type = "choose",
         .func_new2 = func_new,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 4 - 3
ncd/modules/concat.c

@@ -39,6 +39,7 @@
 
 #include <misc/expstring.h>
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_concat.h>
 
@@ -103,11 +104,11 @@ static void func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewStringBin(mem, o->string, o->len);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewStringBin failed");
@@ -123,7 +124,7 @@ static struct NCDModule modules[] = {
         .type = "concat",
         .func_new2 = func_new,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 4 - 3
ncd/modules/concatv.c

@@ -39,6 +39,7 @@
 
 #include <misc/expstring.h>
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_concatv.h>
 
@@ -114,11 +115,11 @@ static void func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewStringBin(mem, o->string, o->len);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewStringBin failed");
@@ -134,7 +135,7 @@ static struct NCDModule modules[] = {
         .type = "concatv",
         .func_new2 = func_new,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 4 - 3
ncd/modules/explode.c

@@ -53,6 +53,7 @@
 #include <misc/substring.h>
 #include <misc/balloc.h>
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_explode.h>
 
@@ -186,11 +187,11 @@ static void func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewList(mem, o->num);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewList failed");
@@ -220,7 +221,7 @@ static struct NCDModule modules[] = {
         .type = "explode",
         .func_new2 = func_new,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 18 - 10
ncd/modules/file.c

@@ -88,6 +88,7 @@
 #include <misc/read_file.h>
 #include <misc/write_file.h>
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_file.h>
 
@@ -105,6 +106,12 @@ struct stat_instance {
     struct stat result;
 };
 
+enum {STRING_SUCCEEDED, STRING_TYPE, STRING_SIZE};
+
+static struct NCD_string_request strings[] = {
+    {"succeeded"}, {"type"}, {"size"}, {NULL}
+};
+
 static void read_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
 {
     struct read_instance *o = vo;
@@ -146,11 +153,11 @@ static void read_func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int read_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int read_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct read_instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewStringBin(mem, o->file_data, o->file_len);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewStringBin failed");
@@ -244,11 +251,11 @@ static void lstat_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleIn
     stat_func_new_common(vo, i, params, 1);
 }
 
-static int stat_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int stat_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct stat_instance *o = vo;
     
-    if (!strcmp(name, "succeeded")) {
+    if (name == strings[STRING_SUCCEEDED].id) {
         const char *str = (o->succeeded ? "true" : "false");
         *out = NCDVal_NewString(mem, str);
         if (NCDVal_IsInvalid(*out)) {
@@ -257,7 +264,7 @@ static int stat_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValR
         return 1;
     }
     
-    if (!strcmp(name, "type")) {
+    if (name == strings[STRING_TYPE].id) {
         const char *str;
         
         if (!o->succeeded) {
@@ -287,7 +294,7 @@ static int stat_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValR
         return 1;
     }
     
-    if (!strcmp(name, "size")) {
+    if (name == strings[STRING_SIZE].id) {
         char str[50];
         if (!o->succeeded) {
             strcpy(str, "failed");
@@ -310,7 +317,7 @@ static struct NCDModule modules[] = {
         .type = "file_read",
         .func_new2 = read_func_new,
         .func_die = read_func_die,
-        .func_getvar = read_func_getvar,
+        .func_getvar2 = read_func_getvar2,
         .alloc_size = sizeof(struct read_instance)
     }, {
         .type = "file_write",
@@ -318,12 +325,12 @@ static struct NCDModule modules[] = {
     }, {
         .type = "file_stat",
         .func_new2 = stat_func_new,
-        .func_getvar = stat_func_getvar,
+        .func_getvar2 = stat_func_getvar2,
         .alloc_size = sizeof(struct stat_instance)
     }, {
         .type = "file_lstat",
         .func_new2 = lstat_func_new,
-        .func_getvar = stat_func_getvar,
+        .func_getvar2 = stat_func_getvar2,
         .alloc_size = sizeof(struct stat_instance)
     }, {
         .type = NULL
@@ -331,5 +338,6 @@ static struct NCDModule modules[] = {
 };
 
 const struct NCDModuleGroup ncdmodule_file = {
-    .modules = modules
+    .modules = modules,
+    .strings = strings
 };

+ 4 - 3
ncd/modules/from_string.c

@@ -39,6 +39,7 @@
 
 #include <ncd/NCDModule.h>
 #include <ncd/NCDValParser.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_from_string.h>
 
@@ -97,11 +98,11 @@ static void func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewCopy(mem, o->val);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewCopy failed");
@@ -117,7 +118,7 @@ static struct NCDModule modules[] = {
         .type = "from_string",
         .func_new2 = func_new,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 4 - 3
ncd/modules/getargs.c

@@ -38,6 +38,7 @@
 #include <string.h>
 
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_getargs.h>
 
@@ -62,11 +63,11 @@ fail0:
     NCDModuleInst_Backend_Dead(i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     NCDModuleInst *i = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         if (!NCDModuleInst_Backend_InterpGetArgs(i, mem, out)) {
             ModuleLog(i, BLOG_ERROR, "NCDModuleInst_Backend_InterpGetArgs failed");
             return 0;
@@ -81,7 +82,7 @@ static struct NCDModule modules[] = {
     {
         .type = "getargs",
         .func_new2 = func_new,
-        .func_getvar = func_getvar
+        .func_getvar2 = func_getvar2
     }, {
         .type = NULL
     }

+ 4 - 3
ncd/modules/implode.c

@@ -41,6 +41,7 @@
 
 #include <misc/expstring.h>
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_implode.h>
 
@@ -126,11 +127,11 @@ static void func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewStringBin(mem, (uint8_t *)o->result, o->result_len);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewStringBin failed");
@@ -146,7 +147,7 @@ static struct NCDModule modules[] = {
         .type = "implode",
         .func_new2 = func_new,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 6 - 5
ncd/modules/logical.c

@@ -47,6 +47,7 @@
 #include <string.h>
 
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_logical.h>
 
@@ -121,11 +122,11 @@ static void func_new_and (void *vo, NCDModuleInst *i, const struct NCDModuleInst
     func_new(vo, i, params, 0, 0);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         const char *v = (o->value ? "true" : "false");
         
         *out = NCDVal_NewString(mem, v);
@@ -142,17 +143,17 @@ static struct NCDModule modules[] = {
     {
         .type = "not",
         .func_new2 = func_new_not,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "or",
         .func_new2 = func_new_or,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "and",
         .func_new2 = func_new_and,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 8 - 7
ncd/modules/netmask.c

@@ -57,6 +57,7 @@
 #include <misc/ipaddr.h>
 #include <misc/parse_number.h>
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_netmask.h>
 
@@ -161,11 +162,11 @@ static void addr_func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int addr_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int addr_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct addr_instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         char buf[IPADDR_PRINT_MAX];
         ipaddr_print_addr(o->addr, buf);
         
@@ -224,11 +225,11 @@ static void prefix_func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int prefix_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int prefix_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct prefix_instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         char buf[6];
         sprintf(buf, "%d", o->prefix);
         
@@ -247,19 +248,19 @@ static struct NCDModule modules[] = {
         .type = "ipv4_prefix_to_mask",
         .func_new2 = prefix_to_mask_func_init,
         .func_die = addr_func_die,
-        .func_getvar = addr_func_getvar,
+        .func_getvar2 = addr_func_getvar2,
         .alloc_size = sizeof(struct addr_instance)
     }, {
         .type = "ipv4_mask_to_prefix",
         .func_new2 = mask_to_prefix_func_init,
         .func_die = prefix_func_die,
-        .func_getvar = prefix_func_getvar,
+        .func_getvar2 = prefix_func_getvar2,
         .alloc_size = sizeof(struct prefix_instance)
     }, {
         .type = "ipv4_net_from_addr_and_prefix",
         .func_new2 = ipv4_net_from_addr_and_prefix_func_init,
         .func_die = addr_func_die,
-        .func_getvar = addr_func_getvar,
+        .func_getvar2 = addr_func_getvar2,
         .alloc_size = sizeof(struct addr_instance)
     }, {
         .type = NULL

+ 21 - 13
ncd/modules/parse.c

@@ -56,6 +56,7 @@
 #include <misc/ipaddr.h>
 #include <ncd/NCDValParser.h>
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_parse.h>
 
@@ -74,6 +75,12 @@ struct ipv4_cidr_instance {
     struct ipv4_ifaddr ifaddr;
 };
 
+enum {STRING_SUCCEEDED, STRING_ADDR, STRING_PREFIX};
+
+static struct NCD_string_request strings[] = {
+    {"succeeded"}, {"addr"}, {"prefix"}, {NULL}
+};
+
 typedef int (*parse_func) (NCDModuleInst *i, const char *str, NCDValMem *mem, NCDValRef *out);
 
 static int parse_number (NCDModuleInst *i, const char *str, NCDValMem *mem, NCDValRef *out)
@@ -172,11 +179,11 @@ static void func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "succeeded")) {
+    if (name == strings[STRING_SUCCEEDED].id) {
         const char *str = o->succeeded ? "true" : "false";
         *out = NCDVal_NewString(mem, str);
         if (NCDVal_IsInvalid(*out)) {
@@ -185,7 +192,7 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o
         return 1;
     }
     
-    if (o->succeeded && !strcmp(name, "")) {
+    if (o->succeeded && name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewCopy(mem, o->value);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewCopy failed");
@@ -236,11 +243,11 @@ fail0:
     NCDModuleInst_Backend_Dead(i);
 }
 
-static int ipv4_cidr_addr_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int ipv4_cidr_addr_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct ipv4_cidr_instance *o = vo;
     
-    if (!strcmp(name, "succeeded")) {
+    if (name == strings[STRING_SUCCEEDED].id) {
         const char *str = o->succeeded ? "true" : "false";
         *out = NCDVal_NewString(mem, str);
         if (NCDVal_IsInvalid(*out)) {
@@ -255,13 +262,13 @@ static int ipv4_cidr_addr_func_getvar (void *vo, const char *name, NCDValMem *me
     
     char str[IPADDR_PRINT_MAX];
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         ipaddr_print_ifaddr(o->ifaddr, str);
     }
-    else if (!strcmp(name, "addr")) {
+    else if (name == strings[STRING_ADDR].id) {
         ipaddr_print_addr(o->ifaddr.addr, str);
     }
-    else if (!strcmp(name, "prefix")) {
+    else if (name == strings[STRING_PREFIX].id) {
         sprintf(str, "%d", o->ifaddr.prefix);
     }
     else {
@@ -280,24 +287,24 @@ static struct NCDModule modules[] = {
         .type = "parse_number",
         .func_new2 = func_new_parse_number,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "parse_value",
         .func_new2 = func_new_parse_value,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "parse_ipv4_addr",
         .func_new2 = func_new_parse_ipv4_addr,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "parse_ipv4_cidr_addr",
         .func_new2 = ipv4_cidr_addr_func_new,
-        .func_getvar = ipv4_cidr_addr_func_getvar,
+        .func_getvar2 = ipv4_cidr_addr_func_getvar2,
         .alloc_size = sizeof(struct ipv4_cidr_instance)
     }, {
         .type = NULL
@@ -305,5 +312,6 @@ static struct NCDModule modules[] = {
 };
 
 const struct NCDModuleGroup ncdmodule_parse = {
-    .modules = modules
+    .modules = modules,
+    .strings = strings
 };

+ 4 - 4
ncd/modules/strcmp.c

@@ -39,6 +39,7 @@
 #include <string.h>
 
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_strcmp.h>
 
@@ -78,13 +79,12 @@ fail0:
     NCDModuleInst_Backend_Dead(i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         const char *v = o->result ? "true" : "false";
-        
         *out = NCDVal_NewString(mem, v);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
@@ -99,7 +99,7 @@ static struct NCDModule modules[] = {
     {
         .type = "strcmp",
         .func_new2 = func_new,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 14 - 7
ncd/modules/sys_evdev.c

@@ -77,6 +77,12 @@ struct instance {
 
 static void instance_free (struct instance *o, int is_error);
 
+enum {STRING_TYPE, STRING_VALUE, STRING_CODE_NUMERIC, STRING_CODE};
+
+static struct NCD_string_request strings[] = {
+    {"type"}, {"value"}, {"code_numeric"}, {"code"}, {NULL}
+};
+
 #define MAKE_LOOKUP_FUNC(_name_) \
 static const char * evdev_##_name_##_to_str (uint16_t type) \
 { \
@@ -213,12 +219,12 @@ static void func_die (void *vo)
     instance_free(o, 0);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     ASSERT(o->processing)
     
-    if (!strcmp(name, "type")) {
+    if (name == strings[STRING_TYPE].id) {
         *out = NCDVal_NewString(mem, evdev_type_to_str(o->event.type));
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
@@ -226,7 +232,7 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o
         return 1;
     }
     
-    if (!strcmp(name, "value")) {
+    if (name == strings[STRING_VALUE].id) {
         char str[50];
         snprintf(str, sizeof(str), "%"PRIi32, o->event.value);
         *out = NCDVal_NewString(mem, str);
@@ -236,7 +242,7 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o
         return 1;
     }
     
-    if (!strcmp(name, "code_numeric")) {
+    if (name == strings[STRING_CODE_NUMERIC].id) {
         char str[50];
         snprintf(str, sizeof(str), "%"PRIu16, o->event.code);
         *out = NCDVal_NewString(mem, str);
@@ -246,7 +252,7 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o
         return 1;
     }
     
-    if (!strcmp(name, "code")) {
+    if (name == strings[STRING_CODE].id) {
         const char *str = "unknown";
         
         #define MAKE_CASE(_evname_, _name_) \
@@ -330,7 +336,7 @@ static struct NCDModule modules[] = {
         .type = "sys.evdev",
         .func_new2 = func_new,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "sys.evdev::nextevent",
@@ -341,5 +347,6 @@ static struct NCDModule modules[] = {
 };
 
 const struct NCDModuleGroup ncdmodule_sys_evdev = {
-    .modules = modules
+    .modules = modules,
+    .strings = strings
 };

+ 4 - 3
ncd/modules/to_string.c

@@ -39,6 +39,7 @@
 
 #include <ncd/NCDModule.h>
 #include <ncd/NCDValGenerator.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_to_string.h>
 
@@ -86,11 +87,11 @@ static void func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewString(mem, o->str);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
@@ -106,7 +107,7 @@ static struct NCDModule modules[] = {
         .type = "to_string",
         .func_new2 = func_new,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 5 - 6
ncd/modules/try.c

@@ -83,10 +83,10 @@ static int process_caller_object_func_getobj (struct instance *o, NCD_string_id_
 static void start_terminating (struct instance *o);
 static void instance_free (struct instance *o);
 
-enum {STRING_CALLER, STRING_TRY, STRING_TRY_TRY};
+enum {STRING_CALLER, STRING_TRY, STRING_TRY_TRY, STRING_SUCCEEDED};
 
 static struct NCD_string_request strings[] = {
-    {"_caller"}, {"_try"}, {"try.try"}, {NULL}
+    {"_caller"}, {"_try"}, {"try.try"}, {"succeeded"}, {NULL}
 };
 
 static void process_handler_event (struct instance *o, int event)
@@ -225,15 +225,14 @@ static void func_die (void *vo)
     }
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     ASSERT(o->state == STATE_FINISHED)
     ASSERT(!o->dying)
     
-    if (!strcmp(name, "succeeded")) {
+    if (name == strings[STRING_SUCCEEDED].id) {
         const char *str = (o->succeeded ? "true" : "false");
-        
         *out = NCDVal_NewString(mem, str);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
@@ -286,7 +285,7 @@ static struct NCDModule modules[] = {
         .type = "try",
         .func_new2 = func_new,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "try.try::assert",

+ 28 - 19
ncd/modules/value.c

@@ -148,6 +148,7 @@
 #include <structure/IndexedList.h>
 #include <structure/SAvl.h>
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_value.h>
 
@@ -230,6 +231,12 @@ static void valref_free (struct valref *r);
 static struct value * valref_val (struct valref *r);
 static void valref_break (struct valref *r);
 
+enum {STRING_EXISTS, STRING_TYPE, STRING_LENGTH, STRING_KEYS};
+
+static struct NCD_string_request strings[] = {
+    {"exists"}, {"type"}, {"length"}, {"keys"}, {NULL}
+};
+
 #include "value_maptree.h"
 #include <structure/SAvl_impl.h>
 
@@ -923,12 +930,12 @@ static void func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     struct value *v = valref_val(&o->ref);
     
-    if (!strcmp(name, "exists")) {
+    if (name == strings[STRING_EXISTS].id) {
         const char *str = v ? "true" : "false";
         *out = NCDVal_NewString(mem, str);
         if (NCDVal_IsInvalid(*out)) {
@@ -937,7 +944,8 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o
         return 1;
     }
     
-    if (strcmp(name, "type") && strcmp(name, "length") && strcmp(name, "keys") && strcmp(name, "")) {
+    if (name != strings[STRING_TYPE].id && name != strings[STRING_LENGTH].id &&
+        name != strings[STRING_KEYS].id && name != NCD_STRING_EMPTY) {
         return 0;
     }
     
@@ -946,13 +954,13 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o
         return 0;
     }
     
-    if (!strcmp(name, "type")) {
+    if (name == strings[STRING_TYPE].id) {
         *out = NCDVal_NewString(mem, get_type_str(v->type));
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
         }
     }
-    else if (!strcmp(name, "length")) {
+    else if (name == strings[STRING_LENGTH].id) {
         size_t len;
         switch (v->type) {
             case NCDVAL_LIST:
@@ -976,7 +984,7 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
         }
     }
-    else if (!strcmp(name, "keys")) {
+    else if (name == strings[STRING_KEYS].id) {
         if (v->type != NCDVAL_MAP) {
             ModuleLog(o->i, BLOG_ERROR, "value is not a map (reading keys variable)");
             return 0;
@@ -1000,7 +1008,7 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o
             NCDVal_ListAppend(*out, key);
         }
     }
-    else if (!strcmp(name, "")) {
+    else if (name == NCD_STRING_EMPTY) {
         if (!value_to_value(o->i, v, mem, out)) {
             return 0;
         }
@@ -1536,70 +1544,70 @@ static struct NCDModule modules[] = {
         .type = "value",
         .func_new2 = func_new_value,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "value::get",
         .base_type = "value",
         .func_new2 = func_new_get,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "value::try_get",
         .base_type = "value",
         .func_new2 = func_new_try_get,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "value::getpath",
         .base_type = "value",
         .func_new2 = func_new_getpath,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "value::insert",
         .base_type = "value",
         .func_new2 = func_new_insert,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "value::replace",
         .base_type = "value",
         .func_new2 = func_new_replace,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "value::replace_this",
         .base_type = "value",
         .func_new2 = func_new_replace_this,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "value::insert_undo",
         .base_type = "value",
         .func_new2 = func_new_insert_undo,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "value::replace_undo",
         .base_type = "value",
         .func_new2 = func_new_replace_undo,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "value::replace_this_undo",
         .base_type = "value",
         .func_new2 = func_new_replace_this_undo,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "value::remove",
@@ -1615,7 +1623,7 @@ static struct NCDModule modules[] = {
         .base_type = "value",
         .func_new2 = func_new_substr,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL
@@ -1623,5 +1631,6 @@ static struct NCDModule modules[] = {
 };
 
 const struct NCDModuleGroup ncdmodule_value = {
-    .modules = modules
+    .modules = modules,
+    .strings = strings
 };

+ 9 - 8
ncd/modules/valuemetic.c

@@ -58,6 +58,7 @@
 #include <string.h>
 
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_valuemetic.h>
 
@@ -129,11 +130,11 @@ static void func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         const char *str = o->result ? "true" : "false";
         
         *out = NCDVal_NewString(mem, str);
@@ -181,37 +182,37 @@ static struct NCDModule modules[] = {
         .type = "val_lesser",
         .func_new2 = func_new_lesser,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "val_greater",
         .func_new2 = func_new_greater,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "val_lesser_equal",
         .func_new2 = func_new_lesser_equal,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "val_greater_equal",
         .func_new2 = func_new_greater_equal,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "val_equal",
         .func_new2 = func_new_equal,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "val_different",
         .func_new2 = func_new_different,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = NULL

+ 4 - 3
ncd/modules/var.c

@@ -41,6 +41,7 @@
 #include <string.h>
 
 #include <ncd/NCDModule.h>
+#include <ncd/static_strings.h>
 
 #include <generated/blog_channel_ncd_var.h>
 
@@ -95,11 +96,11 @@ static void func_die (void *vo)
     NCDModuleInst_Backend_Dead(o->i);
 }
 
-static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out)
+static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out)
 {
     struct instance *o = vo;
     
-    if (!strcmp(name, "")) {
+    if (name == NCD_STRING_EMPTY) {
         *out = NCDVal_NewCopy(mem, o->value);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewCopy failed");
@@ -154,7 +155,7 @@ static struct NCDModule modules[] = {
         .type = "var",
         .func_new2 = func_new,
         .func_die = func_die,
-        .func_getvar = func_getvar,
+        .func_getvar2 = func_getvar2,
         .alloc_size = sizeof(struct instance)
     }, {
         .type = "var::set",