Skip to content

Commit

Permalink
Treat macro definition P1_x=0 as false instead of just checking if de…
Browse files Browse the repository at this point in the history
…fined.
  • Loading branch information
adamshapiro0 committed Aug 21, 2024
1 parent 80214d7 commit 8a7aceb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
28 changes: 14 additions & 14 deletions c/src/point_one/polaris/polaris.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
do { \
} while (0)

#if defined(P1_NO_PRINT)
#if P1_NO_PRINT
#define P1_PrintMessage(level, x, ...) P1_NOOP
#define P1_PrintErrno(x, ...) P1_NOOP

#define P1_PrintData(buffer, length) P1_NOOP
#if defined(POLARIS_USE_TLS)
#if POLARIS_USE_TLS
#define ShowCerts(ssl) \
do { \
} while (0)
#endif
#else // !defined(P1_NO_PRINT)
#else // !P1_NO_PRINT
static int __log_level = POLARIS_LOG_LEVEL_INFO;

static PolarisPrintCallback_t __print_callback = NULL;
Expand Down Expand Up @@ -142,10 +142,10 @@ static void P1_PrintToCallback(int line, int level, const char* format, ...) {
P1_PrintErrnoLevel(POLARIS_LOG_LEVEL_ERROR, x, ret)

static void P1_PrintData(const uint8_t* buffer, size_t length);
#if defined(POLARIS_USE_TLS)
#if POLARIS_USE_TLS
static void ShowCerts(SSL* ssl);
#endif
#endif // defined(P1_NO_PRINT)
#endif // P1_NO_PRINT

#define P1_PrintError(x, ...) \
P1_PrintMessage(POLARIS_LOG_LEVEL_ERROR, x, ##__VA_ARGS__)
Expand All @@ -158,11 +158,11 @@ static void ShowCerts(SSL* ssl);
#define P1_PrintTrace(x, ...) \
P1_PrintMessage(POLARIS_LOG_LEVEL_TRACE, x, ##__VA_ARGS__)

#if defined(POLARIS_NO_PRINT)
#if POLARIS_NO_PRINT
#define P1_PrintReadWriteError(context, x, ret) P1_NOOP
#define P1_DebugPrintReadWriteError(context, x, ret) P1_NOOP
#define P1_PrintSSLError(context, x, ret) P1_NOOP
#elif defined(POLARIS_USE_TLS)
#elif POLARIS_USE_TLS
static void __P1_PrintSSLError(int level, int line, PolarisContext_t* context,
const char* message, int ret) {
SSL_load_error_strings();
Expand Down Expand Up @@ -221,7 +221,7 @@ static void __P1_PrintSSLError(int level, int line, PolarisContext_t* context,
}
#define P1_PrintSSLError(context, x, ret) \
__P1_PrintSSLError(POLARIS_LOG_LEVEL_ERROR, __LINE__, context, x, ret)
#else // !defined(POLARIS_NO_PRINT) && !defined(POLARIS_USE_TLS)
#else // !POLARIS_NO_PRINT && !POLARIS_USE_TLS
#define P1_PrintReadWriteError(context, x, ret) P1_PrintErrno(x, ret)
#define P1_DebugPrintReadWriteError(context, x, ret) \
if (__log_level >= POLARIS_LOG_LEVEL_DEBUG) { \
Expand Down Expand Up @@ -281,14 +281,14 @@ void Polaris_Free(PolarisContext_t* context) { CloseSocket(context, 1); }

/******************************************************************************/
void Polaris_SetLogLevel(int log_level) {
#if !defined(POLARIS_NO_PRINT)
#if !POLARIS_NO_PRINT
__log_level = log_level;
#endif
}

/******************************************************************************/
void Polaris_SetPrintCallback(PolarisPrintCallback_t callback) {
#if !defined(POLARIS_NO_PRINT)
#if !POLARIS_NO_PRINT
__print_callback = callback;
#endif
}
Expand Down Expand Up @@ -1136,7 +1136,7 @@ static int OpenSocket(PolarisContext_t* context, const char* endpoint_url,
// Perform SSL handhshake.
ret = SSL_connect(context->ssl);
if (ret != 1) {
#if !defined(P1_NO_PRINT)
#if !P1_NO_PRINT
// Note: We intentionally reuse the receive buffer to store the error
// message to be displayed to avoid requiring additional stack here. At this
// point we're trying to open the socket, so there should be nobody actively
Expand All @@ -1145,7 +1145,7 @@ static int OpenSocket(PolarisContext_t* context, const char* endpoint_url,
"TLS handshake failed for tcp://%s:%d", endpoint_url,
endpoint_port);
P1_PrintSSLError(context, (char*)context->recv_buffer, ret);
#endif // !defined(P1_NO_PRINT)
#endif // !P1_NO_PRINT
CloseSocket(context, 1);
return POLARIS_SOCKET_ERROR;
}
Expand Down Expand Up @@ -1376,7 +1376,7 @@ static int GetHTTPResponse(PolarisContext_t* context) {
}

/******************************************************************************/
#if !defined(P1_NO_PRINT)
#if !P1_NO_PRINT
void P1_PrintData(const uint8_t* buffer, size_t length) {
if (__log_level < POLARIS_LOG_LEVEL_TRACE) {
return;
Expand Down Expand Up @@ -1415,7 +1415,7 @@ void P1_PrintData(const uint8_t* buffer, size_t length) {
#endif

/******************************************************************************/
#if !defined(P1_NO_PRINT) && defined(POLARIS_USE_TLS)
#if !P1_NO_PRINT && POLARIS_USE_TLS
void ShowCerts(SSL* ssl) {
if (__log_level < POLARIS_LOG_LEVEL_DEBUG) {
return;
Expand Down
14 changes: 7 additions & 7 deletions src/point_one/polaris/polaris_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <iomanip>

#if defined(P1_NO_PRINT)
#if P1_NO_PRINT
#include <iostream>
static std::ostream null_stream(0);
#define LOG(severity) null_stream
Expand All @@ -18,7 +18,7 @@ static std::ostream null_stream(0);
#define LOG_WARNING_STREAM(filename, line) null_stream
#define LOG_ERROR_STREAM(filename, line) null_stream

#elif defined(POLARIS_NO_GLOG)
#elif POLARIS_NO_GLOG
#include <iostream>

// Reference:
Expand Down Expand Up @@ -47,19 +47,19 @@ static Stream cerr_stream;
static std::ostream null_stream(0);

#define LOG(severity) cerr_stream
#if defined(POLARIS_DEBUG)
#if POLARIS_DEBUG
#define VLOG(severity) cerr_stream
#define VLOG_IS_ON(severity) true
#else // !defined(POLARIS_DEBUG)
#else // !POLARIS_DEBUG
#define VLOG(severity) null_stream
#define VLOG_IS_ON(severity) false
#endif // defined(POLARIS_DEBUG)
#endif // POLARIS_DEBUG

#define LOG_INFO_STREAM(filename, line) LOG(INFO)
#define LOG_WARNING_STREAM(filename, line) LOG(WARNING)
#define LOG_ERROR_STREAM(filename, line) LOG(ERROR)

#else // !defined(P1_NO_PRINT) && !defined(POLARIS_NO_GLOG)
#else // !P1_NO_PRINT && !POLARIS_NO_GLOG
#include <glog/logging.h>

#if GOOGLE_STRIP_LOG == 0
Expand All @@ -83,7 +83,7 @@ static std::ostream null_stream(0);
#define LOG_ERROR_STREAM(filename, line) google::NullStream()
#endif

#endif // defined(POLARIS_NO_GLOG)
#endif // P1_NO_PRINT / POLARIS_NO_GLOG

using namespace point_one::polaris;

Expand Down

0 comments on commit 8a7aceb

Please sign in to comment.