fix(os): win str to int64 error
This commit is contained in:
parent
cee955bf94
commit
b7ca4f7710
|
@ -58,9 +58,6 @@ extern "C" {
|
||||||
#else
|
#else
|
||||||
#include <winsock.h>
|
#include <winsock.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define __typeof(a) auto
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
|
@ -66,7 +66,7 @@ int32_t taosUnLockFile(TdFilePtr pFile);
|
||||||
int32_t taosUmaskFile(int32_t maskVal);
|
int32_t taosUmaskFile(int32_t maskVal);
|
||||||
|
|
||||||
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime);
|
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);
|
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime);
|
||||||
bool taosCheckExistFile(const char *pathname);
|
bool taosCheckExistFile(const char *pathname);
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,13 @@ extern "C" {
|
||||||
#define TPOW2(x) ((x) * (x))
|
#define TPOW2(x) ((x) * (x))
|
||||||
#define TABS(x) ((x) > 0 ? (x) : -(x))
|
#define TABS(x) ((x) > 0 ? (x) : -(x))
|
||||||
|
|
||||||
#define TSWAP(a, b) \
|
#define TSWAP(a, b) \
|
||||||
do { \
|
do { \
|
||||||
__typeof(a) __tmp = (a); \
|
char *__tmp = taosMemoryMalloc(sizeof(a)); \
|
||||||
(a) = (b); \
|
memcpy(__tmp, &(a), sizeof(a)); \
|
||||||
(b) = __tmp; \
|
memcpy(&(a), &(b), sizeof(a)); \
|
||||||
|
memcpy(&(b), __tmp, sizeof(a)); \
|
||||||
|
taosMemoryFree(__tmp); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
|
|
@ -25,7 +25,7 @@ extern "C" {
|
||||||
#define tjsonGetNumberValue(pJson, pName, val, code) \
|
#define tjsonGetNumberValue(pJson, pName, val, code) \
|
||||||
do { \
|
do { \
|
||||||
uint64_t _tmp = 0; \
|
uint64_t _tmp = 0; \
|
||||||
code = tjsonGetUBigIntValue(pJson, pName, &_tmp); \
|
code = tjsonGetBigIntValue(pJson, pName, &_tmp); \
|
||||||
val = _tmp; \
|
val = _tmp; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
|
@ -3243,7 +3243,7 @@ int32_t tailFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (pInfo->offset >= pInput->numOfRows) {
|
if (pInfo->offset >= pInput->numOfRows) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} 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) {
|
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex - pInfo->offset; i += 1) {
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ int32_t indexConvertData(void* src, int8_t type, void** dst) {
|
||||||
TASSERT(0);
|
TASSERT(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*dst = *dst - tlen;
|
*dst = (char*)*dst - tlen;
|
||||||
// indexMayFillNumbericData(*dst, tlen);
|
// indexMayFillNumbericData(*dst, tlen);
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) {
|
||||||
tlen = taosEncodeBinary(NULL, src, sizeof(float));
|
tlen = taosEncodeBinary(NULL, src, sizeof(float));
|
||||||
*dst = taosMemoryCalloc(1, tlen + 1);
|
*dst = taosMemoryCalloc(1, tlen + 1);
|
||||||
tlen = taosEncodeBinary(dst, src, sizeof(float));
|
tlen = taosEncodeBinary(dst, src, sizeof(float));
|
||||||
*dst = *dst - tlen;
|
*dst = (char*) * dst - tlen;
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_UINT:
|
case TSDB_DATA_TYPE_UINT:
|
||||||
*dst = taosMemoryCalloc(1, sizeof(int64_t) + 1);
|
*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));
|
tlen = taosEncodeBinary(NULL, src, sizeof(double));
|
||||||
*dst = taosMemoryCalloc(1, tlen + 1);
|
*dst = taosMemoryCalloc(1, tlen + 1);
|
||||||
tlen = taosEncodeBinary(dst, src, sizeof(double));
|
tlen = taosEncodeBinary(dst, src, sizeof(double));
|
||||||
*dst = *dst - tlen;
|
*dst = (char*) * dst - tlen;
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_UBIGINT:
|
case TSDB_DATA_TYPE_UBIGINT:
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -331,7 +331,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) {
|
||||||
tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src));
|
tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src));
|
||||||
*dst = taosMemoryCalloc(1, tlen + 1);
|
*dst = taosMemoryCalloc(1, tlen + 1);
|
||||||
tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src));
|
tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src));
|
||||||
*dst = *dst - tlen;
|
*dst = (char*) * dst - tlen;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) {
|
||||||
tlen = taosEncodeBinary(NULL, src, strlen(src));
|
tlen = taosEncodeBinary(NULL, src, strlen(src));
|
||||||
*dst = taosMemoryCalloc(1, tlen + 1);
|
*dst = taosMemoryCalloc(1, tlen + 1);
|
||||||
tlen = taosEncodeBinary(dst, src, strlen(src));
|
tlen = taosEncodeBinary(dst, src, strlen(src));
|
||||||
*dst = *dst - tlen;
|
*dst = (char*) * dst - tlen;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) {
|
||||||
tlen = taosEncodeBinary(NULL, src, strlen(src));
|
tlen = taosEncodeBinary(NULL, src, strlen(src));
|
||||||
*dst = taosMemoryCalloc(1, tlen + 1);
|
*dst = taosMemoryCalloc(1, tlen + 1);
|
||||||
tlen = taosEncodeBinary(dst, src, strlen(src));
|
tlen = taosEncodeBinary(dst, src, strlen(src));
|
||||||
*dst = *dst - tlen;
|
*dst = (char*) * dst - tlen;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -28,9 +28,9 @@ struct SPCache {
|
||||||
SPage lru;
|
SPage lru;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline int tdbPCachePageHash(const SPgid *pPgid) {
|
static inline uint32_t tdbPCachePageHash(const SPgid *pPgid) {
|
||||||
u32 *t = (u32 *)((pPgid)->fileid);
|
uint32_t *t = (uint32_t *)((pPgid)->fileid);
|
||||||
return t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + (pPgid)->pgno;
|
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)
|
#define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL)
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = tdbGnrtFileID(pPager->dbFileName, pPager->fid, false);
|
ret = tdbGnrtFileID(pPager->fd, pPager->fid, false);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
int64_t stDev = 0, stIno = 0;
|
||||||
|
|
||||||
if (taosDevInoFile(fname, &stDev, &stIno) < 0) {
|
if (taosDevInoFile(fd, &stDev, &stIno) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ extern "C" {
|
||||||
|
|
||||||
#define TDB_ROUND8(x) (((x) + 7) & ~7)
|
#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);
|
int tdbGetFileSize(tdb_fd_t fd, int szPage, SPgno *size);
|
||||||
|
|
||||||
void *tdbRealloc(void *ptr, size_t size);
|
void *tdbRealloc(void *ptr, size_t size);
|
||||||
|
|
|
@ -110,7 +110,7 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha
|
||||||
int64_t taosCopyFile(const char *from, const char *to) {
|
int64_t taosCopyFile(const char *from, const char *to) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
assert(0);
|
assert(0);
|
||||||
return 0;
|
return -1;
|
||||||
#else
|
#else
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
|
@ -190,15 +190,35 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
|
||||||
|
|
||||||
return 0;
|
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.
|
||||||
|
|
||||||
|
#ifdef WINDOWS
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
struct stat fileStat;
|
struct stat fileStat;
|
||||||
#ifdef WINDOWS
|
int32_t code = fstat(pFile->fd, &fileStat);
|
||||||
int32_t code = _stat(path, &fileStat);
|
|
||||||
#else
|
|
||||||
int32_t code = stat(path, &fileStat);
|
|
||||||
#endif
|
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
|
printf("taosFStatFile run fstat fail.");
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,6 +229,7 @@ int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) {
|
||||||
if (stIno != NULL) {
|
if (stIno != NULL) {
|
||||||
*stIno = fileStat.st_ino;
|
*stIno = fileStat.st_ino;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -744,7 +744,8 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
GUID guid;
|
GUID guid;
|
||||||
CoCreateGuid(&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;
|
return 0;
|
||||||
#elif defined(_TD_DARWIN_64)
|
#elif defined(_TD_DARWIN_64)
|
||||||
|
|
|
@ -183,8 +183,12 @@ int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal
|
||||||
if (NULL == p) {
|
if (NULL == p) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
#ifdef WINDOWS
|
||||||
|
sscanf(p,"%lld",pVal);
|
||||||
|
#else
|
||||||
|
// sscanf(p,"%ld",pVal);
|
||||||
*pVal = strtol(p, NULL, 10);
|
*pVal = strtol(p, NULL, 10);
|
||||||
|
#endif
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,8 +218,12 @@ int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pV
|
||||||
if (NULL == p) {
|
if (NULL == p) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
#ifdef WINDOWS
|
||||||
|
sscanf(p,"%llu",pVal);
|
||||||
|
#else
|
||||||
|
// sscanf(p,"%ld",pVal);
|
||||||
*pVal = strtoul(p, NULL, 10);
|
*pVal = strtoul(p, NULL, 10);
|
||||||
|
#endif
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue