{"action":"created","comment":{"url":"https://api.github.com/repos/ros2/rcl/pulls/comments/190098082","pull_request_review_id":122404480,"id":190098082,"diff_hunk":"@@ -0,0 +1,1362 @@\n+// Copyright 2018 Apex.AI, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+#include <errno.h>\n+#include <inttypes.h>\n+#include <stdbool.h>\n+#include <stdint.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <unistd.h>\n+#include <yaml.h>\n+\n+#include \"rcl_yaml_param_parser/parser.h\"\n+#include \"rcl_yaml_param_parser/types.h\"\n+\n+#include \"rcl/error_handling.h\"\n+#include \"rcl/types.h\"\n+#include \"rcutils/strdup.h\"\n+\n+/// NOTE: Will allow a max YAML mapping depth of 5\n+/// map level 1 : Node name mapping\n+/// map level 2 : Params mapping\n+typedef enum yaml_map_lvl_e\n+{\n+  MAP_UNINIT_LVL = 0U,\n+  MAP_NODE_NAME_LVL = 1U,\n+  MAP_PARAMS_LVL = 2U,\n+} yaml_map_lvl_t;\n+\n+/// Basic supported data types in the yaml file\n+typedef enum data_types_e\n+{\n+  DATA_TYPE_UNKNOWN = 0U,\n+  DATA_TYPE_BOOL = 1U,\n+  DATA_TYPE_INT64 = 2U,\n+  DATA_TYPE_DOUBLE = 3U,\n+  DATA_TYPE_STRING = 4U\n+} data_types_t;\n+\n+typedef enum namespace_type_e\n+{\n+  NS_TYPE_NODE = 1U,\n+  NS_TYPE_PARAM = 2U\n+} namespace_type_t;\n+\n+/// Keep track of node and parameter name spaces\n+typedef struct namespace_tracker_s\n+{\n+  char * node_ns;\n+  uint32_t num_node_ns;\n+  char * parameter_ns;\n+  uint32_t num_parameter_ns;\n+} namespace_tracker_t;\n+\n+#define MAX_STRING_SIZE 128U\n+#define PARAMS_KEY \"ros__parameters\"\n+#define NODE_NS_SEPERATOR \"/\"\n+#define PARAMETER_NS_SEPERATOR \".\"\n+\n+#define MAX_NUM_NODE_ENTRIES 256U\n+#define MAX_NUM_PARAMS_PER_NODE 512U\n+\n+static rcl_ret_t node_params_init(\n+  rcl_node_params_t * node_params,\n+  const rcl_allocator_t allocator);\n+\n+static rcl_ret_t add_val_to_bool_arr(\n+  rcl_bool_array_t * const val_array,\n+  bool * value,\n+  const rcl_allocator_t allocator);\n+\n+static rcl_ret_t add_val_to_int_arr(\n+  rcl_int64_array_t * const val_array,\n+  int64_t * value,\n+  const rcl_allocator_t allocator);\n+\n+static rcl_ret_t add_val_to_double_arr(\n+  rcl_double_array_t * const val_array,\n+  double * value,\n+  const rcl_allocator_t allocator);\n+\n+static rcl_ret_t add_val_to_string_arr(\n+  rcutils_string_array_t * const val_array,\n+  char * value,\n+  const rcl_allocator_t allocator);\n+\n+///\n+/// TODO (anup.pemmaiah): Support byte array\n+///\n+\n+static rcl_ret_t add_name_to_ns(\n+  namespace_tracker_t * ns_tracker,\n+  const char * name,\n+  const namespace_type_t namespace_type,\n+  rcl_allocator_t allocator);\n+\n+static rcl_ret_t rem_name_from_ns(\n+  namespace_tracker_t * ns_tracker,\n+  const namespace_type_t namespace_type,\n+  rcl_allocator_t allocator);\n+\n+static rcl_ret_t replace_ns(\n+  namespace_tracker_t * ns_tracker,\n+  char * const new_ns,\n+  const uint32_t new_ns_count,\n+  const namespace_type_t namespace_type,\n+  rcl_allocator_t allocator);\n+\n+static void * get_value(\n+  const char * const value,\n+  data_types_t * val_type,\n+  const rcl_allocator_t allocator);\n+\n+static rcl_ret_t parse_value(\n+  const yaml_event_t event,\n+  const bool is_seq,\n+  data_types_t * seq_data_type,\n+  rcl_params_t * params_st,\n+  const rcl_allocator_t allocator);\n+\n+static rcl_ret_t parse_key(\n+  const yaml_event_t event,\n+  uint32_t * map_level,\n+  bool * is_new_map,\n+  namespace_tracker_t * ns_tracker,\n+  rcl_params_t * params_st,\n+  const rcl_allocator_t allocator);\n+\n+static rcl_ret_t parse_events(\n+  yaml_parser_t * parser,\n+  namespace_tracker_t * ns_tracker,\n+  rcl_params_t * params_st,\n+  const rcl_allocator_t allocator);\n+\n+\n+///\n+/// Add name to namespace tracker\n+///\n+static rcl_ret_t add_name_to_ns(\n+  namespace_tracker_t * ns_tracker,\n+  const char * name,\n+  const namespace_type_t namespace_type,\n+  rcl_allocator_t allocator)\n+{\n+  char * cur_ns;\n+  uint32_t * cur_count;\n+  char * sep_str;\n+  size_t name_len;\n+  size_t ns_len;\n+  size_t sep_len;\n+  size_t tot_len;\n+  rcl_ret_t res = RCL_RET_OK;\n+\n+  switch (namespace_type) {\n+    case NS_TYPE_NODE:\n+      cur_ns = ns_tracker->node_ns;\n+      cur_count = &(ns_tracker->num_node_ns);\n+      sep_str = NODE_NS_SEPERATOR;\n+      break;\n+    case NS_TYPE_PARAM:\n+      cur_ns = ns_tracker->parameter_ns;\n+      cur_count = &(ns_tracker->num_parameter_ns);\n+      sep_str = PARAMETER_NS_SEPERATOR;\n+      break;\n+    default:\n+      res = RCL_RET_ERROR;\n+      break;\n+  }\n+\n+  if (RCL_RET_OK == res) {\n+    /// Add a name to ns\n+    if (NULL == name) {\n+      return RCL_RET_INVALID_ARGUMENT;\n+    }\n+    if (0U == *cur_count) {\n+      cur_ns = rcutils_strdup(name, allocator);\n+      if (NULL == cur_ns) {\n+        return RCL_RET_BAD_ALLOC;\n+      }\n+    } else {\n+      ns_len = strlen(cur_ns);\n+      name_len = strlen(name);\n+      sep_len = strlen(sep_str);\n+      tot_len = ns_len + name_len + sep_len + 1U;\n+\n+      if (tot_len > MAX_STRING_SIZE) {\n+        RCL_SET_ERROR_MSG(\"New namespace string is exceeding max string size\",\n+          allocator);\n+        return RCL_RET_ERROR;\n+      }\n+      cur_ns = allocator.reallocate(cur_ns, tot_len, NULL);\n+      if (NULL == cur_ns) {\n+        return RCL_RET_BAD_ALLOC;\n+      }\n+      memmove((cur_ns + ns_len), sep_str, sep_len);\n+      memmove((cur_ns + ns_len + sep_len), name, name_len);\n+      cur_ns[tot_len - 1U] = '\\0';\n+    }\n+    *cur_count = (*cur_count + 1U);\n+\n+    if (NS_TYPE_NODE == namespace_type) {\n+      ns_tracker->node_ns = cur_ns;\n+    } else {\n+      ns_tracker->parameter_ns = cur_ns;\n+    }\n+  }\n+  return res;\n+}\n+\n+///\n+/// Remove name from namespace tracker\n+///\n+static rcl_ret_t rem_name_from_ns(\n+  namespace_tracker_t * ns_tracker,\n+  const namespace_type_t namespace_type,\n+  rcl_allocator_t allocator)\n+{\n+  char * cur_ns;\n+  uint32_t * cur_count;\n+  char * sep_str;\n+  size_t ns_len;\n+  size_t tot_len;\n+  rcl_ret_t res = RCL_RET_OK;\n+\n+  switch (namespace_type) {\n+    case NS_TYPE_NODE:\n+      cur_ns = ns_tracker->node_ns;\n+      cur_count = &(ns_tracker->num_node_ns);\n+      sep_str = NODE_NS_SEPERATOR;\n+      break;\n+    case NS_TYPE_PARAM:\n+      cur_ns = ns_tracker->parameter_ns;\n+      cur_count = &(ns_tracker->num_parameter_ns);\n+      sep_str = PARAMETER_NS_SEPERATOR;\n+      break;\n+    default:\n+      res = RCL_RET_ERROR;\n+      break;\n+  }\n+\n+  if (RCL_RET_OK == res) {\n+    /// Remove last name from ns\n+    if (*cur_count > 0U) {\n+      if (1U == *cur_count) {\n+        allocator.deallocate(cur_ns, NULL);\n+        cur_ns = NULL;\n+      } else {\n+        ns_len = strlen(cur_ns);\n+        char * last_idx = NULL;\n+        char * next_str = NULL;\n+        const char * end_ptr = (cur_ns + ns_len);\n+\n+        next_str = strstr(cur_ns, sep_str);\n+        while (NULL != next_str) {\n+          if (next_str > end_ptr) {\n+            RCL_SET_ERROR_MSG(\"Internal error. Crossing arrau boundary\", allocator);\n+            return RCL_RET_ERROR;\n+          }\n+          last_idx = next_str;\n+          next_str = (next_str + strlen(sep_str));\n+          next_str = strstr(next_str, sep_str);\n+        }\n+        if (NULL != last_idx) {\n+          tot_len = (size_t)(last_idx - cur_ns);\n+          cur_ns = allocator.reallocate(cur_ns, tot_len, NULL);\n+          if (NULL == cur_ns) {\n+            return RCL_RET_BAD_ALLOC;\n+          }\n+          cur_ns[tot_len] = '\\0';\n+        }\n+      }\n+      *cur_count = (*cur_count - 1U);\n+    }\n+    if (NS_TYPE_NODE == namespace_type) {\n+      ns_tracker->node_ns = cur_ns;\n+    } else {\n+      ns_tracker->parameter_ns = cur_ns;\n+    }\n+  }\n+  return res;\n+}\n+\n+///\n+/// Replace namespace in namespace tracker\n+///\n+static rcl_ret_t replace_ns(\n+  namespace_tracker_t * ns_tracker,\n+  char * const new_ns,\n+  const uint32_t new_ns_count,\n+  const namespace_type_t namespace_type,\n+  rcl_allocator_t allocator)\n+{\n+  rcl_ret_t res = RCL_RET_OK;\n+\n+  /// Remove the old namespace and point to the new namespace\n+  switch (namespace_type) {\n+    case NS_TYPE_NODE:\n+      if (NULL != ns_tracker->node_ns) {\n+        allocator.deallocate(ns_tracker->node_ns, NULL);\n+      }\n+      ns_tracker->node_ns = new_ns;\n+      ns_tracker->num_node_ns = new_ns_count;\n+      break;\n+    case NS_TYPE_PARAM:\n+      if (NULL != ns_tracker->parameter_ns) {\n+        allocator.deallocate(ns_tracker->parameter_ns, NULL);\n+      }\n+      ns_tracker->parameter_ns = new_ns;\n+      ns_tracker->num_parameter_ns = new_ns_count;\n+      break;\n+    default:\n+      res = RCL_RET_ERROR;\n+      break;\n+  }\n+  return res;\n+}\n+\n+///\n+/// Create rcl_node_params_t structure\n+///\n+static rcl_ret_t node_params_init(\n+  rcl_node_params_t * node_params,\n+  const rcl_allocator_t allocator)\n+{\n+  if (NULL == node_params) {\n+    return RCL_RET_INVALID_ARGUMENT;\n+  }\n+\n+  node_params->parameter_names = allocator.zero_allocate(MAX_NUM_PARAMS_PER_NODE,\n+      sizeof(char *), NULL);\n+  if (NULL == node_params->parameter_names) {\n+    return RCL_RET_BAD_ALLOC;\n+  }\n+\n+  node_params->parameter_values = allocator.zero_allocate(MAX_NUM_PARAMS_PER_NODE,\n+      sizeof(rcl_variant_t), NULL);\n+  if (NULL == node_params->parameter_values) {\n+    allocator.deallocate(node_params->parameter_names, NULL);\n+    return RCL_RET_BAD_ALLOC;\n+  }\n+\n+  return RCL_RET_OK;\n+}\n+\n+///\n+/// Create the rcl_params_t parameter structure\n+///\n+rcl_params_t * rcl_yaml_node_struct_init(\n+  const rcl_allocator_t allocator)\n+{\n+  rcl_params_t * params_st;\n+\n+  params_st = allocator.zero_allocate(1, sizeof(rcl_params_t), NULL);\n+  if (NULL == params_st) {\n+    RCUTILS_SAFE_FWRITE_TO_STDERR(\"Error allocating mem\");\n+    return NULL;\n+  }\n+\n+  params_st->node_names = allocator.zero_allocate(MAX_NUM_NODE_ENTRIES,\n+      sizeof(char *), NULL);\n+  if (NULL == params_st->node_names) {\n+    rcl_yaml_node_struct_fini(params_st, allocator);\n+    RCUTILS_SAFE_FWRITE_TO_STDERR(\"Error allocating mem\");\n+    return NULL;\n+  }\n+\n+  params_st->params = allocator.zero_allocate(MAX_NUM_NODE_ENTRIES, sizeof(rcl_node_params_t),\n+      NULL);\n+  if (NULL == params_st->params) {\n+    rcl_yaml_node_struct_fini(params_st, allocator);\n+    RCUTILS_SAFE_FWRITE_TO_STDERR(\"Error allocating mem\");\n+    return NULL;\n+  }\n+\n+  params_st->num_nodes = 0U;\n+\n+  return params_st;\n+}\n+\n+///\n+/// Free param structure\n+/// NOTE: If there is an error, would recommend just to safely exit the process instead\n+/// of calling this free function and continuing\n+///\n+void rcl_yaml_node_struct_fini(\n+  rcl_params_t * params_st,\n+  const rcl_allocator_t allocator)\n+{\n+  uint32_t node_idx;\n+  uint32_t parameter_idx = 0U;\n+\n+  if (NULL == params_st) {\n+    return;\n+  }\n+\n+  for (node_idx = 0; node_idx < params_st->num_nodes; node_idx++) {\n+    char * node_name = params_st->node_names[node_idx];\n+    if (NULL != node_name) {\n+      allocator.deallocate(node_name, NULL);\n+    }\n+\n+    if (NULL != params_st->params) {\n+      char * param_name;\n+      rcl_variant_t * param_var;\n+      for (parameter_idx = 0; parameter_idx < params_st->params[node_idx].num_params;\n+        parameter_idx++)\n+      {\n+        if ((NULL != params_st->params[node_idx].parameter_names) &&\n+          (NULL != params_st->params[node_idx].parameter_values))\n+        {\n+          param_name = params_st->params[node_idx].parameter_names[parameter_idx];\n+          param_var = &(params_st->params[node_idx].parameter_values[parameter_idx]);\n+          if (NULL != param_name) {\n+            allocator.deallocate(param_name, NULL);\n+          }\n+\n+          if (NULL != param_var) {\n+            if (NULL != param_var->bool_value) {\n+              allocator.deallocate(param_var->bool_value, NULL);\n+            } else if (NULL != param_var->integer_value) {\n+              allocator.deallocate(param_var->integer_value, NULL);\n+            } else if (NULL != param_var->double_value) {\n+              allocator.deallocate(param_var->double_value, NULL);\n+            } else if (NULL != param_var->string_value) {\n+              allocator.deallocate(param_var->string_value, NULL);\n+            } else if (NULL != param_var->bool_array_value) {\n+              if (NULL != param_var->bool_array_value->values) {\n+                allocator.deallocate(param_var->bool_array_value->values, NULL);\n+              }\n+              allocator.deallocate(param_var->bool_array_value, NULL);\n+            } else if (NULL != param_var->integer_array_value) {\n+              if (NULL != param_var->integer_array_value->values) {\n+                allocator.deallocate(param_var->integer_array_value->values, NULL);\n+              }\n+              allocator.deallocate(param_var->integer_array_value, NULL);\n+            } else if (NULL != param_var->double_array_value) {\n+              if (NULL != param_var->double_array_value->values) {\n+                allocator.deallocate(param_var->double_array_value->values, NULL);\n+              }\n+              allocator.deallocate(param_var->double_array_value, NULL);\n+            } else if (NULL != param_var->string_array_value) {\n+              for (uint32_t i = 0; i < param_var->string_array_value->size; i++) {\n+                if (NULL != param_var->string_array_value->data[i]) {\n+                  allocator.deallocate(param_var->string_array_value->data[i], NULL);\n+                }\n+              }\n+              allocator.deallocate(param_var->string_array_value, NULL);\n+            } else {\n+              /// Nothing to do to keep pclint happy\n+            }\n+          }  // if (param_var)\n+        }\n+      }  // for (parameter_idx)\n+      if (NULL != params_st->params[node_idx].parameter_values) {\n+        allocator.deallocate(params_st->params[node_idx].parameter_values, NULL);\n+      }\n+      if (NULL != params_st->params[node_idx].parameter_names) {\n+        allocator.deallocate(params_st->params[node_idx].parameter_names, NULL);\n+      }\n+    }  // if (params)\n+  }  // for (node_idx)\n+  if (NULL != params_st->node_names) {\n+    allocator.deallocate(params_st->node_names, NULL);\n+    params_st->node_names = NULL;\n+  }\n+  if (NULL != params_st->params) {\n+    allocator.deallocate(params_st->params, NULL);\n+    params_st->params = NULL;\n+  }\n+  params_st->num_nodes = 0U;\n+  allocator.deallocate(params_st, NULL);\n+}\n+\n+///\n+/// Dump the param structure\n+///\n+void rcl_yaml_node_struct_print(\n+  const rcl_params_t * const params_st)\n+{\n+  uint32_t node_idx;\n+  uint32_t parameter_idx = 0U;\n+\n+  if (NULL == params_st) {\n+    return;\n+  }\n+\n+  printf(\"\\n Node Name\\t\\t\\t\\tParameters\\n\");\n+  for (node_idx = 0; node_idx < params_st->num_nodes; node_idx++) {\n+    int32_t param_col = 50;\n+    const char * const node_name = params_st->node_names[node_idx];\n+    if (NULL != node_name) {\n+      printf(\"%s\\n\", node_name);\n+    }\n+\n+    if (NULL != params_st->params) {\n+      char * param_name;\n+      rcl_variant_t * param_var;\n+      for (parameter_idx = 0; parameter_idx < params_st->params[node_idx].num_params;\n+        parameter_idx++)\n+      {\n+        if ((NULL != params_st->params[node_idx].parameter_names) &&\n+          (NULL != params_st->params[node_idx].parameter_values))\n+        {\n+          param_name = params_st->params[node_idx].parameter_names[parameter_idx];\n+          param_var = &(params_st->params[node_idx].parameter_values[parameter_idx]);\n+          if (NULL != param_name) {\n+            printf(\"%*s\", param_col, param_name);\n+          }\n+\n+          if (NULL != param_var) {\n+            if (NULL != param_var->bool_value) {\n+              printf(\": %s\\n\", *(param_var->bool_value) ? \"true\" : \"false\");\n+            } else if (NULL != param_var->integer_value) {\n+              printf(\": %\" PRId64 \"\\n\", *(param_var->integer_value));\n+            } else if (NULL != param_var->double_value) {\n+              printf(\": %lf\\n\", *(param_var->double_value));\n+            } else if (NULL != param_var->string_value) {\n+              printf(\": %s\\n\", param_var->string_value);\n+            } else if (NULL != param_var->bool_array_value) {\n+              printf(\": \");\n+              for (uint32_t i = 0; i < param_var->bool_array_value->size; i++) {\n+                if (param_var->bool_array_value->values) {\n+                  printf(\"%s, \",\n+                    (param_var->bool_array_value->values[i]) ? \"true\" : \"false\");\n+                }\n+              }\n+              printf(\"\\n\");\n+            } else if (NULL != param_var->integer_array_value) {\n+              printf(\": \");\n+              for (uint32_t i = 0; i < param_var->integer_array_value->size; i++) {\n+                if (param_var->integer_array_value->values) {\n+                  printf(\"%\" PRId64 \", \", param_var->integer_array_value->values[i]);\n+                }\n+              }\n+              printf(\"\\n\");\n+            } else if (NULL != param_var->double_array_value) {\n+              printf(\": \");\n+              for (uint32_t i = 0; i < param_var->double_array_value->size; i++) {\n+                if (param_var->double_array_value->values) {\n+                  printf(\"%lf, \", param_var->double_array_value->values[i]);\n+                }\n+              }\n+              printf(\"\\n\");\n+            } else if (NULL != param_var->string_array_value) {\n+              printf(\": \");\n+              for (uint32_t i = 0; i < param_var->string_array_value->size; i++) {\n+                if (param_var->string_array_value->data[i]) {\n+                  printf(\"%s, \", param_var->string_array_value->data[i]);\n+                }\n+              }\n+              printf(\"\\n\");\n+            }\n+          }\n+        }\n+      }\n+    }\n+  }\n+}\n+\n+///\n+/// Add a value to a bool array. Create the array if it does not exist\n+///\n+static rcl_ret_t add_val_to_bool_arr(\n+  rcl_bool_array_t * const val_array,\n+  bool * value,\n+  const rcl_allocator_t allocator)\n+{\n+  if ((NULL == value) || (NULL == val_array)) {\n+    return RCL_RET_INVALID_ARGUMENT;\n+  }\n+\n+  if (NULL == val_array->values) {\n+    val_array->values = value;\n+    val_array->size++;\n+  } else {\n+    /// Increase the array size by one and add the new value\n+    bool * tmp_arr = val_array->values;\n+    val_array->values = allocator.zero_allocate(val_array->size + 1U, sizeof(bool), NULL);\n+    if (NULL == val_array->values) {\n+      RCUTILS_SAFE_FWRITE_TO_STDERR(\"Error allocating mem\");\n+      return RCL_RET_BAD_ALLOC;\n+    }\n+    memmove(val_array->values, tmp_arr, (val_array->size * sizeof(bool)));\n+    val_array->values[val_array->size] = *value;\n+    val_array->size++;\n+    allocator.deallocate(value, NULL);\n+    allocator.deallocate(tmp_arr, NULL);\n+  }\n+  return RCL_RET_OK;\n+}\n+\n+///\n+/// Add a value to an integer array. Create the array if it does not exist\n+///\n+static rcl_ret_t add_val_to_int_arr(\n+  rcl_int64_array_t * const val_array,\n+  int64_t * value,\n+  const rcl_allocator_t allocator)\n+{\n+  if ((NULL == value) || (NULL == val_array)) {\n+    return RCL_RET_INVALID_ARGUMENT;\n+  }\n+\n+  if (NULL == val_array->values) {\n+    val_array->values = value;\n+    val_array->size++;\n+  } else {\n+    /// Increase the array size by one and add the new value\n+    int64_t * tmp_arr = val_array->values;\n+    val_array->values = allocator.zero_allocate(val_array->size + 1U, sizeof(int64_t),\n+        NULL);\n+    if (NULL == val_array->values) {\n+      RCUTILS_SAFE_FWRITE_TO_STDERR(\"Error allocating mem\");\n+      return RCL_RET_BAD_ALLOC;\n+    }\n+    memmove(val_array->values, tmp_arr, (val_array->size * sizeof(int64_t)));\n+    val_array->values[val_array->size] = *value;\n+    val_array->size++;\n+    allocator.deallocate(value, NULL);\n+    allocator.deallocate(tmp_arr, NULL);\n+  }\n+  return RCL_RET_OK;\n+}\n+\n+///\n+/// Add a value to a double array. Create the array if it does not exist\n+///\n+static rcl_ret_t add_val_to_double_arr(\n+  rcl_double_array_t * const val_array,\n+  double * value,\n+  const rcl_allocator_t allocator)\n+{\n+  if ((NULL == value) || (NULL == val_array)) {\n+    return RCL_RET_INVALID_ARGUMENT;\n+  }\n+\n+  if (NULL == val_array->values) {\n+    val_array->values = value;\n+    val_array->size++;\n+  } else {\n+    /// Increase the array size by one and add the new value\n+    double * tmp_arr = val_array->values;\n+    val_array->values = allocator.zero_allocate(val_array->size + 1U, sizeof(double),\n+        NULL);\n+    if (NULL == val_array->values) {\n+      RCUTILS_SAFE_FWRITE_TO_STDERR(\"Error allocating mem\");\n+      return RCL_RET_BAD_ALLOC;\n+    }\n+    memmove(val_array->values, tmp_arr, (val_array->size * sizeof(double)));\n+    val_array->values[val_array->size] = *value;\n+    val_array->size++;\n+    allocator.deallocate(value, NULL);\n+    allocator.deallocate(tmp_arr, NULL);\n+  }\n+  return RCL_RET_OK;\n+}\n+\n+///\n+/// Add a value to a string array. Create the array if it does not exist\n+///\n+static rcl_ret_t add_val_to_string_arr(\n+  rcutils_string_array_t * const val_array,\n+  char * value,\n+  const rcl_allocator_t allocator)\n+{\n+  if ((NULL == value) || (NULL == val_array)) {\n+    return RCL_RET_INVALID_ARGUMENT;\n+  }\n+\n+  if (NULL == val_array->data) {\n+    rcl_ret_t res;\n+\n+    res = rcutils_string_array_init(val_array, 1, &allocator);\n+    if (RCL_RET_OK != res) {\n+      return res;\n+    }\n+    val_array->data[0U] = value;\n+  } else {\n+    /// Increase the array size by one and add the new value\n+    char ** tmp_arr = val_array->data;\n+    val_array->data = allocator.zero_allocate(val_array->size + 1U, sizeof(char *), NULL);","path":"rcl_yaml_param_parser/src/parser.c","position":null,"original_position":692,"commit_id":"787dae4ac8841bd7146098fd2e1625004e13706b","original_commit_id":"6bf821cadf4382b3c1c389c60e6524e44caffa3c","user":{"login":"anup-pem","id":5606439,"avatar_url":"https://avatars1.githubusercontent.com/u/5606439?v=4","gravatar_id":"","url":"https://api.github.com/users/anup-pem","html_url":"https://github.com/anup-pem","followers_url":"https://api.github.com/users/anup-pem/followers","following_url":"https://api.github.com/users/anup-pem/following{/other_user}","gists_url":"https://api.github.com/users/anup-pem/gists{/gist_id}","starred_url":"https://api.github.com/users/anup-pem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anup-pem/subscriptions","organizations_url":"https://api.github.com/users/anup-pem/orgs","repos_url":"https://api.github.com/users/anup-pem/repos","events_url":"https://api.github.com/users/anup-pem/events{/privacy}","received_events_url":"https://api.github.com/users/anup-pem/received_events","type":"User","site_admin":false},"body":"Agree!","created_at":"2018-05-23T01:07:53Z","updated_at":"2018-05-23T01:07:53Z","html_url":"https://github.com/ros2/rcl/pull/235#discussion_r190098082","pull_request_url":"https://api.github.com/repos/ros2/rcl/pulls/235","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/ros2/rcl/pulls/comments/190098082"},"html":{"href":"https://github.com/ros2/rcl/pull/235#discussion_r190098082"},"pull_request":{"href":"https://api.github.com/repos/ros2/rcl/pulls/235"}},"in_reply_to_id":190006743},"pull_request":{"url":"https://api.github.com/repos/ros2/rcl/pulls/235","id":185886913,"html_url":"https://github.com/ros2/rcl/pull/235","diff_url":"https://github.com/ros2/rcl/pull/235.diff","patch_url":"https://github.com/ros2/rcl/pull/235.patch","issue_url":"https://api.github.com/repos/ros2/rcl/issues/235","number":235,"state":"open","locked":false,"title":"YAML parameter parser","user":{"login":"anup-pem","id":5606439,"avatar_url":"https://avatars1.githubusercontent.com/u/5606439?v=4","gravatar_id":"","url":"https://api.github.com/users/anup-pem","html_url":"https://github.com/anup-pem","followers_url":"https://api.github.com/users/anup-pem/followers","following_url":"https://api.github.com/users/anup-pem/following{/other_user}","gists_url":"https://api.github.com/users/anup-pem/gists{/gist_id}","starred_url":"https://api.github.com/users/anup-pem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anup-pem/subscriptions","organizations_url":"https://api.github.com/users/anup-pem/orgs","repos_url":"https://api.github.com/users/anup-pem/repos","events_url":"https://api.github.com/users/anup-pem/events{/privacy}","received_events_url":"https://api.github.com/users/anup-pem/received_events","type":"User","site_admin":false},"body":"A basic yaml parameter parser to parse ros2 node parameters from a yaml file and populate a C data structure","created_at":"2018-05-04T03:43:53Z","updated_at":"2018-05-23T01:07:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3b0d1b78c5e431d9db473662e342af48087b3e49","assignee":{"login":"anup-pem","id":5606439,"avatar_url":"https://avatars1.githubusercontent.com/u/5606439?v=4","gravatar_id":"","url":"https://api.github.com/users/anup-pem","html_url":"https://github.com/anup-pem","followers_url":"https://api.github.com/users/anup-pem/followers","following_url":"https://api.github.com/users/anup-pem/following{/other_user}","gists_url":"https://api.github.com/users/anup-pem/gists{/gist_id}","starred_url":"https://api.github.com/users/anup-pem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anup-pem/subscriptions","organizations_url":"https://api.github.com/users/anup-pem/orgs","repos_url":"https://api.github.com/users/anup-pem/repos","events_url":"https://api.github.com/users/anup-pem/events{/privacy}","received_events_url":"https://api.github.com/users/anup-pem/received_events","type":"User","site_admin":false},"assignees":[{"login":"anup-pem","id":5606439,"avatar_url":"https://avatars1.githubusercontent.com/u/5606439?v=4","gravatar_id":"","url":"https://api.github.com/users/anup-pem","html_url":"https://github.com/anup-pem","followers_url":"https://api.github.com/users/anup-pem/followers","following_url":"https://api.github.com/users/anup-pem/following{/other_user}","gists_url":"https://api.github.com/users/anup-pem/gists{/gist_id}","starred_url":"https://api.github.com/users/anup-pem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anup-pem/subscriptions","organizations_url":"https://api.github.com/users/anup-pem/orgs","repos_url":"https://api.github.com/users/anup-pem/repos","events_url":"https://api.github.com/users/anup-pem/events{/privacy}","received_events_url":"https://api.github.com/users/anup-pem/received_events","type":"User","site_admin":false}],"requested_reviewers":[{"login":"wjwwood","id":100427,"avatar_url":"https://avatars1.githubusercontent.com/u/100427?v=4","gravatar_id":"","url":"https://api.github.com/users/wjwwood","html_url":"https://github.com/wjwwood","followers_url":"https://api.github.com/users/wjwwood/followers","following_url":"https://api.github.com/users/wjwwood/following{/other_user}","gists_url":"https://api.github.com/users/wjwwood/gists{/gist_id}","starred_url":"https://api.github.com/users/wjwwood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wjwwood/subscriptions","organizations_url":"https://api.github.com/users/wjwwood/orgs","repos_url":"https://api.github.com/users/wjwwood/repos","events_url":"https://api.github.com/users/wjwwood/events{/privacy}","received_events_url":"https://api.github.com/users/wjwwood/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":180241099,"url":"https://api.github.com/repos/ros2/rcl/labels/in%20progress","name":"in progress","color":"fad8c7","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ros2/rcl/pulls/235/commits","review_comments_url":"https://api.github.com/repos/ros2/rcl/pulls/235/comments","review_comment_url":"https://api.github.com/repos/ros2/rcl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ros2/rcl/issues/235/comments","statuses_url":"https://api.github.com/repos/ros2/rcl/statuses/787dae4ac8841bd7146098fd2e1625004e13706b","head":{"label":"ros2:yaml_param_parser","ref":"yaml_param_parser","sha":"787dae4ac8841bd7146098fd2e1625004e13706b","user":{"login":"ros2","id":3979232,"avatar_url":"https://avatars1.githubusercontent.com/u/3979232?v=4","gravatar_id":"","url":"https://api.github.com/users/ros2","html_url":"https://github.com/ros2","followers_url":"https://api.github.com/users/ros2/followers","following_url":"https://api.github.com/users/ros2/following{/other_user}","gists_url":"https://api.github.com/users/ros2/gists{/gist_id}","starred_url":"https://api.github.com/users/ros2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ros2/subscriptions","organizations_url":"https://api.github.com/users/ros2/orgs","repos_url":"https://api.github.com/users/ros2/repos","events_url":"https://api.github.com/users/ros2/events{/privacy}","received_events_url":"https://api.github.com/users/ros2/received_events","type":"Organization","site_admin":false},"repo":{"id":31091419,"name":"rcl","full_name":"ros2/rcl","owner":{"login":"ros2","id":3979232,"avatar_url":"https://avatars1.githubusercontent.com/u/3979232?v=4","gravatar_id":"","url":"https://api.github.com/users/ros2","html_url":"https://github.com/ros2","followers_url":"https://api.github.com/users/ros2/followers","following_url":"https://api.github.com/users/ros2/following{/other_user}","gists_url":"https://api.github.com/users/ros2/gists{/gist_id}","starred_url":"https://api.github.com/users/ros2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ros2/subscriptions","organizations_url":"https://api.github.com/users/ros2/orgs","repos_url":"https://api.github.com/users/ros2/repos","events_url":"https://api.github.com/users/ros2/events{/privacy}","received_events_url":"https://api.github.com/users/ros2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ros2/rcl","description":"Library to support implementation of language specific ROS Client Libraries.","fork":false,"url":"https://api.github.com/repos/ros2/rcl","forks_url":"https://api.github.com/repos/ros2/rcl/forks","keys_url":"https://api.github.com/repos/ros2/rcl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ros2/rcl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ros2/rcl/teams","hooks_url":"https://api.github.com/repos/ros2/rcl/hooks","issue_events_url":"https://api.github.com/repos/ros2/rcl/issues/events{/number}","events_url":"https://api.github.com/repos/ros2/rcl/events","assignees_url":"https://api.github.com/repos/ros2/rcl/assignees{/user}","branches_url":"https://api.github.com/repos/ros2/rcl/branches{/branch}","tags_url":"https://api.github.com/repos/ros2/rcl/tags","blobs_url":"https://api.github.com/repos/ros2/rcl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ros2/rcl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ros2/rcl/git/refs{/sha}","trees_url":"https://api.github.com/repos/ros2/rcl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ros2/rcl/statuses/{sha}","languages_url":"https://api.github.com/repos/ros2/rcl/languages","stargazers_url":"https://api.github.com/repos/ros2/rcl/stargazers","contributors_url":"https://api.github.com/repos/ros2/rcl/contributors","subscribers_url":"https://api.github.com/repos/ros2/rcl/subscribers","subscription_url":"https://api.github.com/repos/ros2/rcl/subscription","commits_url":"https://api.github.com/repos/ros2/rcl/commits{/sha}","git_commits_url":"https://api.github.com/repos/ros2/rcl/git/commits{/sha}","comments_url":"https://api.github.com/repos/ros2/rcl/comments{/number}","issue_comment_url":"https://api.github.com/repos/ros2/rcl/issues/comments{/number}","contents_url":"https://api.github.com/repos/ros2/rcl/contents/{+path}","compare_url":"https://api.github.com/repos/ros2/rcl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ros2/rcl/merges","archive_url":"https://api.github.com/repos/ros2/rcl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ros2/rcl/downloads","issues_url":"https://api.github.com/repos/ros2/rcl/issues{/number}","pulls_url":"https://api.github.com/repos/ros2/rcl/pulls{/number}","milestones_url":"https://api.github.com/repos/ros2/rcl/milestones{/number}","notifications_url":"https://api.github.com/repos/ros2/rcl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ros2/rcl/labels{/name}","releases_url":"https://api.github.com/repos/ros2/rcl/releases{/id}","deployments_url":"https://api.github.com/repos/ros2/rcl/deployments","created_at":"2015-02-21T00:06:40Z","updated_at":"2018-05-01T22:25:28Z","pushed_at":"2018-05-23T01:07:13Z","git_url":"git://github.com/ros2/rcl.git","ssh_url":"git@github.com:ros2/rcl.git","clone_url":"https://github.com/ros2/rcl.git","svn_url":"https://github.com/ros2/rcl","homepage":null,"size":762,"stargazers_count":17,"watchers_count":17,"language":"C","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":18,"mirror_url":null,"archived":false,"open_issues_count":18,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":18,"open_issues":18,"watchers":17,"default_branch":"master"}},"base":{"label":"ros2:master","ref":"master","sha":"e8491ab8abba5c9653fdfc46064cc3b0d5ee18b9","user":{"login":"ros2","id":3979232,"avatar_url":"https://avatars1.githubusercontent.com/u/3979232?v=4","gravatar_id":"","url":"https://api.github.com/users/ros2","html_url":"https://github.com/ros2","followers_url":"https://api.github.com/users/ros2/followers","following_url":"https://api.github.com/users/ros2/following{/other_user}","gists_url":"https://api.github.com/users/ros2/gists{/gist_id}","starred_url":"https://api.github.com/users/ros2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ros2/subscriptions","organizations_url":"https://api.github.com/users/ros2/orgs","repos_url":"https://api.github.com/users/ros2/repos","events_url":"https://api.github.com/users/ros2/events{/privacy}","received_events_url":"https://api.github.com/users/ros2/received_events","type":"Organization","site_admin":false},"repo":{"id":31091419,"name":"rcl","full_name":"ros2/rcl","owner":{"login":"ros2","id":3979232,"avatar_url":"https://avatars1.githubusercontent.com/u/3979232?v=4","gravatar_id":"","url":"https://api.github.com/users/ros2","html_url":"https://github.com/ros2","followers_url":"https://api.github.com/users/ros2/followers","following_url":"https://api.github.com/users/ros2/following{/other_user}","gists_url":"https://api.github.com/users/ros2/gists{/gist_id}","starred_url":"https://api.github.com/users/ros2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ros2/subscriptions","organizations_url":"https://api.github.com/users/ros2/orgs","repos_url":"https://api.github.com/users/ros2/repos","events_url":"https://api.github.com/users/ros2/events{/privacy}","received_events_url":"https://api.github.com/users/ros2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ros2/rcl","description":"Library to support implementation of language specific ROS Client Libraries.","fork":false,"url":"https://api.github.com/repos/ros2/rcl","forks_url":"https://api.github.com/repos/ros2/rcl/forks","keys_url":"https://api.github.com/repos/ros2/rcl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ros2/rcl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ros2/rcl/teams","hooks_url":"https://api.github.com/repos/ros2/rcl/hooks","issue_events_url":"https://api.github.com/repos/ros2/rcl/issues/events{/number}","events_url":"https://api.github.com/repos/ros2/rcl/events","assignees_url":"https://api.github.com/repos/ros2/rcl/assignees{/user}","branches_url":"https://api.github.com/repos/ros2/rcl/branches{/branch}","tags_url":"https://api.github.com/repos/ros2/rcl/tags","blobs_url":"https://api.github.com/repos/ros2/rcl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ros2/rcl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ros2/rcl/git/refs{/sha}","trees_url":"https://api.github.com/repos/ros2/rcl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ros2/rcl/statuses/{sha}","languages_url":"https://api.github.com/repos/ros2/rcl/languages","stargazers_url":"https://api.github.com/repos/ros2/rcl/stargazers","contributors_url":"https://api.github.com/repos/ros2/rcl/contributors","subscribers_url":"https://api.github.com/repos/ros2/rcl/subscribers","subscription_url":"https://api.github.com/repos/ros2/rcl/subscription","commits_url":"https://api.github.com/repos/ros2/rcl/commits{/sha}","git_commits_url":"https://api.github.com/repos/ros2/rcl/git/commits{/sha}","comments_url":"https://api.github.com/repos/ros2/rcl/comments{/number}","issue_comment_url":"https://api.github.com/repos/ros2/rcl/issues/comments{/number}","contents_url":"https://api.github.com/repos/ros2/rcl/contents/{+path}","compare_url":"https://api.github.com/repos/ros2/rcl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ros2/rcl/merges","archive_url":"https://api.github.com/repos/ros2/rcl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ros2/rcl/downloads","issues_url":"https://api.github.com/repos/ros2/rcl/issues{/number}","pulls_url":"https://api.github.com/repos/ros2/rcl/pulls{/number}","milestones_url":"https://api.github.com/repos/ros2/rcl/milestones{/number}","notifications_url":"https://api.github.com/repos/ros2/rcl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ros2/rcl/labels{/name}","releases_url":"https://api.github.com/repos/ros2/rcl/releases{/id}","deployments_url":"https://api.github.com/repos/ros2/rcl/deployments","created_at":"2015-02-21T00:06:40Z","updated_at":"2018-05-01T22:25:28Z","pushed_at":"2018-05-23T01:07:13Z","git_url":"git://github.com/ros2/rcl.git","ssh_url":"git@github.com:ros2/rcl.git","clone_url":"https://github.com/ros2/rcl.git","svn_url":"https://github.com/ros2/rcl","homepage":null,"size":762,"stargazers_count":17,"watchers_count":17,"language":"C","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":18,"mirror_url":null,"archived":false,"open_issues_count":18,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":18,"open_issues":18,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ros2/rcl/pulls/235"},"html":{"href":"https://github.com/ros2/rcl/pull/235"},"issue":{"href":"https://api.github.com/repos/ros2/rcl/issues/235"},"comments":{"href":"https://api.github.com/repos/ros2/rcl/issues/235/comments"},"review_comments":{"href":"https://api.github.com/repos/ros2/rcl/pulls/235/comments"},"review_comment":{"href":"https://api.github.com/repos/ros2/rcl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ros2/rcl/pulls/235/commits"},"statuses":{"href":"https://api.github.com/repos/ros2/rcl/statuses/787dae4ac8841bd7146098fd2e1625004e13706b"}},"author_association":"NONE"}}
{"actor":{"display_login":"anup-pem"}}