Skip to content

Commit

Permalink
Merge pull request #1371 from jphickey/fix-1365-cpp-compat
Browse files Browse the repository at this point in the history
Fix #1365, fixup API headers for C++
  • Loading branch information
dzbaker committed Mar 2, 2023
2 parents a9939e6 + 68599dd commit a776f69
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
18 changes: 12 additions & 6 deletions src/os/inc/osapi-clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ static inline int64 OS_TimeGetTotalSeconds(OS_time_t tm)
*/
static inline OS_time_t OS_TimeFromTotalSeconds(int64 tm)
{
return (OS_time_t) {.ticks = (tm * OS_TIME_TICKS_PER_SECOND)};
OS_time_t ostm = {tm * OS_TIME_TICKS_PER_SECOND};
return ostm;
}

/*-------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -180,7 +181,8 @@ static inline int64 OS_TimeGetTotalMilliseconds(OS_time_t tm)
*/
static inline OS_time_t OS_TimeFromTotalMilliseconds(int64 tm)
{
return (OS_time_t) {.ticks = (tm * OS_TIME_TICKS_PER_MSEC)};
OS_time_t ostm = {tm * OS_TIME_TICKS_PER_MSEC};
return ostm;
}

/*-------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -213,7 +215,8 @@ static inline int64 OS_TimeGetTotalMicroseconds(OS_time_t tm)
*/
static inline OS_time_t OS_TimeFromTotalMicroseconds(int64 tm)
{
return (OS_time_t) {.ticks = (tm * OS_TIME_TICKS_PER_USEC)};
OS_time_t ostm = {tm * OS_TIME_TICKS_PER_USEC};
return ostm;
}

/*-------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -250,7 +253,8 @@ static inline int64 OS_TimeGetTotalNanoseconds(OS_time_t tm)
*/
static inline OS_time_t OS_TimeFromTotalNanoseconds(int64 tm)
{
return (OS_time_t) {.ticks = (tm / OS_TIME_TICK_RESOLUTION_NS)};
OS_time_t ostm = {tm / OS_TIME_TICK_RESOLUTION_NS};
return ostm;
}

/*-------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -462,7 +466,8 @@ static inline OS_time_t OS_TimeAssembleFromSubseconds(int64 seconds, uint32 subs
*/
static inline OS_time_t OS_TimeAdd(OS_time_t time1, OS_time_t time2)
{
return ((OS_time_t) {time1.ticks + time2.ticks});
OS_time_t ostm = {time1.ticks + time2.ticks};
return ostm;
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -476,7 +481,8 @@ static inline OS_time_t OS_TimeAdd(OS_time_t time1, OS_time_t time2)
*/
static inline OS_time_t OS_TimeSubtract(OS_time_t time1, OS_time_t time2)
{
return ((OS_time_t) {time1.ticks - time2.ticks});
OS_time_t ostm = {time1.ticks - time2.ticks};
return ostm;
}

/**@}*/
Expand Down
2 changes: 1 addition & 1 deletion src/os/inc/osapi-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ typedef enum
{
OS_FILE_FLAG_NONE = 0x00,
OS_FILE_FLAG_CREATE = 0x01,
OS_FILE_FLAG_TRUNCATE = 0x02,
OS_FILE_FLAG_TRUNCATE = 0x02
} OS_file_flag_t;

/*
Expand Down
6 changes: 4 additions & 2 deletions src/os/inc/osapi-idmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ static inline unsigned long OS_ObjectIdToInteger(osal_id_t object_id)
static inline osal_id_t OS_ObjectIdFromInteger(unsigned long value)
{
#ifdef OSAL_OMIT_DEPRECATED
return (osal_id_t) {value};
osal_id_t idv = {(uint32)value};
#else
return (osal_id_t)value;
osal_id_t idv = (osal_id_t)value;
#endif

return idv;
}

/*-------------------------------------------------------------------------------------*/
Expand Down
11 changes: 11 additions & 0 deletions src/os/inc/osapi-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
#include "osconfig.h"
#include "common_types.h"

/*
* C++ does not support variadic macros until C++11
* These macros should only be used from C code, not headers
* or inline functions. This ifdef prevents the C++ compiler
* from throwing an error about these definitions - as a result
* these macros are NOT available in C++ source files.
*/
#ifndef __cplusplus

#ifdef OSAL_CONFIG_BUGCHECK_DISABLE

/**
Expand Down Expand Up @@ -145,4 +154,6 @@
*/
#define BUGCHECK_VOID(cond) BUGCHECK(cond, )

#endif /* __cplusplus */

#endif /* OSAPI_MACROS_H */
2 changes: 1 addition & 1 deletion src/os/inc/osapi-select.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ typedef enum
OS_STREAM_STATE_BOUND = 0x01, /**< @brief whether the stream is bound */
OS_STREAM_STATE_CONNECTED = 0x02, /**< @brief whether the stream is connected */
OS_STREAM_STATE_READABLE = 0x04, /**< @brief whether the stream is readable */
OS_STREAM_STATE_WRITABLE = 0x08, /**< @brief whether the stream is writable */
OS_STREAM_STATE_WRITABLE = 0x08 /**< @brief whether the stream is writable */
} OS_StreamState_t;

/** @defgroup OSAPISelect OSAL Select APIs
Expand Down

0 comments on commit a776f69

Please sign in to comment.