Skip to content

Commit

Permalink
Fix macro code to use boolean value in while instruction (false) (#469)
Browse files Browse the repository at this point in the history
* Fix macro code  to use boolean value in while instruction (false)

Signed-off-by: Michael Methner <mmethner@de.adit-jv.com>
  • Loading branch information
michael-methner authored May 8, 2023
1 parent b543d48 commit cfc2c86
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 39 deletions.
8 changes: 4 additions & 4 deletions include/dlt/dlt_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ typedef enum {
{ length = -1; } \
else \
{ dst = *((type *)src); src += sizeof(type); length -= sizeof(type); } \
} while(0)
} while(false)

# define DLT_MSG_READ_ID(dst, src, length) \
do { \
if ((length < 0) || ((length) < DLT_ID_SIZE)) \
{ length = -1; } \
else \
{ memcpy(dst, src, DLT_ID_SIZE); src += DLT_ID_SIZE; length -= DLT_ID_SIZE; } \
} while(0)
} while(false)

# define DLT_MSG_READ_STRING(dst, src, maxlength, dstlength, length) \
do { \
Expand All @@ -324,15 +324,15 @@ typedef enum {
src += length; \
maxlength -= length; \
} \
} while(0)
} while(false)

# define DLT_MSG_READ_NULL(src, maxlength, length) \
do { \
if (((maxlength) < 0) || ((length) < 0) || ((maxlength) < (length))) \
{ length = -1; } \
else \
{ src += length; maxlength -= length; } \
} while(0)
} while(false)

# define DLT_HEADER_SHOW_NONE 0x0000
# define DLT_HEADER_SHOW_TIME 0x0001
Expand Down
4 changes: 2 additions & 2 deletions include/dlt/dlt_cpp_extension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static inline int32_t logToDltVariadic(DltContextData &log, First const &valueA,
dlt_user_log_write_finish(&log);\
}\
}\
while(0)
while(false)

/**
* @brief macro to write a log message with variable number of arguments and without the need to specify the type of log data.
Expand All @@ -227,6 +227,6 @@ static inline int32_t logToDltVariadic(DltContextData &log, First const &valueA,
dlt_user_log_write_finish(&log);\
}\
}\
while(0)
while(false)

#endif /* DLT_CPP_EXTENSION_HPP */
4 changes: 3 additions & 1 deletion include/dlt/dlt_user.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
\{
*/

#include <stdbool.h>

#ifndef DLT_NETWORK_TRACE_ENABLE
#cmakedefine DLT_NETWORK_TRACE_ENABLE
#endif
Expand Down Expand Up @@ -111,7 +113,7 @@ extern "C" {
#define DLT_SEM_LOCK() do{\
while ((sem_wait(&dlt_mutex) == -1) && (errno == EINTR)) \
continue; /* Restart if interrupted */ \
} while(0)
} while(false)
#define DLT_SEM_FREE() { sem_post(&dlt_mutex); }

/**
Expand Down
62 changes: 32 additions & 30 deletions include/dlt/dlt_user_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
#include "dlt_version.h"
#include "dlt_types.h"

#include <stdbool.h>

/**
* \defgroup userapi DLT User API
* \addtogroup userapi
Expand Down Expand Up @@ -110,27 +112,27 @@
*/
#define DLT_REGISTER_APP(APPID, DESCRIPTION) do { \
(void)dlt_check_library_version(_DLT_PACKAGE_MAJOR_VERSION, _DLT_PACKAGE_MINOR_VERSION); \
(void)dlt_register_app(APPID, DESCRIPTION); } while (0)
(void)dlt_register_app(APPID, DESCRIPTION); } while(false)


/**
* Unregister application.
*/
#define DLT_UNREGISTER_APP() do { \
(void)dlt_unregister_app(); } while (0)
(void)dlt_unregister_app(); } while(false)

/**
* Unregister application and flush the logs buffered in startup buffer if any.
*/
#define DLT_UNREGISTER_APP_FLUSH_BUFFERED_LOGS() do { \
(void)dlt_unregister_app_flush_buffered_logs(); } while (0)
(void)dlt_unregister_app_flush_buffered_logs(); } while(false)

/**
* To Get application ID.
* @Param APPID character pointer of minimum 4 bytes
*/
#define DLT_GET_APPID(APPID) do{\
dlt_get_appid(APPID);} while(0)
dlt_get_appid(APPID);} while(false)

