From 3ff60c3ec1d6c2d0f4f23f4dcdcd0bdc0476c7f1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Aug 2020 11:19:16 +0800 Subject: [PATCH] TD-1037 --- src/inc/taosmsg.h | 4 ++-- src/os/inc/osFile.h | 12 ++++++++++++ src/os/inc/osMemory.h | 6 +++--- src/os/inc/osWindows.h | 3 +++ src/util/inc/tconfig.h | 2 +- src/util/src/tcompression.c | 2 +- src/util/src/tconfig.c | 8 ++++---- src/util/src/terror.c | 2 +- src/util/src/thashutil.c | 2 +- src/util/src/tlog.c | 2 +- src/util/src/tsched.c | 4 ++-- src/util/src/tskiplist.c | 8 ++++---- src/util/src/ttimer.c | 4 ++-- src/util/src/tutil.c | 4 ++-- 14 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 57e0b46f06..6d43568ecd 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -206,7 +206,7 @@ typedef struct SSubmitMsg { SMsgHead header; int32_t length; int32_t numOfBlocks; - SSubmitBlk blocks[]; + char blocks[]; } SSubmitMsg; typedef struct { @@ -680,7 +680,7 @@ typedef struct STableMetaMsg { typedef struct SMultiTableMeta { int32_t numOfTables; int32_t contLen; - STableMetaMsg metas[]; + char metas[]; } SMultiTableMeta; typedef struct { diff --git a/src/os/inc/osFile.h b/src/os/inc/osFile.h index 6e48e80ca4..3bd32734e6 100644 --- a/src/os/inc/osFile.h +++ b/src/os/inc/osFile.h @@ -56,6 +56,18 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP // TAOS_OS_FUNC_FILE_GETTMPFILEPATH void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath); +#ifdef TAOS_OS_FUNC_FILE_ISDIR + #define S_ISDIR(m) (((m) & 0170000) == (0040000)) +#endif + +#ifdef TAOS_OS_FUNC_FILE_ISREG + #define S_ISREG(m) !(S_ISDIR(m)) +#endif + +#ifdef TAOS_OS_FUNC_FILE_ISLNK + #define S_ISLNK(m) 0 +#endif + #ifdef __cplusplus } #endif diff --git a/src/os/inc/osMemory.h b/src/os/inc/osMemory.h index aaac8c68e3..37d9dc9828 100644 --- a/src/os/inc/osMemory.h +++ b/src/os/inc/osMemory.h @@ -74,9 +74,9 @@ void taosTMemset(void *ptr, int c); #define taosCalloc(num, size) taos_calloc(num, size, __FILE__, __LINE__) #define taosRealloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__) #define taosFree(ptr) taos_free(ptr, __FILE__, __LINE__) - #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__) - #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__) - #define taosGetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__) + //#define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__) + //#define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__) + //#define taosGetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__) #endif #endif diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index 8c5c8e9d1a..fcb89c072d 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -60,6 +60,9 @@ extern "C" { #define TAOS_OS_FUNC_DIR #define TAOS_OS_FUNC_FILE +#define TAOS_OS_FUNC_FILE_ISREG +#define TAOS_OS_FUNC_FILE_ISDIR +#define TAOS_OS_FUNC_FILE_ISLNK #define TAOS_OS_FUNC_FILE_SENDIFLE #define taosFSendFile(outfile, infile, offset, count) taosFSendFileImp(outfile, infile, offset, size) #define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h index 79b19ff79d..0520cf29a8 100644 --- a/src/util/inc/tconfig.h +++ b/src/util/inc/tconfig.h @@ -68,7 +68,7 @@ typedef struct { int8_t cfgStatus; int8_t unitType; int8_t valType; - uint32_t ptrLength; + int32_t ptrLength; } SGlobalCfg; extern SGlobalCfg tsGlobalConfig[]; diff --git a/src/util/src/tcompression.c b/src/util/src/tcompression.c index b085e26e07..33828d93f0 100644 --- a/src/util/src/tcompression.c +++ b/src/util/src/tcompression.c @@ -129,7 +129,7 @@ int tsCompressINTImp(const char *const input, const int nelements, char *const o if (zigzag_value >= SIMPLE8B_MAX_INT64) goto _copy_and_exit; - char tmp_bit; + int64_t tmp_bit; if (zigzag_value == 0) { // Take care here, __builtin_clzl give wrong anser for value 0; tmp_bit = 0; diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index 9fc9386b42..ccf4ea7317 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -98,7 +98,7 @@ static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) { } static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { - int length = strlen(input_value); + int length = (int)strlen(input_value); char *option = (char *)cfg->ptr; if (length <= 0 || length > cfg->ptrLength) { uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", @@ -150,7 +150,7 @@ static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) { } static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) { - int length = strlen(input_value); + int length = (int) strlen(input_value); char *option = (char *)cfg->ptr; if (length <= 0 || length > cfg->ptrLength) { uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", @@ -283,7 +283,7 @@ void taosReadGlobalLogCfg() { option = value = NULL; olen = vlen = 0; - getline(&line, &len, fp); + taosGetline(&line, &len, fp); line[len - 1] = 0; paGetToken(line, &option, &olen); @@ -329,7 +329,7 @@ bool taosReadGlobalCfg() { option = value = NULL; olen = vlen = 0; - getline(&line, &len, fp); + taosGetline(&line, &len, fp); line[len - 1] = 0; paGetToken(line, &option, &olen); diff --git a/src/util/src/terror.c b/src/util/src/terror.c index aa6925464e..1eb6893cbc 100644 --- a/src/util/src/terror.c +++ b/src/util/src/terror.c @@ -49,7 +49,7 @@ static int tsCompareTaosError(const void* a, const void* b) { } static pthread_once_t tsErrorInit = PTHREAD_ONCE_INIT; -static void tsSortError() { +static void tsSortError(void) { qsort(errors, sizeof(errors)/sizeof(errors[0]), sizeof(errors[0]), tsCompareTaosError); } diff --git a/src/util/src/thashutil.c b/src/util/src/thashutil.c index 33f0d6d430..681d73db3d 100644 --- a/src/util/src/thashutil.c +++ b/src/util/src/thashutil.c @@ -78,7 +78,7 @@ uint32_t taosIntHash_64(const char *key, uint32_t UNUSED_PARAM(len)) { uint64_t hash = val >> 16U; hash += (val & 0xFFFFU); - return hash; + return (uint32_t)hash; } _hash_fn_t taosGetDefaultHashFunction(int32_t type) { diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 913989bf52..cf6ccdcbce 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -65,7 +65,7 @@ typedef struct { int32_t tsAsyncLog = 1; float tsTotalLogDirGB = 0; float tsAvailLogDirGB = 0; -float tsMinimalLogDirGB = 0.1; +float tsMinimalLogDirGB = 0.1f; char tsLogDir[TSDB_FILENAME_LEN] = "/var/log/taos"; static SLogObj tsLogObj = { .fileNum = 1 }; diff --git a/src/util/src/tsched.c b/src/util/src/tsched.c index 39155bc0fd..cf7f5c10d4 100644 --- a/src/util/src/tsched.c +++ b/src/util/src/tsched.c @@ -192,12 +192,12 @@ void taosCleanUpScheduler(void *param) { pSched->stop = true; for (int i = 0; i < pSched->numOfThreads; ++i) { - if (pSched->qthread[i]) { + if (taosCheckPthreadValid(pSched->qthread[i])) { tsem_post(&pSched->fullSem); } } for (int i = 0; i < pSched->numOfThreads; ++i) { - if (pSched->qthread[i]) { + if (taosCheckPthreadValid(pSched->qthread[i])) { pthread_join(pSched->qthread[i], NULL); } } diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 14029fbd81..303c2440bf 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -19,7 +19,7 @@ #include "tutil.h" #include "tcompare.h" -__attribute__ ((unused)) static FORCE_INLINE void recordNodeEachLevel(SSkipList *pSkipList, int32_t level) { // record link count in each level +UNUSED_FUNC static FORCE_INLINE void recordNodeEachLevel(SSkipList *pSkipList, int32_t level) { // record link count in each level #if SKIP_LIST_RECORD_PERFORMANCE for (int32_t i = 0; i < level; ++i) { pSkipList->state.nLevelNodeCnt[i]++; @@ -27,7 +27,7 @@ __attribute__ ((unused)) static FORCE_INLINE void recordNodeEachLevel(SSkipList #endif } -__attribute__ ((unused)) static FORCE_INLINE void removeNodeEachLevel(SSkipList *pSkipList, int32_t level) { +UNUSED_FUNC static FORCE_INLINE void removeNodeEachLevel(SSkipList *pSkipList, int32_t level) { #if SKIP_LIST_RECORD_PERFORMANCE for (int32_t i = 0; i < level; ++i) { pSkipList->state.nLevelNodeCnt[i]--; @@ -132,7 +132,7 @@ static bool initForwardBackwardPtr(SSkipList* pSkipList) { pSkipList->pTail = (SSkipListNode*) ((char*) pSkipList->pHead + SL_NODE_HEADER_SIZE(maxLevel)); pSkipList->pTail->level = pSkipList->maxLevel; - for(int32_t i = 0; i < maxLevel; ++i) { + for (uint32_t i = 0; i < maxLevel; ++i) { SL_GET_FORWARD_POINTER(pSkipList->pHead, i) = pSkipList->pTail; SL_GET_BACKWARD_POINTER(pSkipList->pTail, i) = pSkipList->pHead; } @@ -177,7 +177,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint8_t keyLen, ui } } - srand(time(NULL)); + srand((uint32_t)time(NULL)); #if SKIP_LIST_RECORD_PERFORMANCE pSkipList->state.nTotalMemSize += sizeof(SSkipList); diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index b2982d353f..0222a6d80a 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -445,7 +445,7 @@ bool taosTmrStopA(tmr_h* timerId) { bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle, tmr_h* pTmrId) { tmr_ctrl_t* ctrl = (tmr_ctrl_t*)handle; if (ctrl == NULL || ctrl->label[0] == 0) { - return NULL; + return false; } uintptr_t id = (uintptr_t)*pTmrId; @@ -491,7 +491,7 @@ static void taosTmrModuleInit(void) { return; } - for (int i = 0; i < tsMaxTmrCtrl - 1; ++i) { + for (uint32_t i = 0; i < tsMaxTmrCtrl - 1; ++i) { tmr_ctrl_t* ctrl = tmrCtrls + i; ctrl->next = ctrl + 1; } diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index f4b6ae629d..6c4af437b2 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -273,7 +273,7 @@ char *strbetween(char *string, char *begin, char *end) { char *_begin = strstr(string, begin); if (_begin != NULL) { char *_end = strstr(_begin + strlen(begin), end); - int size = _end - _begin; + int size = (int)(_end - _begin); if (_end != NULL && size > 0) { result = (char *)calloc(1, size); memcpy(result, _begin + strlen(begin), size - +strlen(begin)); @@ -332,7 +332,7 @@ bool taosGetVersionNumber(char *versionStr, int *versionNubmer) { } int versionNumberPos[5] = {0}; - int len = strlen(versionStr); + int len = (int)strlen(versionStr); int dot = 0; for (int pos = 0; pos < len && dot < 4; ++pos) { if (versionStr[pos] == '.') { -- GitLab