sdbRow.c 1.4 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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/>.
 */

#define _DEFAULT_SOURCE
S
Shengliang Guan 已提交
17
#include "sdb.h"
S
Shengliang Guan 已提交
18 19

SSdbRow *sdbAllocRow(int32_t objSize) {
wafwerar's avatar
wafwerar 已提交
20
  SSdbRow *pRow = taosMemoryCalloc(1, objSize + sizeof(SSdbRow));
S
Shengliang Guan 已提交
21 22 23 24 25
  if (pRow == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return NULL;
  }

H
Haojun Liao 已提交
26
#if 1
S
Shengliang Guan 已提交
27
  mTrace("row:%p, is created, len:%d", pRow->pObj, objSize);
28
#endif
S
Shengliang Guan 已提交
29 30 31 32 33 34 35 36 37 38 39 40
  return pRow;
}

void *sdbGetRowObj(SSdbRow *pRow) {
  if (pRow == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return NULL;
  }

  return pRow->pObj;
}

41
void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc) {
S
Shengliang Guan 已提交
42 43 44
  // remove attached object such as trans
  SdbDeleteFp deleteFp = pSdb->deleteFps[pRow->type];
  if (deleteFp != NULL) {
45
    (*deleteFp)(pSdb, pRow->pObj, callFunc);
S
Shengliang Guan 已提交
46 47
  }

48
  sdbPrintOper(pSdb, pRow, "free");
S
Shengliang Guan 已提交
49

H
Haojun Liao 已提交
50
#if 1
S
Shengliang Guan 已提交
51
  mTrace("row:%p, is freed", pRow->pObj);
52
#endif
wafwerar's avatar
wafwerar 已提交
53
  taosMemoryFreeClear(pRow);
S
Shengliang Guan 已提交
54
}