Changeset: 8097a49ff5af for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8097a49ff5af Modified Files: monetdb5/modules/atoms/json.c Branch: Jul2017 Log Message:
Removed some logically dead code; properly free error. diffs (truncated from 448 to 300 lines): diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c --- a/monetdb5/modules/atoms/json.c +++ b/monetdb5/modules/atoms/json.c @@ -28,12 +28,14 @@ break; \ } while (0) -#define hex(J) \ - do { \ - if ((*(J) >='0' && *(J) <='9') || \ - (*(J) >='a' && *(J) <='f') || \ - (*(J) >='A' && *(J) <='F')) \ - (J)++; \ +#define hex(J) \ + do { \ + if ((*(J) >='0' && *(J) <='9') || \ + (*(J) >='a' && *(J) <='f') || \ + (*(J) >='A' && *(J) <='F')) \ + (J)++; \ + else \ + throw(MAL, "json.parser", "illegal escape char"); \ } while (0) #define CHECK_JSON(jt) \ @@ -56,24 +58,22 @@ int TYPE_json; /* Internal constructors. */ static int jsonhint = 8; -static JSON *JSONparse(char *j, int silent); +static JSON *JSONparse(char *j); static JSON * -JSONnewtree(int size) +JSONnewtree(void) { JSON *js; - if (size == 0) - size = jsonhint; js = (JSON *) GDKzalloc(sizeof(JSON)); if (js == NULL) return NULL; - js->elm = (JSONterm *) GDKzalloc(sizeof(JSONterm) * size); + js->elm = (JSONterm *) GDKzalloc(sizeof(JSONterm) * jsonhint); if (js->elm == NULL) { GDKfree(js); return NULL; } - js->size = size; + js->size = jsonhint; return js; } @@ -103,6 +103,7 @@ JSONfree(JSON *c) { if (c == 0) return; + freeException(c->error); GDKfree(c->elm); GDKfree(c); } @@ -111,7 +112,7 @@ int JSONfromString(str src, int *len, json *j) { ssize_t slen = (ssize_t) strlen(src); - JSON *jt = JSONparse(src, FALSE); + JSON *jt = JSONparse(src); if (*j) GDKfree(*j); @@ -259,7 +260,7 @@ JSONdumpInternal(JSON *jt, int depth) str JSONdump(void *ret, json *val) { - JSON *jt = JSONparse(*val, FALSE); + JSON *jt = JSONparse(*val); CHECK_JSON(jt); (void) ret; @@ -288,7 +289,7 @@ JSONjson2str(str *ret, json *j) str JSONstr2json(json *ret, str *j) { - JSON *jt = JSONparse(*j, FALSE); + JSON *jt = JSONparse(*j); CHECK_JSON(jt); JSONfree(jt); @@ -300,12 +301,11 @@ JSONstr2json(json *ret, str *j) str JSONisvalid(bit *ret, json *j) { - JSON *jt = JSONparse(*j, FALSE); + JSON *jt = JSONparse(*j); if (jt == NULL) throw(MAL, "json.isvalid", MAL_MALLOC_FAIL); *ret = jt->error == MAL_SUCCEED; - GDKfree(jt->error); JSONfree(jt); return MAL_SUCCEED; } @@ -371,11 +371,13 @@ JSONappend(JSON *jt, int idx, int nxt) } /* - * The JSON filter operation takes a path expression which is purposely kept simple, - * It provides step (.), multistep (..) and indexed ([nr]) access to the JSON elements. - * A wildcard * can be used as placeholder for a step identifier. + * The JSON filter operation takes a path expression which is + * purposely kept simple, It provides step (.), multistep (..) and + * indexed ([nr]) access to the JSON elements. A wildcard * can be + * used as placeholder for a step identifier. * - * A path expression is always validated upfront and can only be applied to valid json strings. + * A path expression is always validated upfront and can only be + * applied to valid json strings. * Path samples: * .store.book * .store.book[0] @@ -641,7 +643,7 @@ JSONfilterInternal(json *ret, json *js, throw(MAL,"JSONfilterInternal",MAL_MALLOC_FAIL); return MAL_SUCCEED; } - jt = JSONparse(j, FALSE); + jt = JSONparse(j); CHECK_JSON(jt); memset(terms, 0, sizeof(terms)); msg = JSONcompile(*expr, terms); @@ -688,10 +690,10 @@ JSONfilterInternal(json *ret, json *js, static str -JSONstringParser(char *j, char **next, int silent) +JSONstringParser(char *j, char **next) { - if (*j == '"') - j++; + assert(*j == '"'); + j++; for (; *j; j++) { switch (*j) { case '\\': @@ -716,9 +718,6 @@ JSONstringParser(char *j, char **next, i break; default: *next = j; - if (silent) { - return MAL_SUCCEED; - } throw(MAL, "json.parser", "illegal escape char"); } break; @@ -729,13 +728,11 @@ JSONstringParser(char *j, char **next, i } } *next = j; - if (!silent) - throw(MAL, "json.parser", "Nonterminated string"); - return MAL_SUCCEED; + throw(MAL, "json.parser", "Nonterminated string"); } static str -JSONnumberParser(char *j, char **next, int silent) +JSONnumberParser(char *j, char **next) { char *backup = j; @@ -744,9 +741,7 @@ JSONnumberParser(char *j, char **next, i skipblancs(j); if (*j < '0' || *j > '9') { *next = j; - if (!silent) - throw(MAL, "json.parser", "Number expected"); - return MAL_SUCCEED; + throw(MAL, "json.parser", "Number expected"); } for (; *j; j++) if (*j < '0' || *j > '9') @@ -779,12 +774,11 @@ JSONnumberParser(char *j, char **next, i } static int -JSONtoken(JSON *jt, char *j, char **next, int silent) +JSONtoken(JSON *jt, char *j, char **next) { str msg; int nxt, idx = JSONnew(jt); - assert(silent==0); if (jt->error) return idx; skipblancs(j); @@ -797,12 +791,11 @@ JSONtoken(JSON *jt, char *j, char **next skipblancs(j); if (*j == '}') break; - nxt = JSONtoken(jt, j, next, silent); + nxt = JSONtoken(jt, j, next); if (jt->error) return idx; if (jt->elm[nxt].kind != JSON_ELEMENT) { - if (!silent) - jt->error = createException(MAL, "json.parser", "Syntax error : element expected"); + jt->error = createException(MAL, "json.parser", "Syntax error : element expected"); return idx; } JSONappend(jt, idx, nxt); @@ -813,15 +806,13 @@ JSONtoken(JSON *jt, char *j, char **next if (*j == '}') break; if (*j != '}' && *j != ',') { - if (!silent) - jt->error = createException(MAL, "json.parser", "Syntax error : ',' or '}' expected"); + jt->error = createException(MAL, "json.parser", "Syntax error : ',' or '}' expected"); return idx; } j++; } if (*j != '}') { - if (!silent) - jt->error = createException(MAL, "json.parser", "Syntax error : '}' expected"); + jt->error = createException(MAL, "json.parser", "Syntax error : '}' expected"); return idx; } else j++; @@ -836,7 +827,7 @@ JSONtoken(JSON *jt, char *j, char **next skipblancs(j); if (*j == ']') break; - nxt = JSONtoken(jt, j, next, silent); + nxt = JSONtoken(jt, j, next); if (jt->error) return idx; switch (jt->elm[nxt].kind) { @@ -872,33 +863,29 @@ JSONtoken(JSON *jt, char *j, char **next if (*j == ']') break; if (jt->elm[nxt].kind == JSON_ELEMENT) { - if (!silent) - jt->error = createException(MAL, "json.parser", "Syntax error : Array value expected"); + jt->error = createException(MAL, "json.parser", "Syntax error : Array value expected"); return idx; } if (*j != ']' && *j != ',') { - if (!silent) - jt->error = createException(MAL, "json.parser", "Syntax error : ',' or ']' expected"); + jt->error = createException(MAL, "json.parser", "Syntax error : ',' or ']' expected"); return idx; } j++; skipblancs(j); } if (*j != ']') { - if (!silent) - jt->error = createException(MAL, "json.parser", "Syntax error : ']' expected"); + jt->error = createException(MAL, "json.parser", "Syntax error : ']' expected"); } else j++; *next = j; jt->elm[idx].valuelen = *next - jt->elm[idx].value; return idx; case '"': - msg = JSONstringParser(j, next, silent); - if (!silent && msg) { + msg = JSONstringParser(j, next); + if (msg) { jt->error = msg; return idx; } - freeException(msg); jt->elm[idx].kind = JSON_STRING; jt->elm[idx].value = j; jt->elm[idx].valuelen = *next - j; @@ -908,7 +895,7 @@ JSONtoken(JSON *jt, char *j, char **next j++; skipblancs(j); jt->elm[idx].kind = JSON_ELEMENT; - nxt = JSONtoken(jt, j, next, silent); + nxt = JSONtoken(jt, j, next); if (jt->error) return idx; jt->elm[idx].child = nxt; @@ -924,8 +911,7 @@ JSONtoken(JSON *jt, char *j, char **next jt->elm[idx].valuelen = 4; return idx; } - if (!silent) - jt->error = createException(MAL, "json.parser", "Syntax error: NULL expected"); + jt->error = createException(MAL, "json.parser", "Syntax error: NULL expected"); return idx; case 't': if (strncmp("true", j, 4) == 0) { @@ -935,8 +921,7 @@ JSONtoken(JSON *jt, char *j, char **next jt->elm[idx].valuelen = 4; return idx; } - if (!silent) - jt->error = createException(MAL, "json.parser", "Syntax error: True expected"); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list