From 3e36eb230b65d53acc8e02b00a024e72ed249425 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Tue, 23 May 2017 19:35:50 +0200 Subject: Fix gcc compiler warnings reported by Sergei modified: storage/connect/array.cpp modified: storage/connect/array.h modified: storage/connect/blkfil.cpp modified: storage/connect/blkfil.h modified: storage/connect/block.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/csort.h modified: storage/connect/filamvct.cpp modified: storage/connect/filter.cpp modified: storage/connect/filter.h modified: storage/connect/global.h modified: storage/connect/json.h modified: storage/connect/plgdbsem.h modified: storage/connect/plgdbutl.cpp modified: storage/connect/tabcol.cpp modified: storage/connect/tabcol.h modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabjson.cpp modified: storage/connect/table.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/tabodbc.h modified: storage/connect/tabsys.h modified: storage/connect/tabxml.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.cpp modified: storage/connect/xobject.h modified: storage/connect/xtable.h Set values as nullable when retrieving catalog info modified: storage/connect/jdbconn.cpp modified: storage/connect/mysql-test/connect/r/odbc_oracle.result modified: storage/connect/odbconn.cpp Change format of Jpath modified: storage/connect/json.cpp modified: storage/connect/jsonudf.cpp modified: storage/connect/mysql-test/connect/r/json.result modified: storage/connect/mysql-test/connect/r/json_udf.result modified: storage/connect/mysql-test/connect/r/json_udf_bin.result modified: storage/connect/mysql-test/connect/r/zip.result modified: storage/connect/mysql-test/connect/t/json.test modified: storage/connect/mysql-test/connect/t/json_udf.test modified: storage/connect/mysql-test/connect/t/json_udf_bin.test modified: storage/connect/mysql-test/connect/t/zip.test modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/tabmgo.cpp Change null representation from ??? to modified: storage/connect/json.cpp Change the name of UDF that are equal to a native JSON function name modified: storage/connect/jsonudf.cpp modified: storage/connect/jsonudf.h modified: storage/connect/mysql-test/connect/t/json_udf.inc modified: storage/connect/mysql-test/connect/t/json_udf2.inc Fix bug in making JSON project info modified: storage/connect/mongofam.cpp Fix COMPUTE when one argument is null modified: storage/connect/value.cpp Value is null only when nullable modified: storage/connect/value.h --- storage/connect/jsonudf.cpp | 521 ++++++++++++++++++++++---------------------- 1 file changed, 263 insertions(+), 258 deletions(-) (limited to 'storage/connect/jsonudf.cpp') diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index f07a1ac818f..124e5bdc6ad 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -27,9 +27,11 @@ #endif #define M 7 -uint GetJsonGrpSize(void); -static int IsJson(UDF_ARGS *args, uint i); -static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i); +bool IsNum(PSZ s); +char *NextChr(PSZ s, char sep); +uint GetJsonGrpSize(void); +static int IsJson(UDF_ARGS *args, uint i); +static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i); static char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error); static char *bin_handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, @@ -111,10 +113,9 @@ my_bool JSNX::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) PJNODE jnp = &Nodes[i]; if (*p) { - if (p[--n] == ']') { - p[n--] = 0; - p++; - } else { + if (p[n - 1] == ']') { + p[--n] = 0; + } else if (!IsNum(p)) { // Wrong array specification sprintf(g->Message, "Invalid array specification %s", p); return true; @@ -124,8 +125,7 @@ my_bool JSNX::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) b = true; // To check whether a numeric Rank was specified - for (int k = 0; dg && p[k]; k++) - dg = isdigit(p[k]) > 0; + dg = IsNum(p); if (!n) { // Default specifications @@ -160,13 +160,12 @@ my_bool JSNX::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) // Set the Op value; switch (*p) { case '+': jnp->Op = OP_ADD; break; - case '*': jnp->Op = OP_MULT; break; + case 'x': jnp->Op = OP_MULT; break; case '>': jnp->Op = OP_MAX; break; case '<': jnp->Op = OP_MIN; break; case '!': jnp->Op = OP_SEP; break; // Average case '#': jnp->Op = OP_NUM; break; - case 'x': - case 'X': // Expand this array + case '*': // Expand this array strcpy(g->Message, "Expand not supported by this function"); return true; default: @@ -232,9 +231,9 @@ my_bool JSNX::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) /*********************************************************************************/ my_bool JSNX::ParseJpath(PGLOBAL g) { - char *p, *p2 = NULL, *pbuf = NULL; + char *p, *p1 = NULL, *p2 = NULL, *pbuf = NULL; int i; - my_bool mul = false; + my_bool a, mul = false; if (Parsed) return false; // Already done @@ -245,8 +244,12 @@ my_bool JSNX::ParseJpath(PGLOBAL g) if (!(pbuf = PlgDBDup(g, Jpath))) return true; - // The Jpath must be analyzed - for (i = 0, p = pbuf; (p = strchr(p, ':')); i++, p++) + if (*pbuf == '$') pbuf++; + if (*pbuf == '.') pbuf++; + if (*pbuf == '[') p1 = pbuf++; + + // Estimate the required number of nodes + for (i = 0, p = pbuf; (p = NextChr(p, '.')); i++, p++) Nod++; // One path node found if (!(Nodes = (PJNODE)PlgDBSubAlloc(g, NULL, (++Nod) * sizeof(JNODE)))) @@ -255,12 +258,28 @@ my_bool JSNX::ParseJpath(PGLOBAL g) memset(Nodes, 0, (Nod)* sizeof(JNODE)); // Analyze the Jpath for this column - for (i = 0, p = pbuf; i < Nod; i++, p = (p2 ? p2 + 1 : p + strlen(p))) { - if ((p2 = strchr(p, ':'))) - *p2 = 0; + for (i = 0, p = pbuf; p && i < Nod; i++, p = (p2 ? p2 : NULL)) { + a = (p1 != NULL); + p1 = strchr(p, '['); + p2 = strchr(p, '.'); + + if (!p2) + p2 = p1; + else if (p1) { + if (p1 < p2) + p2 = p1; + else if (p1 == p2 + 1) + *p2++ = 0; // Old syntax .[ + else + p1 = NULL; + + } // endif p1 + + if (p2) + *p2++ = 0; // Jpath must be explicit - if (*p == 0 || *p == '[') { + if (a || *p == 0 || *p == '[' || IsNum(p)) { // Analyse intermediate array processing if (SetArrayOptions(g, p, i, Nodes[i-1].Key)) return true; @@ -279,6 +298,7 @@ my_bool JSNX::ParseJpath(PGLOBAL g) } // endfor i, p + Nod = i; MulVal = AllocateValue(g, Value); Parsed = true; return false; @@ -711,6 +731,7 @@ PSZ JSNX::Locate(PGLOBAL g, PJSON jsp, PJVAL jvp, int k) // Write to the path string Jp = new(g) JOUTSTR(g); + Jp->WriteChr('$'); Jvalp = jvp; K = k; @@ -769,7 +790,12 @@ my_bool JSNX::LocateArray(PJAR jarp) /*********************************************************************************/ my_bool JSNX::LocateObject(PJOB jobp) { - size_t m = Jp->N; + size_t m; + + if (Jp->WriteChr('.')) + return true; + + m = Jp->N; for (PJPR pair = jobp->First; pair && !Found; pair = pair->Next) { Jp->N = m; @@ -790,19 +816,12 @@ my_bool JSNX::LocateObject(PJOB jobp) /*********************************************************************************/ my_bool JSNX::LocateValue(PJVAL jvp) { - if (CompareTree(Jvalp, jvp)) { + if (CompareTree(Jvalp, jvp)) Found = (--K == 0); - } else if (jvp->GetArray()) { - if (Jp->WriteChr(':')) - return true; - + else if (jvp->GetArray()) return LocateArray(jvp->GetArray()); - } else if (jvp->GetObject()) { - if (Jp->WriteChr(':')) - return true; - + else if (jvp->GetObject()) return LocateObject(jvp->GetObject()); - } // endif's return false; } // end of LocateValue @@ -848,6 +867,7 @@ PSZ JSNX::LocateAll(PGLOBAL g, PJSON jsp, PJVAL jvp, int mx) if (!g->Message[0]) strcpy(g->Message, "Invalid json tree"); + return NULL; } else { if (Jp->N > 1) Jp->N--; @@ -858,7 +878,6 @@ PSZ JSNX::LocateAll(PGLOBAL g, PJSON jsp, PJVAL jvp, int mx) return Jp->Strp; } // endif's - return NULL; } // end of LocateAll /*********************************************************************************/ @@ -964,26 +983,26 @@ my_bool JSNX::CompareTree(PJSON jp1, PJSON jp2) /*********************************************************************************/ my_bool JSNX::AddPath(void) { - char s[16]; - my_bool b = false; + char s[16]; - if (Jp->WriteChr('"')) + if (Jp->WriteStr("\"$")) return true; for (int i = 0; i <= I; i++) { - if (b) { - if (Jp->WriteChr(':')) return true; - } else - b = true; - if (Jpnp[i].Type == TYPE_JAR) { sprintf(s, "[%d]", Jpnp[i].N + B); if (Jp->WriteStr(s)) return true; - } else if (Jp->WriteStr(Jpnp[i].Key)) - return true; + } else { + if (Jp->WriteChr('.')) + return true; + + if (Jp->WriteStr(Jpnp[i].Key)) + return true; + + } // endif's } // endfor i @@ -1104,7 +1123,7 @@ static my_bool JsonInit(UDF_INIT *initid, UDF_ARGS *args, } // endif g g->Mrr = (args->arg_count && args->args[0]) ? 1 : 0; - g->ActivityStart = (PACTIVITY)more; + g->More = more; initid->maybe_null = mbn; initid->max_length = reslen; initid->ptr = (char*)g; @@ -1379,6 +1398,7 @@ static my_bool CalcLen(UDF_ARGS *args, my_bool obj, memlen += (k + sizeof(JOBJECT) + sizeof(JPAIR)); } else memlen += sizeof(JARRAY); + switch (args->arg_type[i]) { case STRING_RESULT: if (n == 2 && args->args[i]) { @@ -1448,13 +1468,13 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n, } // endif b - ml += (unsigned long)g->ActivityStart; // more + ml += g->More; if (ml > g->Sarea_Size) { free(g->Sarea); if (!(g->Sarea = PlugAllocMem(g, ml))) { - char errmsg[256]; + char errmsg[MAX_STR]; sprintf(errmsg, MSG(WORK_AREA), g->Message); strcpy(g->Message, errmsg); @@ -1495,7 +1515,7 @@ static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i) /*********************************************************************************/ /* Make a valid key from the passed argument. */ /*********************************************************************************/ -static PSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) +static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) { if (args->arg_count > (unsigned)i) { int j = 0, n = args->attribute_lengths[i]; @@ -1756,16 +1776,16 @@ void jsonvalue_deinit(UDF_INIT* initid) /*********************************************************************************/ /* Make a Json array containing all the parameters. */ /*********************************************************************************/ -my_bool json_array_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +my_bool json_make_array_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { unsigned long reslen, memlen; CalcLen(args, false, reslen, memlen); return JsonInit(initid, args, message, false, reslen, memlen); -} // end of json_array_init +} // end of json_make_array_init -char *json_array(UDF_INIT *initid, UDF_ARGS *args, char *result, - unsigned long *res_length, char *, char *) +char *json_make_array(UDF_INIT *initid, UDF_ARGS *args, char *result, + unsigned long *res_length, char *, char *) { char *str; PGLOBAL g = (PGLOBAL)initid->ptr; @@ -1792,12 +1812,12 @@ char *json_array(UDF_INIT *initid, UDF_ARGS *args, char *result, *res_length = strlen(str); return str; -} // end of json_array +} // end of json_make_array void json_array_deinit(UDF_INIT* initid) { JsonFreeMem((PGLOBAL)initid->ptr); -} // end of json_array_deinit +} // end of json_make_array_deinit /*********************************************************************************/ /* Add one or several values to a Json array. */ @@ -2080,16 +2100,16 @@ void json_array_delete_deinit(UDF_INIT* initid) /*********************************************************************************/ /* Make a Json Object containing all the parameters. */ /*********************************************************************************/ -my_bool json_object_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +my_bool json_make_object_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { unsigned long reslen, memlen; CalcLen(args, true, reslen, memlen); return JsonInit(initid, args, message, false, reslen, memlen); -} // end of json_object_init +} // end of json_make_object_init -char *json_object(UDF_INIT *initid, UDF_ARGS *args, char *result, - unsigned long *res_length, char *, char *) +char *json_make_object(UDF_INIT *initid, UDF_ARGS *args, char *result, + unsigned long *res_length, char *, char *) { char *str = NULL; PGLOBAL g = (PGLOBAL)initid->ptr; @@ -2114,12 +2134,12 @@ char *json_object(UDF_INIT *initid, UDF_ARGS *args, char *result, *res_length = strlen(str); return str; -} // end of json_object +} // end of json_make_object -void json_object_deinit(UDF_INIT* initid) +void json_make_object_deinit(UDF_INIT* initid) { JsonFreeMem((PGLOBAL)initid->ptr); -} // end of json_object_deinit +} // end of json_make_object_deinit /*********************************************************************************/ /* Make a Json Object containing all not null parameters. */ @@ -2252,7 +2272,8 @@ my_bool json_object_add_init(UDF_INIT *initid, UDF_ARGS *args, char *message) char *json_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error) { - char *key, *str = NULL; + PCSZ key; + char *str = NULL; PGLOBAL g = (PGLOBAL)initid->ptr; if (g->Xchk) { @@ -2357,7 +2378,7 @@ char *json_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, } // endif Xchk if (!CheckMemory(g, initid, args, 1, false, true, true)) { - char *key; + PCSZ key; PJOB jobp; PJSON jsp, top; PJVAL jvp = MakeValue(g, args, 0, &top); @@ -2913,7 +2934,6 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *) { char *p, *path, *str = NULL; - int rc; PJSON jsp; PJSNX jsx; PJVAL jvp; @@ -2921,68 +2941,64 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, if (g->N) { str = (char*)g->Activityp; - goto fin; + goto err; } else if (initid->const_item) g->N = 1; - // Save stack and allocation environment and prepare error return - if (g->jump_level == MAX_JUMP) { - PUSH_WARNING(MSG(TOO_MANY_JUMPS)); - *is_null = 1; - return NULL; - } // endif jump_level + try { + if (!g->Xchk) { + if (CheckMemory(g, initid, args, 1, true)) { + PUSH_WARNING("CheckMemory error"); + goto err; + } else + jvp = MakeValue(g, args, 0); - if ((rc= setjmp(g->jumper[++g->jump_level])) != 0) { - PUSH_WARNING(g->Message); - str = NULL; - goto err; - } // endif rc + if ((p = jvp->GetString())) { + if (!(jsp = ParseJson(g, p, strlen(p)))) { + PUSH_WARNING(g->Message); + goto err; + } // endif jsp - if (!g->Xchk) { - if (CheckMemory(g, initid, args, 1, true)) { - PUSH_WARNING("CheckMemory error"); - goto err; - } else - jvp = MakeValue(g, args, 0); + } else + jsp = jvp->GetJson(); - if ((p = jvp->GetString())) { - if (!(jsp = ParseJson(g, p, strlen(p)))) { - PUSH_WARNING(g->Message); - goto err; - } // endif jsp + if (g->Mrr) { // First argument is a constant + g->Xchk = jsp; + JsonMemSave(g); + } // endif Mrr } else - jsp = jvp->GetJson(); + jsp = (PJSON)g->Xchk; - if (g->Mrr) { // First argument is a constant - g->Xchk = jsp; - JsonMemSave(g); - } // endif Mrr + path = MakePSZ(g, args, 1); + jsx = new(g) JSNX(g, jsp, TYPE_STRING, initid->max_length); - } else - jsp = (PJSON)g->Xchk; - - path = MakePSZ(g, args, 1); - jsx = new(g) JSNX(g, jsp, TYPE_STRING, initid->max_length); + if (jsx->SetJpath(g, path)) { + PUSH_WARNING(g->Message); + goto err; + } // endif SetJpath - if (jsx->SetJpath(g, path)) { - PUSH_WARNING(g->Message); - goto err; - } // endif SetJpath + jsx->ReadValue(g); - jsx->ReadValue(g); + if (!jsx->GetValue()->IsNull()) + str = jsx->GetValue()->GetCharValue(); - if (!jsx->GetValue()->IsNull()) - str = jsx->GetValue()->GetCharValue(); + if (initid->const_item) + // Keep result of constant function + g->Activityp = (PACTIVITY)str; - if (initid->const_item) - // Keep result of constant function - g->Activityp = (PACTIVITY)str; + } catch (int n) { + if (trace) + htrc("Exception %d: %s\n", n, g->Message); + PUSH_WARNING(g->Message); + str = NULL; + } catch (const char *msg) { + strcpy(g->Message, msg); + PUSH_WARNING(g->Message); + str = NULL; + } // end catch err: - g->jump_level--; - - fin: if (!str) { *is_null = 1; *res_length = 0; @@ -3253,7 +3269,7 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error) { char *p, *path = NULL; - int k, rc; + int k; PJVAL jvp, jvp2; PJSON jsp; PJSNX jsx; @@ -3273,61 +3289,58 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, } else if (initid->const_item) g->N = 1; - // Save stack and allocation environment and prepare error return - if (g->jump_level == MAX_JUMP) { - PUSH_WARNING(MSG(TOO_MANY_JUMPS)); - *error = 1; - *is_null = 1; - return NULL; - } // endif jump_level + try { + if (!g->Xchk) { + if (CheckMemory(g, initid, args, 1, !g->Xchk)) { + PUSH_WARNING("CheckMemory error"); + *error = 1; + goto err; + } else + jvp = MakeValue(g, args, 0); - if ((rc= setjmp(g->jumper[++g->jump_level])) != 0) { - PUSH_WARNING(g->Message); - *error = 1; - path = NULL; - goto err; - } // endif rc + if ((p = jvp->GetString())) { + if (!(jsp = ParseJson(g, p, strlen(p)))) { + PUSH_WARNING(g->Message); + goto err; + } // endif jsp - if (!g->Xchk) { - if (CheckMemory(g, initid, args, 1, !g->Xchk)) { - PUSH_WARNING("CheckMemory error"); - *error = 1; - goto err; - } else - jvp = MakeValue(g, args, 0); + } else + jsp = jvp->GetJson(); - if ((p = jvp->GetString())) { - if (!(jsp = ParseJson(g, p, strlen(p)))) { - PUSH_WARNING(g->Message); - goto err; - } // endif jsp + if (g->Mrr) { // First argument is a constant + g->Xchk = jsp; + JsonMemSave(g); + } // endif Mrr } else - jsp = jvp->GetJson(); + jsp = (PJSON)g->Xchk; - if (g->Mrr) { // First argument is a constant - g->Xchk = jsp; - JsonMemSave(g); - } // endif Mrr + // The item to locate + jvp2 = MakeValue(g, args, 1); - } else - jsp = (PJSON)g->Xchk; - - // The item to locate - jvp2 = MakeValue(g, args, 1); + k = (args->arg_count > 2) ? (int)*(long long*)args->args[2] : 1; - k = (args->arg_count > 2) ? (int)*(long long*)args->args[2] : 1; + jsx = new(g) JSNX(g, jsp, TYPE_STRING); + path = jsx->Locate(g, jsp, jvp2, k); - jsx = new(g) JSNX(g, jsp, TYPE_STRING); - path = jsx->Locate(g, jsp, jvp2, k); + if (initid->const_item) + // Keep result of constant function + g->Activityp = (PACTIVITY)path; - if (initid->const_item) - // Keep result of constant function - g->Activityp = (PACTIVITY)path; + } catch (int n) { + if (trace) + htrc("Exception %d: %s\n", n, g->Message); + PUSH_WARNING(g->Message); + *error = 1; + path = NULL; + } catch (const char *msg) { + strcpy(g->Message, msg); + PUSH_WARNING(g->Message); + *error = 1; + path = NULL; + } // end catch err: - g->jump_level--; - if (!path) { *res_length = 0; *is_null = 1; @@ -3378,7 +3391,7 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error) { char *p, *path = NULL; - int rc, mx = 10; + int mx = 10; PJVAL jvp, jvp2; PJSON jsp; PJSNX jsx; @@ -3399,62 +3412,59 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, } else if (initid->const_item) g->N = 1; - // Save stack and allocation environment and prepare error return - if (g->jump_level == MAX_JUMP) { - PUSH_WARNING(MSG(TOO_MANY_JUMPS)); - *error = 1; - *is_null = 1; - return NULL; - } // endif jump_level + try { + if (!g->Xchk) { + if (CheckMemory(g, initid, args, 1, true)) { + PUSH_WARNING("CheckMemory error"); + *error = 1; + goto err; + } else + jvp = MakeValue(g, args, 0); - if ((rc= setjmp(g->jumper[++g->jump_level])) != 0) { - PUSH_WARNING(g->Message); - *error = 1; - path = NULL; - goto err; - } // endif rc + if ((p = jvp->GetString())) { + if (!(jsp = ParseJson(g, p, strlen(p)))) { + PUSH_WARNING(g->Message); + goto err; + } // endif jsp - if (!g->Xchk) { - if (CheckMemory(g, initid, args, 1, true)) { - PUSH_WARNING("CheckMemory error"); - *error = 1; - goto err; - } else - jvp = MakeValue(g, args, 0); + } else + jsp = jvp->GetJson(); - if ((p = jvp->GetString())) { - if (!(jsp = ParseJson(g, p, strlen(p)))) { - PUSH_WARNING(g->Message); - goto err; - } // endif jsp + if (g->Mrr) { // First argument is a constant + g->Xchk = jsp; + JsonMemSave(g); + } // endif Mrr } else - jsp = jvp->GetJson(); + jsp = (PJSON)g->Xchk; - if (g->Mrr) { // First argument is a constant - g->Xchk = jsp; - JsonMemSave(g); - } // endif Mrr + // The item to locate + jvp2 = MakeValue(g, args, 1); - } else - jsp = (PJSON)g->Xchk; - - // The item to locate - jvp2 = MakeValue(g, args, 1); + if (args->arg_count > 2) + mx = (int)*(long long*)args->args[2]; - if (args->arg_count > 2) - mx = (int)*(long long*)args->args[2]; + jsx = new(g) JSNX(g, jsp, TYPE_STRING); + path = jsx->LocateAll(g, jsp, jvp2, mx); - jsx = new(g) JSNX(g, jsp, TYPE_STRING); - path = jsx->LocateAll(g, jsp, jvp2, mx); + if (initid->const_item) + // Keep result of constant function + g->Activityp = (PACTIVITY)path; - if (initid->const_item) - // Keep result of constant function - g->Activityp = (PACTIVITY)path; + } catch (int n) { + if (trace) + htrc("Exception %d: %s\n", n, g->Message); + PUSH_WARNING(g->Message); + *error = 1; + path = NULL; + } catch (const char *msg) { + strcpy(g->Message, msg); + PUSH_WARNING(g->Message); + *error = 1; + path = NULL; + } // end catch err: - g->jump_level--; - if (!path) { *res_length = 0; *is_null = 1; @@ -3632,11 +3642,11 @@ void jsoncontains_path_deinit(UDF_INIT* initid) /*********************************************************************************/ /* This function is used by the json_set/insert/update_item functions. */ /*********************************************************************************/ -static char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, +char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error) { char *p, *path, *str = NULL; - int w, rc; + int w; my_bool b = true; PJSON jsp; PJSNX jsx; @@ -3658,78 +3668,73 @@ static char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, w = 2; else { PUSH_WARNING("Logical error, please contact CONNECT developer"); - goto err; + goto fin; } // endelse - // Save stack and allocation environment and prepare error return - if (g->jump_level == MAX_JUMP) { - PUSH_WARNING(MSG(TOO_MANY_JUMPS)); - *error = 1; - goto fin; - } // endif jump_level + try { + if (!g->Xchk) { + if (CheckMemory(g, initid, args, 1, true, false, true)) { + PUSH_WARNING("CheckMemory error"); + throw 1; + } else + jvp = MakeValue(g, args, 0); - if ((rc= setjmp(g->jumper[++g->jump_level])) != 0) { - PUSH_WARNING(g->Message); - str = NULL; - goto err; - } // endif rc + if ((p = jvp->GetString())) { + if (!(jsp = ParseJson(g, p, strlen(p)))) { + throw 2; + } // endif jsp - if (!g->Xchk) { - if (CheckMemory(g, initid, args, 1, true, false, true)) { - PUSH_WARNING("CheckMemory error"); - goto err; - } else - jvp = MakeValue(g, args, 0); + } else + jsp = jvp->GetJson(); - if ((p = jvp->GetString())) { - if (!(jsp = ParseJson(g, p, strlen(p)))) { - PUSH_WARNING(g->Message); - goto err; - } // endif jsp + if (g->Mrr) { // First argument is a constant + g->Xchk = jsp; + JsonMemSave(g); + } // endif Mrr } else - jsp = jvp->GetJson(); + jsp = (PJSON)g->Xchk; - if (g->Mrr) { // First argument is a constant - g->Xchk = jsp; - JsonMemSave(g); - } // endif Mrr + jsx = new(g)JSNX(g, jsp, TYPE_STRING, initid->max_length, 0, true); - } else - jsp = (PJSON)g->Xchk; + for (uint i = 1; i + 1 < args->arg_count; i += 2) { + jvp = MakeValue(gb, args, i); + path = MakePSZ(g, args, i + 1); - jsx = new(g)JSNX(g, jsp, TYPE_STRING, initid->max_length, 0, true); - - for (uint i = 1; i+1 < args->arg_count; i += 2) { - jvp = MakeValue(gb, args, i); - path = MakePSZ(g, args, i+1); - - if (jsx->SetJpath(g, path, false)) { - PUSH_WARNING(g->Message); - continue; - } // endif SetJpath + if (jsx->SetJpath(g, path, false)) { + PUSH_WARNING(g->Message); + continue; + } // endif SetJpath - if (w) { - jsx->ReadValue(g); - b = jsx->GetValue()->IsNull(); - b = (w == 1) ? b : !b; - } // endif w + if (w) { + jsx->ReadValue(g); + b = jsx->GetValue()->IsNull(); + b = (w == 1) ? b : !b; + } // endif w - if (b && jsx->WriteValue(gb, jvp)) - PUSH_WARNING(g->Message); + if (b && jsx->WriteValue(gb, jvp)) + PUSH_WARNING(g->Message); - } // endfor i + } // endfor i - // In case of error or file, return unchanged argument - if (!(str = MakeResult(g, args, jsp, INT_MAX32))) - str = MakePSZ(g, args, 0); + // In case of error or file, return unchanged argument + if (!(str = MakeResult(g, args, jsp, INT_MAX32))) + str = MakePSZ(g, args, 0); - if (g->N) - // Keep result of constant function - g->Activityp = (PACTIVITY)str; + if (g->N) + // Keep result of constant function + g->Activityp = (PACTIVITY)str; -err: - g->jump_level--; + } catch (int n) { + if (trace) + htrc("Exception %d: %s\n", n, g->Message); + PUSH_WARNING(g->Message); + str = NULL; + } catch (const char *msg) { + strcpy(g->Message, msg); + PUSH_WARNING(g->Message); + str = NULL; + } // end catch fin: if (!str) { @@ -4556,7 +4561,7 @@ char *jbin_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result, } // endif bsp if (!CheckMemory(g, initid, args, 2, false, true, true)) { - char *key; + PCSZ key; PJOB jobp; PJVAL jvp = MakeValue(g, args, 0, &top); PJSON jsp = jvp->GetJson(); @@ -4636,7 +4641,7 @@ char *jbin_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, } // endif bsp if (!CheckMemory(g, initid, args, 1, false, true, true)) { - char *key; + PCSZ key; PJOB jobp; PJVAL jvp = MakeValue(g, args, 0, &top); PJSON jsp = jvp->GetJson(); @@ -4905,7 +4910,7 @@ void jbin_item_merge_deinit(UDF_INIT* initid) /*********************************************************************************/ /* This function is used by the jbin_set/insert/update functions. */ /*********************************************************************************/ -static char *bin_handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, +char *bin_handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error) { char *p, *path; -- cgit v1.2.1