/**
* Register context (with default log level and default trace status)
Expand All @@ -139,7 +141,7 @@
* @param DESCRIPTION ASCII string containing description
*/
#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION) do { \
(void)dlt_register_context(&(CONTEXT), CONTEXTID, DESCRIPTION); } while (0)
(void)dlt_register_context(&(CONTEXT), CONTEXTID, DESCRIPTION); } while (false)

/**
* Register context with pre-defined log level and pre-defined trace status.
Expand All @@ -152,7 +154,7 @@
* (DLT_TRACE_STATUS_DEFAULT is not allowed here)
*/
#define DLT_REGISTER_CONTEXT_LL_TS(CONTEXT, CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS) do { \
(void)dlt_register_context_ll_ts(&(CONTEXT), CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS); } while (0)
(void)dlt_register_context_ll_ts(&(CONTEXT), CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS); } while (false)

/**
* Register context (with default log level and default trace status and log level change callback)
Expand All @@ -162,14 +164,14 @@
* @param CBK log level change callback to be registered
*/
#define DLT_REGISTER_CONTEXT_LLCCB(CONTEXT, CONTEXTID, DESCRIPTION, CBK) do { \
(void)dlt_register_context_llccb(&(CONTEXT), CONTEXTID, DESCRIPTION, CBK); } while (0)
(void)dlt_register_context_llccb(&(CONTEXT), CONTEXTID, DESCRIPTION, CBK); } while(false)

/**
* Unregister context.
* @param CONTEXT object containing information about one special logging context
*/
#define DLT_UNREGISTER_CONTEXT(CONTEXT) do { \
(void)dlt_unregister_context(&(CONTEXT)); } while (0)
(void)dlt_unregister_context(&(CONTEXT)); } while(false)

/**
* Register callback function called when injection message was received
Expand All @@ -178,7 +180,7 @@
* @param CALLBACK function pointer to callback function
*/
#define DLT_REGISTER_INJECTION_CALLBACK(CONTEXT, SERVICEID, CALLBACK) do { \
(void)dlt_register_injection_callback(&(CONTEXT), SERVICEID, CALLBACK); } while (0)
(void)dlt_register_injection_callback(&(CONTEXT), SERVICEID, CALLBACK); } while(false)

/**
* Register callback function called when injection message was received
Expand All @@ -188,15 +190,15 @@
* @param PRIV_DATA data specific to context
*/
#define DLT_REGISTER_INJECTION_CALLBACK_WITH_ID(CONTEXT, SERVICEID, CALLBACK, PRIV_DATA) do { \
(void)dlt_register_injection_callback_with_id(&(CONTEXT), SERVICEID, CALLBACK, PRIV_DATA); } while (0)
(void)dlt_register_injection_callback_with_id(&(CONTEXT), SERVICEID, CALLBACK, PRIV_DATA); } while(false)

/**
* Register callback function called when log level of context was changed
* @param CONTEXT object containing information about one special logging context
* @param CALLBACK function pointer to callback function
*/
#define DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(CONTEXT, CALLBACK) do { \
(void)dlt_register_log_level_changed_callback(&(CONTEXT), CALLBACK); } while (0)
(void)dlt_register_log_level_changed_callback(&(CONTEXT), CALLBACK); } while(false)

