texpr.c 1.9 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"
20
#include "taosdef.h"
H
Hongze Cheng 已提交
21
#include "tmsg.h"
H
Haojun Liao 已提交
22 23 24
#include "tarray.h"
#include "tbuffer.h"
#include "tcompare.h"
H
Haojun Liao 已提交
25
#include "thash.h"
H
Haojun Liao 已提交
26
#include "texpr.h"
H
Haojun Liao 已提交
27
#include "tvariant.h"
D
dapan1121 已提交
28
#include "tdef.h"
H
hzcheng 已提交
29

H
Haojun Liao 已提交
30 31 32
static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *));

void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) {
H
Haojun Liao 已提交
33 34 35 36
  if (pNode == NULL) {
    return;
  }

37
  if (pNode->nodeType == TEXPR_BINARYEXPR_NODE || pNode->nodeType == TEXPR_UNARYEXPR_NODE) {
H
Haojun Liao 已提交
38
    doExprTreeDestroy(&pNode, fp);
H
Haojun Liao 已提交
39
  }
wafwerar's avatar
wafwerar 已提交
40
  taosMemoryFree(pNode);
H
Haojun Liao 已提交
41 42
}

H
Haojun Liao 已提交
43
static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
H
Haojun Liao 已提交
44 45 46
  if (*pExpr == NULL) {
    return;
  }
wafwerar's avatar
wafwerar 已提交
47
  taosMemoryFree(*pExpr);
H
Haojun Liao 已提交
48 49 50
  *pExpr = NULL;
}

51 52
// TODO: these three functions should be made global
static void* exception_calloc(size_t nmemb, size_t size) {
wafwerar's avatar
wafwerar 已提交
53
  void* p = taosMemoryCalloc(nmemb, size);
54
  if (p == NULL) {
55
    THROW(TSDB_CODE_QRY_OUT_OF_MEMORY);
56
  }
57 58 59 60
  return p;
}

static void* exception_malloc(size_t size) {
wafwerar's avatar
wafwerar 已提交
61
  void* p = taosMemoryMalloc(size);
62
  if (p == NULL) {
63
    THROW(TSDB_CODE_QRY_OUT_OF_MEMORY);
64 65
  }
  return p;
66 67
}

68
static UNUSED_FUNC char* exception_strdup(const char* str) {
69 70
  char* p = strdup(str);
  if (p == NULL) {
71
    THROW(TSDB_CODE_QRY_OUT_OF_MEMORY);
72 73 74 75
  }
  return p;
}