diff options
Diffstat (limited to 'storage/connect/jsonudf.cpp')
-rw-r--r-- | storage/connect/jsonudf.cpp | 372 |
1 files changed, 136 insertions, 236 deletions
diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index 9ea391edae9..4e00703d9ef 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -1455,7 +1455,7 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n, 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); @@ -1496,7 +1496,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]; @@ -2253,7 +2253,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) { @@ -2358,7 +2359,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); @@ -2921,70 +2922,53 @@ 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; -#if defined(USE_TRY) try { -#else // !USE_TRY - // 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 + if (!g->Xchk) { + if (CheckMemory(g, initid, args, 1, true)) { + PUSH_WARNING("CheckMemory error"); + goto err; + } else + jvp = MakeValue(g, args, 0); - if (setjmp(g->jumper[++g->jump_level])) { - PUSH_WARNING(g->Message); - str = NULL; - goto err; - } // endif rc -#endif // !USE_TRY + 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 - - } else - jsp = (PJSON)g->Xchk; + path = MakePSZ(g, args, 1); + jsx = new(g) JSNX(g, jsp, TYPE_STRING, initid->max_length); - 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; -#if defined(USE_TRY) - } catch (int n) { + } catch (int n) { if (trace) htrc("Exception %d: %s\n", n, g->Message); PUSH_WARNING(g->Message); @@ -2996,12 +2980,6 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, } // end catch err: -#else // !USE_TRY - err: - g->jump_level--; -#endif // !USE_TRY - - fin: if (!str) { *is_null = 1; *res_length = 0; @@ -3292,64 +3270,45 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, } else if (initid->const_item) g->N = 1; -#if defined(USE_TRY) try { -#else // !USE_TRY - // 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 + 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 (setjmp(g->jumper[++g->jump_level])) { - PUSH_WARNING(g->Message); - *error = 1; - path = NULL; - goto err; - } // endif rc -#endif // !USE_TRY + 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(); - - if (g->Mrr) { // First argument is a constant - g->Xchk = jsp; - JsonMemSave(g); - } // endif Mrr - - } else - jsp = (PJSON)g->Xchk; + jsp = (PJSON)g->Xchk; - // The item to locate - jvp2 = MakeValue(g, args, 1); + // 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; -#if defined(USE_TRY) - } catch (int n) { + } catch (int n) { if (trace) htrc("Exception %d: %s\n", n, g->Message); PUSH_WARNING(g->Message); @@ -3363,11 +3322,6 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, } // end catch err: -#else // !USE_TRY - err: - g->jump_level--; -#endif // !USE_TRY - if (!path) { *res_length = 0; *is_null = 1; @@ -3439,65 +3393,46 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, } else if (initid->const_item) g->N = 1; -#if defined(USE_TRY) try { -#else // !USE_TRY - // 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 + 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 (setjmp(g->jumper[++g->jump_level])) { - PUSH_WARNING(g->Message); - *error = 1; - path = NULL; - goto err; - } // endif rc -#endif // !USE_TRY + 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(); - - if (g->Mrr) { // First argument is a constant - g->Xchk = jsp; - JsonMemSave(g); - } // endif Mrr - - } else - jsp = (PJSON)g->Xchk; + jsp = (PJSON)g->Xchk; - // The item to locate - jvp2 = MakeValue(g, args, 1); + // 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; -#if defined(USE_TRY) - } catch (int n) { + } catch (int n) { if (trace) htrc("Exception %d: %s\n", n, g->Message); PUSH_WARNING(g->Message); @@ -3511,11 +3446,6 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, } // end catch err: -#else // !USE_TRY - err: - g->jump_level--; -#endif // !USE_TRY - if (!path) { *res_length = 0; *is_null = 1; @@ -3722,87 +3652,61 @@ char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, goto fin; } // endelse -#if defined(USE_TRY) try { -#else // !USE_TRY - // 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 + 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 (setjmp(g->jumper[++g->jump_level])) { - PUSH_WARNING(g->Message); - str = NULL; - goto err; - } // endif rc -#endif // !USE_TRY + 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"); -#if defined(USE_TRY) - throw 1; -#else // !USE_TRY - goto err; -#endif // !USE_TRY - } else - jvp = MakeValue(g, args, 0); + } else + jsp = jvp->GetJson(); - if ((p = jvp->GetString())) { - if (!(jsp = ParseJson(g, p, strlen(p)))) { -#if defined(USE_TRY) - throw 2; -#else // !USE_TRY - PUSH_WARNING(g->Message); - goto err; -#endif // !USE_TRY - } // endif jsp + if (g->Mrr) { // First argument is a constant + g->Xchk = jsp; + JsonMemSave(g); + } // endif Mrr } else - jsp = jvp->GetJson(); - - if (g->Mrr) { // First argument is a constant - g->Xchk = jsp; - JsonMemSave(g); - } // endif Mrr + jsp = (PJSON)g->Xchk; - } else - jsp = (PJSON)g->Xchk; + jsx = new(g)JSNX(g, jsp, TYPE_STRING, initid->max_length, 0, true); - 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); - 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; -#if defined(USE_TRY) - } catch (int n) { + } catch (int n) { if (trace) htrc("Exception %d: %s\n", n, g->Message); PUSH_WARNING(g->Message); @@ -3812,10 +3716,6 @@ char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, PUSH_WARNING(g->Message); str = NULL; } // end catch -#else // !USE_TRY -err: - g->jump_level--; -#endif // !USE_TRY fin: if (!str) { @@ -4642,7 +4542,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(); @@ -4722,7 +4622,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(); |