/**
* Send log message with variable list of messages (intended for verbose mode)
Expand All @@ -221,7 +223,7 @@
__VA_ARGS__; \
(void)dlt_user_log_write_finish(&log_local); \
} \
} while (0)
} while (false)
#endif

/**
Expand Down Expand Up @@ -250,7 +252,7 @@
log_local.user_timestamp = (uint32_t) TS; \
(void)dlt_user_log_write_finish(&log_local); \
} \
} while (0)
} while (false)
#endif

/**
Expand Down Expand Up @@ -279,7 +281,7 @@
__VA_ARGS__; \
(void)dlt_user_log_write_finish(&log_local); \
} \
} while (0)
} while(false)
#endif

/**
Expand Down Expand Up @@ -311,7 +313,7 @@
log_local.user_timestamp = (uint32_t) TS; \
(void)dlt_user_log_write_finish(&log_local); \
} \
} while (0)
} while(false)
#endif

/**
Expand Down Expand Up @@ -643,7 +645,7 @@
{ \
(void)dlt_user_trace_network(&(CONTEXT), TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD); \
} \
} while (0)
} while(false)

/**
* Trace network message, allow truncation
Expand All @@ -660,7 +662,7 @@
{ \
(void)dlt_user_trace_network_truncated(&(CONTEXT), TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD, 1); \
} \
} while (0)
} while(false)

/**
* Trace network message, segment large messages
Expand All @@ -677,7 +679,7 @@
{ \
(void)dlt_user_trace_network_segmented(&(CONTEXT), TYPE, HEADERLEN, HEADER, PAYLOADLEN, PAYLOAD); \
} \
} while (0)
} while(false)

/**
* Send log message with string parameter.
Expand All @@ -691,7 +693,7 @@
{ \
(void)dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \
} \
} while (0)
} while(false)

/**
* Send log message with string parameter and integer parameter.
Expand All @@ -706,7 +708,7 @@
{ \
(void)dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \
} \
} while (0)
} while(false)

/**
* Send log message with string parameter and unsigned integer parameter.
Expand All @@ -721,7 +723,7 @@
{ \
(void)dlt_log_string_uint(&(CONTEXT), LOGLEVEL, TEXT, UINT_VAR); \
} \
} while (0)
} while(false)

/**
* Send log message with unsigned integer parameter.
Expand All @@ -735,7 +737,7 @@
{ \
(void)dlt_log_uint(&(CONTEXT), LOGLEVEL, UINT_VAR); \
} \
} while (0)
} while(false)

/**
* Send log message with integer parameter.
Expand All @@ -749,7 +751,7 @@
{ \
(void)dlt_log_int(&(CONTEXT), LOGLEVEL, INT_VAR); \
} \
} while (0)
} while(false)

/**
* Send log message with binary memory block.
Expand All @@ -764,29 +766,29 @@
{ \
(void)dlt_log_raw(&(CONTEXT), LOGLEVEL, BUF, LEN); \
} \
} while (0)
} while(false)

/**
* Send log message with marker.
*/
#define DLT_LOG_MARKER() \
do { \
(void)dlt_log_marker(); \
} while (0)
} while(false)

/**
* Switch to verbose mode
*
*/
#define DLT_VERBOSE_MODE() do { \
(void)dlt_verbose_mode(); } while (0)
(void)dlt_verbose_mode(); } while(false)

/**
* Switch to non-verbose mode
*
*/
#define DLT_NONVERBOSE_MODE() do { \
(void)dlt_nonverbose_mode(); } while (0)
(void)dlt_nonverbose_mode(); } while(false)

/**
* Set maximum logged log level and trace status of application
Expand All @@ -795,21 +797,21 @@
* @param TRACESTATUS This is the trace status to be set for the whole application
*/
#define DLT_SET_APPLICATION_LL_TS_LIMIT(LOGLEVEL, TRACESTATUS) do { \
(void)dlt_set_application_ll_ts_limit(LOGLEVEL, TRACESTATUS); } while (0)
(void)dlt_set_application_ll_ts_limit(LOGLEVEL, TRACESTATUS); } while(false)

/**
* Enable local printing of messages
*
*/
#define DLT_ENABLE_LOCAL_PRINT() do { \
(void)dlt_enable_local_print(); } while (0)
(void)dlt_enable_local_print(); } while(false)

/**
* Disable local printing of messages
*
*/
#define DLT_DISABLE_LOCAL_PRINT() do { \
(void)dlt_disable_local_print(); } while (0)
(void)dlt_disable_local_print(); } while(false)

/**
* Check if log level is enabled
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/dlt_daemon_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ extern "C" {
#define DLT_DAEMON_SEM_LOCK() do{\
while ((sem_wait(&dlt_daemon_mutex) == -1) && (errno == EINTR)) \
continue; /* Restart if interrupted */ \
} while(0)
} while(false)

#define DLT_DAEMON_SEM_FREE() { sem_post(&dlt_daemon_mutex); }
extern sem_t dlt_daemon_mutex;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dlt_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
int *p = NULL; \
*p = 0; \
} \
} while (0)
} while (false)
#else /* DLT_FATAL_LOG_RESET_ENABLE */
# define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL)
#endif /* DLT_FATAL_LOG_RESET_ENABLE */
Expand Down

0 comments on commit cfc2c86

Please sign in to comment.