Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin committed Jul 31, 2024
1 parent 6af581f commit 413555b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions include/aws/sdkutils/private/endpoints_types_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ struct aws_endpoints_value {
double number;
struct aws_array_list array;
} v;
/* TODO: ref count? */
bool is_shallow;
/* Value is a reference to another value, no need to clean it up. */
bool is_ref;
};

struct aws_endpoints_parameter {
Expand Down
18 changes: 9 additions & 9 deletions source/endpoints_rule_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static int s_init_top_level_scope(
case AWS_ENDPOINTS_PARAMETER_BOOLEAN:
case AWS_ENDPOINTS_PARAMETER_STRING_ARRAY:
val->value = value->default_value;
val->value.is_shallow = true;
val->value.is_ref = true;
break;
break;
default:
Expand Down Expand Up @@ -312,12 +312,12 @@ static int s_resolve_expr(
size_t len = aws_array_list_length(&expr->e.array);
aws_array_list_init_dynamic(&out_value->v.array, allocator, len, sizeof(struct aws_endpoints_value));
for (size_t i = 0; i < len; ++i) {
struct aws_endpoints_expr elem;
aws_array_list_get_at(&expr->e.array, &elem, i);
struct aws_endpoints_expr expr_elem;
aws_array_list_get_at(&expr->e.array, &expr_elem, i);
struct aws_endpoints_value val;
if (s_resolve_expr(allocator, &elem, scope, &val)) {
AWS_LOGF_ERROR(AWS_LS_SDKUTILS_ENDPOINTS_RESOLVE, "Failed to array element.");
/* todo: cleanup */
if (s_resolve_expr(allocator, &expr_elem, scope, &val)) {
AWS_LOGF_ERROR(AWS_LS_SDKUTILS_ENDPOINTS_RESOLVE, "Failed to resolve array element.");
aws_endpoints_value_clean_up(out_value);
goto on_error;
}
aws_array_list_set_at(&out_value->v.array, &val, i);
Expand All @@ -338,7 +338,7 @@ static int s_resolve_expr(
struct aws_endpoints_scope_value *aws_endpoints_scope_value = element->value;

*out_value = aws_endpoints_scope_value->value;
out_value->is_shallow = true;
out_value->is_ref = true;
}
break;
}
Expand Down Expand Up @@ -481,7 +481,7 @@ int aws_endpoints_path_through_array(
}

*out_value = *val;
out_value->is_shallow = true;
out_value->is_ref = true;

return AWS_OP_SUCCESS;

Expand Down Expand Up @@ -756,7 +756,7 @@ int aws_endpoints_request_context_add_string_array(

for (size_t i = 0; i < len; ++i) {
struct aws_endpoints_value elem = {
.is_shallow = false,
.is_ref = false,
.type = AWS_ENDPOINTS_VALUE_STRING,
.v.owning_cursor_object = aws_endpoints_owning_cursor_from_cursor(allocator, values[i])};

Expand Down
2 changes: 1 addition & 1 deletion source/endpoints_ruleset.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ static int s_on_parameter_key(
aws_json_value_get_string(element, &cur);

struct aws_endpoints_value val = {
.is_shallow = false,
.is_ref = false,
.type = AWS_ENDPOINTS_VALUE_STRING,
.v.owning_cursor_string = aws_endpoints_non_owning_cursor_create(cur)};

Expand Down
13 changes: 10 additions & 3 deletions source/endpoints_types_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void aws_endpoints_value_clean_up_cb(void *value);
void aws_endpoints_value_clean_up(struct aws_endpoints_value *aws_endpoints_value) {
AWS_PRECONDITION(aws_endpoints_value);

if (aws_endpoints_value->is_shallow) {
if (aws_endpoints_value->is_ref) {
goto on_done;
}

Expand Down Expand Up @@ -236,7 +236,7 @@ int aws_endpoints_deep_copy_parameter_value(
struct aws_endpoints_value *to) {

to->type = from->type;
to->is_shallow = false;
to->is_ref = false;

if (to->type == AWS_ENDPOINTS_VALUE_STRING) {
to->v.owning_cursor_string =
Expand All @@ -251,7 +251,10 @@ int aws_endpoints_deep_copy_parameter_value(
aws_array_list_get_at(&from->v.array, &val, i);

struct aws_endpoints_value to_val;
aws_endpoints_deep_copy_parameter_value(allocator, &val, &to_val);
if (aws_endpoints_deep_copy_parameter_value(allocator, &val, &to_val)) {
AWS_LOGF_ERROR(AWS_LS_SDKUTILS_ENDPOINTS_RESOLVE, "Unexpected array element type.");
goto on_error;
}

aws_array_list_set_at(&to->v.array, &to_val, i);
}
Expand All @@ -261,4 +264,8 @@ int aws_endpoints_deep_copy_parameter_value(
}

return AWS_OP_SUCCESS;

on_error:
aws_endpoints_value_clean_up(to);
return AWS_OP_ERR;
}

0 comments on commit 413555b

Please sign in to comment.