diff --git a/include/os/os.h b/include/os/os.h index 329ad481aa..41180ba49e 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -58,9 +58,6 @@ extern "C" { #else #include #endif - -#define __typeof(a) auto - #endif #include diff --git a/include/os/osFile.h b/include/os/osFile.h index 5ba161270d..8751e175a5 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -66,7 +66,7 @@ int32_t taosUnLockFile(TdFilePtr pFile); int32_t taosUmaskFile(int32_t maskVal); int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime); -int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno); +int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno); int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime); bool taosCheckExistFile(const char *pathname); diff --git a/include/os/osMath.h b/include/os/osMath.h index 829bbd847b..f17ca56c9e 100644 --- a/include/os/osMath.h +++ b/include/os/osMath.h @@ -23,11 +23,13 @@ extern "C" { #define TPOW2(x) ((x) * (x)) #define TABS(x) ((x) > 0 ? (x) : -(x)) -#define TSWAP(a, b) \ - do { \ - __typeof(a) __tmp = (a); \ - (a) = (b); \ - (b) = __tmp; \ +#define TSWAP(a, b) \ + do { \ + char *__tmp = taosMemoryMalloc(sizeof(a)); \ + memcpy(__tmp, &(a), sizeof(a)); \ + memcpy(&(a), &(b), sizeof(a)); \ + memcpy(&(b), __tmp, sizeof(a)); \ + taosMemoryFree(__tmp); \ } while (0) #ifdef WINDOWS diff --git a/include/util/tjson.h b/include/util/tjson.h index a95efe56e7..84f7b81726 100644 --- a/include/util/tjson.h +++ b/include/util/tjson.h @@ -25,7 +25,7 @@ extern "C" { #define tjsonGetNumberValue(pJson, pName, val, code) \ do { \ uint64_t _tmp = 0; \ - code = tjsonGetUBigIntValue(pJson, pName, &_tmp); \ + code = tjsonGetBigIntValue(pJson, pName, &_tmp); \ val = _tmp; \ } while (0) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 479a11ca4a..edfada4f47 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -3243,7 +3243,7 @@ int32_t tailFunction(SqlFunctionCtx* pCtx) { if (pInfo->offset >= pInput->numOfRows) { return 0; } else { - pInfo->numOfPoints = MIN(pInfo->numOfPoints, pInput->numOfRows - pInfo->offset); + pInfo->numOfPoints = TMIN(pInfo->numOfPoints, pInput->numOfRows - pInfo->offset); } for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex - pInfo->offset; i += 1) { diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index eea30bfb03..dd11e135b3 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -266,7 +266,7 @@ int32_t indexConvertData(void* src, int8_t type, void** dst) { TASSERT(0); break; } - *dst = *dst - tlen; + *dst = (char*)*dst - tlen; // indexMayFillNumbericData(*dst, tlen); return tlen; } @@ -306,7 +306,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, src, sizeof(float)); *dst = taosMemoryCalloc(1, tlen + 1); tlen = taosEncodeBinary(dst, src, sizeof(float)); - *dst = *dst - tlen; + *dst = (char*) * dst - tlen; break; case TSDB_DATA_TYPE_UINT: *dst = taosMemoryCalloc(1, sizeof(int64_t) + 1); @@ -320,7 +320,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, src, sizeof(double)); *dst = taosMemoryCalloc(1, tlen + 1); tlen = taosEncodeBinary(dst, src, sizeof(double)); - *dst = *dst - tlen; + *dst = (char*) * dst - tlen; break; case TSDB_DATA_TYPE_UBIGINT: assert(0); @@ -331,7 +331,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src)); *dst = taosMemoryCalloc(1, tlen + 1); tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src)); - *dst = *dst - tlen; + *dst = (char*) * dst - tlen; break; } @@ -340,7 +340,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, src, strlen(src)); *dst = taosMemoryCalloc(1, tlen + 1); tlen = taosEncodeBinary(dst, src, strlen(src)); - *dst = *dst - tlen; + *dst = (char*) * dst - tlen; break; #endif } @@ -349,7 +349,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, src, strlen(src)); *dst = taosMemoryCalloc(1, tlen + 1); tlen = taosEncodeBinary(dst, src, strlen(src)); - *dst = *dst - tlen; + *dst = (char*) * dst - tlen; break; #endif default: diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 8574e071f2..84b8688ade 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -28,9 +28,9 @@ struct SPCache { SPage lru; }; -static inline int tdbPCachePageHash(const SPgid *pPgid) { - u32 *t = (u32 *)((pPgid)->fileid); - return t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + (pPgid)->pgno; +static inline uint32_t tdbPCachePageHash(const SPgid *pPgid) { + uint32_t *t = (uint32_t *)((pPgid)->fileid); + return (uint32_t)(t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + (pPgid)->pgno); } #define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL) diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index fbd5cb3aac..dc36c76027 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -72,7 +72,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { return -1; } - ret = tdbGnrtFileID(pPager->dbFileName, pPager->fid, false); + ret = tdbGnrtFileID(pPager->fd, pPager->fid, false); if (ret < 0) { return -1; } diff --git a/source/libs/tdb/src/db/tdbUtil.c b/source/libs/tdb/src/db/tdbUtil.c index 3746d9358f..4acb83c8e4 100644 --- a/source/libs/tdb/src/db/tdbUtil.c +++ b/source/libs/tdb/src/db/tdbUtil.c @@ -35,10 +35,10 @@ void tdbFree(void *p) { } } -int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) { +int tdbGnrtFileID(tdb_fd_t fd, uint8_t *fileid, bool unique) { int64_t stDev = 0, stIno = 0; - if (taosDevInoFile(fname, &stDev, &stIno) < 0) { + if (taosDevInoFile(fd, &stDev, &stIno) < 0) { return -1; } diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index 29a505fa78..c518e8efcc 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -28,7 +28,7 @@ extern "C" { #define TDB_ROUND8(x) (((x) + 7) & ~7) -int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique); +int tdbGnrtFileID(tdb_fd_t fd, uint8_t *fileid, bool unique); int tdbGetFileSize(tdb_fd_t fd, int szPage, SPgno *size); void *tdbRealloc(void *ptr, size_t size); diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 3cd05b65cd..aa64e65638 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -110,7 +110,7 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha int64_t taosCopyFile(const char *from, const char *to) { #ifdef WINDOWS assert(0); - return 0; + return -1; #else char buffer[4096]; int64_t size = 0; @@ -190,15 +190,35 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) { return 0; } -int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) { +int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) { + if (pFile == NULL) { + return 0; + } + assert(pFile->fd >= 0); // Please check if you have closed the file. - struct stat fileStat; #ifdef WINDOWS - int32_t code = _stat(path, &fileStat); + + BY_HANDLE_FILE_INFORMATION bhfi; + HANDLE handle = (HANDLE)_get_osfhandle(pFile->fd); + if (GetFileInformationByHandle(handle, &bhfi) == FALSE) { + printf("taosFStatFile get file info fail."); + return -1; + } + + if (stDev != NULL) { + *stDev = (int64_t)(bhfi.dwVolumeSerialNumber); + } + + if (stIno != NULL) { + *stIno = (int64_t)((((uint64_t)bhfi.nFileIndexHigh) << 32) + bhfi.nFileIndexLow); + } + #else - int32_t code = stat(path, &fileStat); -#endif + + struct stat fileStat; + int32_t code = fstat(pFile->fd, &fileStat); if (code < 0) { + printf("taosFStatFile run fstat fail."); return code; } @@ -209,6 +229,7 @@ int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) { if (stIno != NULL) { *stIno = fileStat.st_ino; } +#endif return 0; } diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index fd6172e04f..4d7b15401c 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -744,7 +744,8 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { #ifdef WINDOWS GUID guid; CoCreateGuid(&guid); - memcpy(uid, &guid, uidlen); + snprintf(uid, uidlen, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], + guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); return 0; #elif defined(_TD_DARWIN_64) diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 558c2258f4..c5cd968fd9 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -183,8 +183,12 @@ int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal if (NULL == p) { return TSDB_CODE_FAILED; } - +#ifdef WINDOWS + sscanf(p,"%lld",pVal); +#else + // sscanf(p,"%ld",pVal); *pVal = strtol(p, NULL, 10); +#endif return TSDB_CODE_SUCCESS; } @@ -214,8 +218,12 @@ int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pV if (NULL == p) { return TSDB_CODE_FAILED; } - +#ifdef WINDOWS + sscanf(p,"%llu",pVal); +#else + // sscanf(p,"%ld",pVal); *pVal = strtoul(p, NULL, 10); +#endif return TSDB_CODE_SUCCESS; }