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;
  }

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

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

  return pRow->pObj;
}

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

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

  mTrace("row:%p, is freed", pRow->pObj);
wafwerar's avatar
wafwerar 已提交
49
  taosMemoryFreeClear(pRow);
S
Shengliang Guan 已提交
50
}