Example #1
0
ParseNode* new_node(void *malloc_pool, ObItemType type, int num)
{
  ParseNode* node = (ParseNode*)parse_malloc(sizeof(ParseNode), malloc_pool);
  if (node != NULL)
  {
    memset(node, 0 , sizeof(ParseNode));

    node->type_ = type;
    node->num_child_ = num;
    if(num > 0)
    {
      int64_t alloc_size = sizeof(ParseNode*) * num ;
      //node->children_ = (ParseNode**)malloc(alloc_size);
      node->children_ = (ParseNode**)parse_malloc(alloc_size, malloc_pool);
      if (node->children_ != NULL)
      {
        memset(node->children_, 0, alloc_size);
      }
      else
      {
        parse_free(node);
        node = NULL;
      }
    }
    else
    {
      node->children_ = 0;
    }
  }
  return node;
}
Example #2
0
char* copy_expr_string(ParseResult* p, int expr_start, int expr_end)
{
  char *expr_string = NULL;
  if (p->input_sql_ != NULL && expr_start >= 0 && expr_end >= 0 && expr_end >= expr_start)
  {
    int len = expr_end - expr_start + 1;
    expr_string = (char*)parse_malloc(len + 1, p->malloc_pool_);
    if (expr_string != NULL)
    {
      memmove(expr_string, p->input_sql_ + expr_start - 1, len);
      expr_string[len] = '\0';
    }
  }
  return expr_string;
}