X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=src%2Fcommon%2Ffilter%2Ffilter-visitor-generate-bytecode.c;h=938f7d8a903febf4151183554f179b8bb17c25d8;hb=d72eb77f6e7a272889ad0eace21da52ae483800e;hp=e0ba9fd0a43d342ca3540cc6785dddb57f1b898a;hpb=6afbab01c56b1a634c7071e1e885759ac4fd0b7f;p=lttng-tools.git diff --git a/src/common/filter/filter-visitor-generate-bytecode.c b/src/common/filter/filter-visitor-generate-bytecode.c index e0ba9fd0a..938f7d8a9 100644 --- a/src/common/filter/filter-visitor-generate-bytecode.c +++ b/src/common/filter/filter-visitor-generate-bytecode.c @@ -19,6 +19,7 @@ #include "common/bytecode/bytecode.h" #include "common/compat/string.h" #include "common/macros.h" +#include "common/string-utils/string-utils.h" #include "filter-ast.h" #include "filter-ir.h" @@ -59,27 +60,6 @@ int visit_node_root(struct filter_parser_ctx *ctx, struct ir_op *node) return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn)); } -static -int append_str(char **s, const char *append) -{ - char *old = *s; - char *new; - size_t oldlen = (old == NULL) ? 0 : strlen(old); - size_t appendlen = strlen(append); - - new = calloc(oldlen + appendlen + 1, 1); - if (!new) { - return -ENOMEM; - } - if (oldlen) { - strcpy(new, old); - } - strcat(new, append); - *s = new; - free(old); - return 0; -} - /* * 1: match * 0: no match @@ -97,14 +77,14 @@ int load_expression_legacy_match(const struct ir_load_expression *exp, switch (op->type) { case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT: *op_type = BYTECODE_OP_GET_CONTEXT_REF; - if (append_str(symbol, "$ctx.")) { + if (strutils_append_str(symbol, "$ctx.")) { return -ENOMEM; } need_dot = false; break; case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT: *op_type = BYTECODE_OP_GET_CONTEXT_REF; - if (append_str(symbol, "$app.")) { + if (strutils_append_str(symbol, "$app.")) { return -ENOMEM; } need_dot = false; @@ -130,10 +110,10 @@ int load_expression_legacy_match(const struct ir_load_expression *exp, case IR_LOAD_EXPRESSION_LOAD_FIELD: goto end; case IR_LOAD_EXPRESSION_GET_SYMBOL: - if (need_dot && append_str(symbol, ".")) { + if (need_dot && strutils_append_str(symbol, ".")) { return -ENOMEM; } - if (append_str(symbol, op->u.symbol)) { + if (strutils_append_str(symbol, op->u.symbol)) { return -ENOMEM; } break; @@ -240,7 +220,7 @@ int visit_node_load_expression(struct filter_parser_ctx *ctx, switch (op->type) { case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT: { - const int ret = bytecode_push_get_context_root(&ctx->bytecode); + ret = bytecode_push_get_context_root(&ctx->bytecode); if (ret) { return ret; @@ -250,7 +230,8 @@ int visit_node_load_expression(struct filter_parser_ctx *ctx, } case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT: { - const int ret = bytecode_push_get_app_context_root(&ctx->bytecode); + ret = bytecode_push_get_app_context_root( + &ctx->bytecode); if (ret) { return ret; @@ -260,7 +241,7 @@ int visit_node_load_expression(struct filter_parser_ctx *ctx, } case IR_LOAD_EXPRESSION_GET_PAYLOAD_ROOT: { - const int ret = bytecode_push_get_payload_root(&ctx->bytecode); + ret = bytecode_push_get_payload_root(&ctx->bytecode); if (ret) { return ret; @@ -270,10 +251,8 @@ int visit_node_load_expression(struct filter_parser_ctx *ctx, } case IR_LOAD_EXPRESSION_GET_SYMBOL: { - const int ret = bytecode_push_get_symbol( - &ctx->bytecode, - &ctx->bytecode_reloc, - op->u.symbol); + ret = bytecode_push_get_symbol(&ctx->bytecode, + &ctx->bytecode_reloc, op->u.symbol); if (ret) { return ret; @@ -283,7 +262,8 @@ int visit_node_load_expression(struct filter_parser_ctx *ctx, } case IR_LOAD_EXPRESSION_GET_INDEX: { - const int ret = bytecode_push_get_index_u64(&ctx->bytecode, op->u.index); + ret = bytecode_push_get_index_u64( + &ctx->bytecode, op->u.index); if (ret) { return ret; @@ -295,7 +275,6 @@ int visit_node_load_expression(struct filter_parser_ctx *ctx, { struct load_op *insn; uint32_t insn_len = sizeof(struct load_op); - int ret; insn = calloc(insn_len, 1); if (!insn)