Only use CB_new constructor
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/91695c79 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/91695c79 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/91695c79 Branch: refs/heads/master Commit: 91695c795e564b3d9f67d8d500d76053b62ed2e8 Parents: f472b5e Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Tue Nov 10 13:45:21 2015 +0100 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Sun Nov 15 12:38:48 2015 +0100 ---------------------------------------------------------------------- core/Lucy/Search/ANDQuery.c | 3 ++- core/Lucy/Search/Compiler.c | 3 ++- core/Lucy/Search/ORQuery.c | 3 ++- core/Lucy/Search/PhraseQuery.c | 3 ++- core/Lucy/Util/Json.c | 25 ++++++++++++++----------- core/LucyX/Search/ProximityQuery.c | 3 ++- 6 files changed, 24 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/91695c79/core/Lucy/Search/ANDQuery.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Search/ANDQuery.c b/core/Lucy/Search/ANDQuery.c index 3e2f2d5..3178c42 100644 --- a/core/Lucy/Search/ANDQuery.c +++ b/core/Lucy/Search/ANDQuery.c @@ -49,7 +49,8 @@ ANDQuery_To_String_IMP(ANDQuery *self) { uint32_t num_kids = Vec_Get_Size(ivars->children); if (!num_kids) { return Str_new_from_trusted_utf8("()", 2); } else { - CharBuf *buf = CB_new_from_trusted_utf8("(", 1); + CharBuf *buf = CB_new(0); + CB_Cat_Trusted_Utf8(buf, "(", 1); for (uint32_t i = 0; i < num_kids; i++) { String *kid_string = Obj_To_String(Vec_Fetch(ivars->children, i)); CB_Cat(buf, kid_string); http://git-wip-us.apache.org/repos/asf/lucy/blob/91695c79/core/Lucy/Search/Compiler.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Search/Compiler.c b/core/Lucy/Search/Compiler.c index 6dc920e..cea70f6 100644 --- a/core/Lucy/Search/Compiler.c +++ b/core/Lucy/Search/Compiler.c @@ -109,7 +109,8 @@ String* Compiler_To_String_IMP(Compiler *self) { CompilerIVARS *const ivars = Compiler_IVARS(self); String *stringified_query = Query_To_String(ivars->parent); - CharBuf *buf = CB_new_from_trusted_utf8("compiler(", 9); + CharBuf *buf = CB_new(0); + CB_Cat_Trusted_Utf8(buf, "compiler(", 9); CB_Cat(buf, stringified_query); CB_Cat_Trusted_Utf8(buf, ")", 1); String *string = CB_Yield_String(buf); http://git-wip-us.apache.org/repos/asf/lucy/blob/91695c79/core/Lucy/Search/ORQuery.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Search/ORQuery.c b/core/Lucy/Search/ORQuery.c index e6264ba..9b34d85 100644 --- a/core/Lucy/Search/ORQuery.c +++ b/core/Lucy/Search/ORQuery.c @@ -64,7 +64,8 @@ ORQuery_To_String_IMP(ORQuery *self) { uint32_t num_kids = Vec_Get_Size(ivars->children); if (!num_kids) { return Str_new_from_trusted_utf8("()", 2); } else { - CharBuf *buf = CB_new_from_trusted_utf8("(", 1); + CharBuf *buf = CB_new(0); + CB_Cat_Trusted_Utf8(buf, "(", 1); uint32_t last_kid = num_kids - 1; for (uint32_t i = 0; i < num_kids; i++) { String *kid_string = Obj_To_String(Vec_Fetch(ivars->children, i)); http://git-wip-us.apache.org/repos/asf/lucy/blob/91695c79/core/Lucy/Search/PhraseQuery.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Search/PhraseQuery.c b/core/Lucy/Search/PhraseQuery.c index bcaad8d..a453cfd 100644 --- a/core/Lucy/Search/PhraseQuery.c +++ b/core/Lucy/Search/PhraseQuery.c @@ -139,7 +139,8 @@ String* PhraseQuery_To_String_IMP(PhraseQuery *self) { PhraseQueryIVARS *const ivars = PhraseQuery_IVARS(self); uint32_t num_terms = Vec_Get_Size(ivars->terms); - CharBuf *buf = CB_new_from_str(ivars->field); + CharBuf *buf = CB_new(0); + CB_Cat(buf, ivars->field); CB_Cat_Trusted_Utf8(buf, ":\"", 2); for (uint32_t i = 0; i < num_terms; i++) { Obj *term = Vec_Fetch(ivars->terms, i); http://git-wip-us.apache.org/repos/asf/lucy/blob/91695c79/core/Lucy/Util/Json.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Util/Json.c b/core/Lucy/Util/Json.c index 6afa9b9..2d26695 100644 --- a/core/Lucy/Util/Json.c +++ b/core/Lucy/Util/Json.c @@ -89,7 +89,7 @@ S_cat_whitespace(CharBuf *buf, int32_t depth); // Set the global error object, appending escaped JSON in the vicinity of the // error. static void -S_set_error(CharBuf *buf, const char *json, const char *limit, int line, +S_set_error(const char *mess, const char *json, const char *limit, int line, const char *func); #define SET_ERROR(_mess, _json, _end) \ S_set_error(_mess, _json, _end, __LINE__, CFISH_ERR_FUNC_MACRO) @@ -480,7 +480,7 @@ S_do_parse_json(void *json_parser, const char *json, size_t len) { } LucyParseJson(json_parser, token_type, value, &state); if (state.errors) { - SET_ERROR(CB_newf("JSON syntax error"), save, end); + SET_ERROR("JSON syntax error", save, end); return NULL; } } @@ -488,7 +488,7 @@ S_do_parse_json(void *json_parser, const char *json, size_t len) { // Finish up. LucyParseJson(json_parser, 0, NULL, &state); if (state.errors) { - SET_ERROR(CB_newf("JSON syntax error"), json, end); + SET_ERROR("JSON syntax error", json, end); return NULL; } return state.result; @@ -527,7 +527,7 @@ S_parse_number(const char **json_ptr, const char *limit) { } } if (!result) { - SET_ERROR(CB_newf("JSON syntax error"), top, limit); + SET_ERROR("JSON syntax error", top, limit); } return result; } @@ -554,7 +554,7 @@ S_parse_string(const char **json_ptr, const char *limit) { } } if (!end) { - SET_ERROR(CB_newf("Unterminated string"), *json_ptr, limit); + SET_ERROR("Unterminated string", *json_ptr, limit); return NULL; } @@ -628,12 +628,12 @@ S_unescape_text(const char *top, const char *end) { char *temp_ptr = temp; if (num_end != temp_ptr + 4 || code_point < 0) { FREEMEM(target_buf); - SET_ERROR(CB_newf("Invalid \\u escape"), text - 5, end); + SET_ERROR("Invalid \\u escape", text - 5, end); return NULL; } if (code_point >= 0xD800 && code_point <= 0xDFFF) { FREEMEM(target_buf); - SET_ERROR(CB_newf("Surrogate pairs not supported"), + SET_ERROR("Surrogate pairs not supported", text - 5, end); return NULL; } @@ -643,7 +643,7 @@ S_unescape_text(const char *top, const char *end) { break; default: FREEMEM(target_buf); - SET_ERROR(CB_newf("Illegal escape"), text - 1, end); + SET_ERROR("Illegal escape", text - 1, end); return NULL; } } @@ -674,8 +674,11 @@ SI_check_keyword(const char *json, const char* end, const char *keyword, } static void -S_set_error(CharBuf *buf, const char *json, const char *limit, int line, +S_set_error(const char *mess, const char *json, const char *limit, int line, const char *func) { + CharBuf *buf = CB_new(0); + CB_Cat_Utf8(buf, mess, strlen(mess)); + if (func) { CB_catf(buf, " at %s %s line %i32 near ", func, __FILE__, (int32_t)line); @@ -696,11 +699,11 @@ S_set_error(CharBuf *buf, const char *json, const char *limit, int line, String *snippet = SSTR_WRAP_UTF8(json, (size_t)len); S_append_json_string(snippet, buf); - String *mess = CB_Yield_String(buf); + String *full_mess = CB_Yield_String(buf); DECREF(buf); // Set global error object. - Err_set_error(Err_new(mess)); + Err_set_error(Err_new(full_mess)); } int64_t http://git-wip-us.apache.org/repos/asf/lucy/blob/91695c79/core/LucyX/Search/ProximityQuery.c ---------------------------------------------------------------------- diff --git a/core/LucyX/Search/ProximityQuery.c b/core/LucyX/Search/ProximityQuery.c index 5ee0519..3e0337d 100644 --- a/core/LucyX/Search/ProximityQuery.c +++ b/core/LucyX/Search/ProximityQuery.c @@ -151,7 +151,8 @@ String* ProximityQuery_To_String_IMP(ProximityQuery *self) { ProximityQueryIVARS *const ivars = ProximityQuery_IVARS(self); uint32_t num_terms = Vec_Get_Size(ivars->terms); - CharBuf *buf = CB_new_from_str(ivars->field); + CharBuf *buf = CB_new(0); + CB_Cat(buf, ivars->field); CB_Cat_Trusted_Utf8(buf, ":\"", 2); for (uint32_t i = 0; i < num_terms; i++) { Obj *term = Vec_Fetch(ivars->terms, i);