未验证 提交 f5ae3389 编写于 作者: H Haojun Liao 提交者: GitHub

Merge pull request #6687 from bit-hope/develop

fix cmake scripts and reduce compile warnings
...@@ -42,13 +42,6 @@ INCLUDE(cmake/env.inc) ...@@ -42,13 +42,6 @@ INCLUDE(cmake/env.inc)
INCLUDE(cmake/version.inc) INCLUDE(cmake/version.inc)
INCLUDE(cmake/install.inc) INCLUDE(cmake/install.inc)
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -Wall -Wshadow -Werror")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe -Wall -Wshadow -Werror")
ENDIF ()
MESSAGE(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
MESSAGE(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
ADD_SUBDIRECTORY(deps) ADD_SUBDIRECTORY(deps)
ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(tests)
......
...@@ -182,7 +182,7 @@ IF (TD_WINDOWS) ...@@ -182,7 +182,7 @@ IF (TD_WINDOWS)
MESSAGE("memory sanitizer detected as false") MESSAGE("memory sanitizer detected as false")
SET(DEBUG_FLAGS "/Zi /W3 /GL") SET(DEBUG_FLAGS "/Zi /W3 /GL")
ENDIF () ENDIF ()
SET(RELEASE_FLAGS "/W0 /O3 /GL") SET(RELEASE_FLAGS "/W0 /O2 /GL") # MSVC only support O2
ENDIF () ENDIF ()
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/pthread) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/pthread)
...@@ -205,6 +205,10 @@ IF (TD_WINDOWS_32) ...@@ -205,6 +205,10 @@ IF (TD_WINDOWS_32)
MESSAGE(STATUS "windows32 is defined") MESSAGE(STATUS "windows32 is defined")
ENDIF () ENDIF ()
IF (TD_LINUX)
SET(COMMON_FLAGS "${COMMON_FLAGS} -pipe -Wshadow")
ENDIF ()
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
......
...@@ -74,13 +74,14 @@ bool taosGetProcMemory(float *memoryUsedMB) { ...@@ -74,13 +74,14 @@ bool taosGetProcMemory(float *memoryUsedMB) {
return false; return false;
} }
ssize_t _bytes = 0;
size_t len; size_t len;
char * line = NULL; char * line = NULL;
while (!feof(fp)) { while (!feof(fp)) {
tfree(line); tfree(line);
len = 0; len = 0;
getline(&line, &len, fp); _bytes = getline(&line, &len, fp);
if (line == NULL) { if ((_bytes < 0) || (line == NULL)) {
break; break;
} }
if (strstr(line, "VmRSS:") != NULL) { if (strstr(line, "VmRSS:") != NULL) {
...@@ -113,8 +114,8 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { ...@@ -113,8 +114,8 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
size_t len; size_t len;
char * line = NULL; char * line = NULL;
getline(&line, &len, fp); ssize_t _bytes = getline(&line, &len, fp);
if (line == NULL) { if ((_bytes < 0) || (line == NULL)) {
uError("read file:%s failed", tsSysCpuFile); uError("read file:%s failed", tsSysCpuFile);
fclose(fp); fclose(fp);
return false; return false;
...@@ -138,8 +139,8 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { ...@@ -138,8 +139,8 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
size_t len = 0; size_t len = 0;
char * line = NULL; char * line = NULL;
getline(&line, &len, fp); ssize_t _bytes = getline(&line, &len, fp);
if (line == NULL) { if ((_bytes < 0) || (line == NULL)) {
uError("read file:%s failed", tsProcCpuFile); uError("read file:%s failed", tsProcCpuFile);
fclose(fp); fclose(fp);
return false; return false;
...@@ -339,6 +340,7 @@ static bool taosGetCardInfo(int64_t *bytes) { ...@@ -339,6 +340,7 @@ static bool taosGetCardInfo(int64_t *bytes) {
return false; return false;
} }
ssize_t _bytes = 0;
size_t len = 2048; size_t len = 2048;
char * line = calloc(1, len); char * line = calloc(1, len);
...@@ -357,7 +359,12 @@ static bool taosGetCardInfo(int64_t *bytes) { ...@@ -357,7 +359,12 @@ static bool taosGetCardInfo(int64_t *bytes) {
int64_t nouse6 = 0; int64_t nouse6 = 0;
char nouse0[200] = {0}; char nouse0[200] = {0};
getline(&line, &len, fp); _bytes = getline(&line, &len, fp);
if (_bytes < 0)
{
break;
}
line[len - 1] = 0; line[len - 1] = 0;
if (strstr(line, "lo:") != NULL) { if (strstr(line, "lo:") != NULL) {
...@@ -420,6 +427,7 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { ...@@ -420,6 +427,7 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) {
return false; return false;
} }
ssize_t _bytes = 0;
size_t len; size_t len;
char * line = NULL; char * line = NULL;
char tmp[10]; char tmp[10];
...@@ -428,8 +436,8 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { ...@@ -428,8 +436,8 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) {
while (!feof(fp)) { while (!feof(fp)) {
tfree(line); tfree(line);
len = 0; len = 0;
getline(&line, &len, fp); _bytes = getline(&line, &len, fp);
if (line == NULL) { if ((_bytes < 0) || (line == NULL)) {
break; break;
} }
if (strstr(line, "rchar:") != NULL) { if (strstr(line, "rchar:") != NULL) {
......
...@@ -297,6 +297,7 @@ void httpJsonTimestamp(JsonBuf* buf, int64_t t, int32_t timePrecision) { ...@@ -297,6 +297,7 @@ void httpJsonTimestamp(JsonBuf* buf, int64_t t, int32_t timePrecision) {
} }
default: default:
fractionLen = 0;
assert(false); assert(false);
} }
...@@ -342,6 +343,7 @@ void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, int32_t timePrecision) { ...@@ -342,6 +343,7 @@ void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, int32_t timePrecision) {
} }
default: default:
fractionLen = 0;
assert(false); assert(false);
} }
......
...@@ -18,6 +18,24 @@ ...@@ -18,6 +18,24 @@
#include "exception.h" #include "exception.h"
#include "taoserror.h" #include "taoserror.h"
typedef union Un4B {
uint32_t ui;
float f;
} Un4B;
#if __STDC_VERSION__ >= 201112L
static_assert(sizeof(Un4B) == sizeof(uint32_t), "sizeof(Un4B) must equal to sizeof(uint32_t)");
static_assert(sizeof(Un4B) == sizeof(float), "sizeof(Un4B) must equal to sizeof(float)");
#endif
typedef union Un8B {
uint64_t ull;
double d;
} Un8B;
#if __STDC_VERSION__ >= 201112L
static_assert(sizeof(Un8B) == sizeof(uint64_t), "sizeof(Un8B) must equal to sizeof(uint64_t)");
static_assert(sizeof(Un8B) == sizeof(double), "sizeof(Un8B) must equal to sizeof(double)");
#endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// reader functions // reader functions
...@@ -175,13 +193,21 @@ uint64_t tbufReadUint64( SBufferReader* buf ) { ...@@ -175,13 +193,21 @@ uint64_t tbufReadUint64( SBufferReader* buf ) {
} }
float tbufReadFloat( SBufferReader* buf ) { float tbufReadFloat( SBufferReader* buf ) {
uint32_t ret = tbufReadUint32( buf ); Un4B _un;
return *(float*)( &ret ); tbufReadToBuffer( buf, &_un, sizeof(_un) );
if( buf->endian ) {
_un.ui = ntohl( _un.ui );
}
return _un.f;
} }
double tbufReadDouble(SBufferReader* buf) { double tbufReadDouble(SBufferReader* buf) {
uint64_t ret = tbufReadUint64( buf ); Un8B _un;
return *(double*)( &ret ); tbufReadToBuffer( buf, &_un, sizeof(_un) );
if( buf->endian ) {
_un.ull = htobe64( _un.ull );
}
return _un.d;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -381,17 +407,37 @@ void tbufWriteUint64At( SBufferWriter* buf, size_t pos, uint64_t data ) { ...@@ -381,17 +407,37 @@ void tbufWriteUint64At( SBufferWriter* buf, size_t pos, uint64_t data ) {
} }
void tbufWriteFloat( SBufferWriter* buf, float data ) { void tbufWriteFloat( SBufferWriter* buf, float data ) {
tbufWriteUint32( buf, *(uint32_t*)(&data) ); Un4B _un;
_un.f = data;
if( buf->endian ) {
_un.ui = htonl( _un.ui );
}
tbufWrite( buf, &_un, sizeof(_un) );
} }
void tbufWriteFloatAt( SBufferWriter* buf, size_t pos, float data ) { void tbufWriteFloatAt( SBufferWriter* buf, size_t pos, float data ) {
tbufWriteUint32At( buf, pos, *(uint32_t*)(&data) ); Un4B _un;
_un.f = data;
if( buf->endian ) {
_un.ui = htonl( _un.ui );
}
tbufWriteAt( buf, pos, &_un, sizeof(_un) );
} }
void tbufWriteDouble( SBufferWriter* buf, double data ) { void tbufWriteDouble( SBufferWriter* buf, double data ) {
tbufWriteUint64( buf, *(uint64_t*)(&data) ); Un8B _un;
_un.d = data;
if( buf->endian ) {
_un.ull = htobe64( _un.ull );
}
tbufWrite( buf, &_un, sizeof(_un) );
} }
void tbufWriteDoubleAt( SBufferWriter* buf, size_t pos, double data ) { void tbufWriteDoubleAt( SBufferWriter* buf, size_t pos, double data ) {
tbufWriteUint64At( buf, pos, *(uint64_t*)(&data) ); Un8B _un;
_un.d = data;
if( buf->endian ) {
_un.ull = htobe64( _un.ull );
}
tbufWriteAt( buf, pos, &_un, sizeof(_un) );
} }
...@@ -327,7 +327,8 @@ void taosReadGlobalLogCfg() { ...@@ -327,7 +327,8 @@ void taosReadGlobalLogCfg() {
printf("\nconfig file:%s not found, all variables are set to default\n", fileName); printf("\nconfig file:%s not found, all variables are set to default\n", fileName);
return; return;
} }
ssize_t _bytes = 0;
size_t len = 1024; size_t len = 1024;
line = calloc(1, len); line = calloc(1, len);
...@@ -337,7 +338,12 @@ void taosReadGlobalLogCfg() { ...@@ -337,7 +338,12 @@ void taosReadGlobalLogCfg() {
option = value = NULL; option = value = NULL;
olen = vlen = 0; olen = vlen = 0;
tgetline(&line, &len, fp); _bytes = tgetline(&line, &len, fp);
if (_bytes < 0)
{
break;
}
line[len - 1] = 0; line[len - 1] = 0;
paGetToken(line, &option, &olen); paGetToken(line, &option, &olen);
...@@ -373,7 +379,8 @@ bool taosReadGlobalCfg() { ...@@ -373,7 +379,8 @@ bool taosReadGlobalCfg() {
return false; return false;
} }
} }
ssize_t _bytes = 0;
size_t len = 1024; size_t len = 1024;
line = calloc(1, len); line = calloc(1, len);
...@@ -383,7 +390,12 @@ bool taosReadGlobalCfg() { ...@@ -383,7 +390,12 @@ bool taosReadGlobalCfg() {
option = value = value2 = value3 = NULL; option = value = value2 = value3 = NULL;
olen = vlen = vlen2 = vlen3 = 0; olen = vlen = vlen2 = vlen3 = 0;
tgetline(&line, &len, fp); _bytes = tgetline(&line, &len, fp);
if (_bytes < 0)
{
break;
}
line[len - 1] = 0; line[len - 1] = 0;
paGetToken(line, &option, &olen); paGetToken(line, &option, &olen);
......
...@@ -427,13 +427,23 @@ char *taosIpStr(uint32_t ipInt) { ...@@ -427,13 +427,23 @@ char *taosIpStr(uint32_t ipInt) {
} }
FORCE_INLINE float taos_align_get_float(const char* pBuf) { FORCE_INLINE float taos_align_get_float(const char* pBuf) {
float fv = 0; #if __STDC_VERSION__ >= 201112L
*(int32_t*)(&fv) = *(int32_t*)pBuf; static_assert(sizeof(float) == sizeof(uint32_t), "sizeof(float) must equal to sizeof(uint32_t)");
#else
assert(sizeof(float) == sizeof(uint32_t));
#endif
float fv = 0;
memcpy(&fv, pBuf, sizeof(fv)); // in ARM, return *((const float*)(pBuf)) may cause problem
return fv; return fv;
} }
FORCE_INLINE double taos_align_get_double(const char* pBuf) { FORCE_INLINE double taos_align_get_double(const char* pBuf) {
double dv = 0; #if __STDC_VERSION__ >= 201112L
*(int64_t*)(&dv) = *(int64_t*)pBuf; static_assert(sizeof(double) == sizeof(uint64_t), "sizeof(double) must equal to sizeof(uint64_t)");
#else
assert(sizeof(double) == sizeof(uint64_t));
#endif
double dv = 0;
memcpy(&dv, pBuf, sizeof(dv)); // in ARM, return *((const double*)(pBuf)) may cause problem
return dv; return dv;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册