texpr.c 1.7 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

16
#include "function.h"
S
slguan 已提交
17
#include "os.h"
H
Haojun Liao 已提交
18

S
Shengliang Guan 已提交
19
#include "texception.h"
H
Hongze Cheng 已提交
20
#include "tmsg.h"
H
hzcheng 已提交
21

H
Haojun Liao 已提交
22 23 24
static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *));

void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) {
H
Haojun Liao 已提交
25 26 27 28
  if (pNode == NULL) {
    return;
  }

29
  if (pNode->nodeType == TEXPR_BINARYEXPR_NODE || pNode->nodeType == TEXPR_UNARYEXPR_NODE) {
H
Haojun Liao 已提交
30
    doExprTreeDestroy(&pNode, fp);
H
Haojun Liao 已提交
31
  }
wafwerar's avatar
wafwerar 已提交
32
  taosMemoryFree(pNode);
H
Haojun Liao 已提交
33 34
}

H
Haojun Liao 已提交
35
static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
H
Haojun Liao 已提交
36 37 38
  if (*pExpr == NULL) {
    return;
  }
wafwerar's avatar
wafwerar 已提交
39
  taosMemoryFree(*pExpr);
H
Haojun Liao 已提交
40 41 42
  *pExpr = NULL;
}

43 44
// TODO: these three functions should be made global
static void* exception_calloc(size_t nmemb, size_t size) {
wafwerar's avatar
wafwerar 已提交
45
  void* p = taosMemoryCalloc(nmemb, size);
46
  if (p == NULL) {
47
    THROW(TSDB_CODE_QRY_OUT_OF_MEMORY);
48
  }
49 50 51 52
  return p;
}

static void* exception_malloc(size_t size) {
wafwerar's avatar
wafwerar 已提交
53
  void* p = taosMemoryMalloc(size);
54
  if (p == NULL) {
55
    THROW(TSDB_CODE_QRY_OUT_OF_MEMORY);
56 57
  }
  return p;
58 59
}

60
static UNUSED_FUNC char* exception_strdup(const char* str) {
61 62
  char* p = strdup(str);
  if (p == NULL) {
63
    THROW(TSDB_CODE_QRY_OUT_OF_MEMORY);
64 65 66 67
  }
  return p;
}