Fix compilation errors for RMW build on Windows (#248)

* Fix compilation errors for RMW build on Windows

This commit fixes the compilation errors that occur when building
the ROS2 rmw_cyclonedds_cpp module on Windows with the msvc C++
compiler. The error are fixed by adding explicit casts when calling
operations on atomics and a different syntax is used for compound
literals (the c99 syntax is not supported in msvc in C++ mode).

In additionally some warnings related to emtpy array usage
in structs are suppressed for msvc.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Restructured macros for vendor id cast and casts for atomic operations

To improve readability I've restructured the macros that are used
for vendor id casts on msvc in c++ mode and macros for type-casting
arguments in operations on atomics (as suggested in the review of
my previous commit)

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Moved atomic function suffix to macro

Moved the suffix for (msvc) 64 bit atomic functions to the
DDSRT_ATOMIC_OP64 macro

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
This commit is contained in:
dennis-adlink 2019-09-09 14:18:13 +02:00 committed by eboasson
parent 9b9a07a8e5
commit 0c23eea7cb
4 changed files with 87 additions and 65 deletions

View file

@ -19,6 +19,7 @@ typedef struct {
uint8_t id[2];
} nn_vendorid_t;
/* All existing vendor codes have the major part equal to 1 (and this will probably be true for a long, long time) */
#define NN_VENDORID_MINOR_RTI 0x01
#define NN_VENDORID_MINOR_PRISMTECH_OSPL 0x02
@ -38,8 +39,15 @@ typedef struct {
#define NN_VENDORID_MINOR_ECLIPSE 0x10
#define NN_VENDORID_MINOR_PRISMTECH_CLOUD 0x20
#if defined(_WIN32) && defined(__cplusplus)
#define NN_VENDORID(vendor) {{ 0x01, NN_VENDORID_MINOR_##vendor }}
#define NN_VENDORID_UNKNOWN {{ 0x00, 0x00 }}
#else
#define NN_VENDORID(vendor) ((nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_##vendor }})
#define NN_VENDORID_UNKNOWN ((nn_vendorid_t) {{ 0x00, 0x00 }})
#define NN_VENDORID_ECLIPSE ((nn_vendorid_t) {{ 0x01, 0x10 }})
#endif
#define NN_VENDORID_ECLIPSE NN_VENDORID (ECLIPSE)
#if defined (__cplusplus)
extern "C" {
@ -49,32 +57,32 @@ inline bool vendor_equals (nn_vendorid_t a, nn_vendorid_t b) {
return ((a.id[0] << 8) | a.id[1]) == ((b.id[0] << 8) | b.id[1]);
}
inline bool vendor_is_eclipse (nn_vendorid_t vendor) {
return vendor_equals (vendor, NN_VENDORID_ECLIPSE);
return vendor_equals (vendor, NN_VENDORID (ECLIPSE));
}
inline bool vendor_is_rti (nn_vendorid_t vendor) {
return vendor_equals (vendor, (nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_RTI }});
return vendor_equals (vendor, NN_VENDORID (RTI));
}
inline bool vendor_is_opensplice (nn_vendorid_t vendor) {
return vendor_equals (vendor, (nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_PRISMTECH_OSPL }});
return vendor_equals (vendor, NN_VENDORID (PRISMTECH_OSPL));
}
inline bool vendor_is_twinoaks (nn_vendorid_t vendor) {
return vendor_equals (vendor, (nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_TWINOAKS }});
return vendor_equals (vendor, NN_VENDORID (TWINOAKS));
}
inline bool vendor_is_eprosima (nn_vendorid_t vendor) {
return vendor_equals (vendor, (nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_EPROSIMA }});
return vendor_equals (vendor, NN_VENDORID (EPROSIMA));
}
inline bool vendor_is_cloud (nn_vendorid_t vendor) {
return vendor_equals (vendor, (nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_PRISMTECH_CLOUD }});
return vendor_equals (vendor, NN_VENDORID (PRISMTECH_CLOUD));
}
inline bool vendor_is_eclipse_or_opensplice (nn_vendorid_t vendor) {
return vendor_is_eclipse (vendor) | vendor_is_opensplice (vendor);
}
inline bool vendor_is_prismtech (nn_vendorid_t vendor) {
return (vendor_equals (vendor, (nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_PRISMTECH_OSPL }}) ||
vendor_equals (vendor, (nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_PRISMTECH_LITE }}) ||
vendor_equals (vendor, (nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_PRISMTECH_GATEWAY }}) ||
vendor_equals (vendor, (nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_PRISMTECH_JAVA }}) ||
vendor_equals (vendor, (nn_vendorid_t) {{ 0x01, NN_VENDORID_MINOR_PRISMTECH_CLOUD }}));
return (vendor_equals (vendor, NN_VENDORID (PRISMTECH_OSPL)) ||
vendor_equals (vendor, NN_VENDORID (PRISMTECH_LITE)) ||
vendor_equals (vendor, NN_VENDORID (PRISMTECH_GATEWAY)) ||
vendor_equals (vendor, NN_VENDORID (PRISMTECH_JAVA)) ||
vendor_equals (vendor, NN_VENDORID (PRISMTECH_CLOUD)));
}
inline bool vendor_is_eclipse_or_prismtech (nn_vendorid_t vendor) {
return vendor_is_eclipse (vendor) || vendor_is_prismtech (vendor);

View file

@ -13,6 +13,7 @@
#define NN_PROTOCOL_H
#include "dds/ddsrt/endian.h"
#include "dds/ddsrt/misc.h"
#include "dds/ddsi/q_feature_check.h"
#include "dds/ddsi/q_rtps.h"
@ -223,6 +224,7 @@ typedef struct MsgLen {
uint32_t length;
} MsgLen_t;
DDSRT_WARNING_MSVC_OFF(4200)
typedef struct AckNack {
SubmessageHeader_t smhdr;
nn_entityid_t readerId;
@ -231,10 +233,12 @@ typedef struct AckNack {
uint32_t bits[];
/* nn_count_t count; */
} AckNack_t;
DDSRT_WARNING_MSVC_ON(4200)
#define ACKNACK_FLAG_FINAL 0x02u
#define ACKNACK_SIZE(numbits) (offsetof (AckNack_t, bits) + NN_SEQUENCE_NUMBER_SET_BITS_SIZE (numbits) + 4)
#define ACKNACK_SIZE_MAX ACKNACK_SIZE (256u)
DDSRT_WARNING_MSVC_OFF(4200)
typedef struct Gap {
SubmessageHeader_t smhdr;
nn_entityid_t readerId;
@ -243,6 +247,7 @@ typedef struct Gap {
nn_sequence_number_set_header_t gapList;
uint32_t bits[];
} Gap_t;
DDSRT_WARNING_MSVC_ON(4200)
#define GAP_SIZE(numbits) (offsetof (Gap_t, bits) + NN_SEQUENCE_NUMBER_SET_BITS_SIZE (numbits))
#define GAP_SIZE_MAX GAP_SIZE (256u)
@ -272,6 +277,7 @@ typedef struct HeartbeatFrag {
nn_count_t count;
} HeartbeatFrag_t;
DDSRT_WARNING_MSVC_OFF(4200)
typedef struct NackFrag {
SubmessageHeader_t smhdr;
nn_entityid_t readerId;
@ -281,6 +287,7 @@ typedef struct NackFrag {
uint32_t bits[];
/* nn_count_t count; */
} NackFrag_t;
DDSRT_WARNING_MSVC_ON(4200)
#define NACKFRAG_SIZE(numbits) (offsetof (NackFrag_t, bits) + NN_FRAGMENT_NUMBER_SET_BITS_SIZE (numbits) + 4)
#define NACKFRAG_SIZE_MAX NACKFRAG_SIZE (256u)
@ -305,12 +312,14 @@ typedef union Submessage {
PT_InfoContainer_t pt_infocontainer;
} Submessage_t;
DDSRT_WARNING_MSVC_OFF(4200)
typedef struct ParticipantMessageData {
nn_guid_prefix_t participantGuidPrefix;
uint32_t kind; /* really 4 octets */
uint32_t length;
char value[];
} ParticipantMessageData_t;
DDSRT_WARNING_MSVC_ON(4200)
#define PARTICIPANT_MESSAGE_DATA_KIND_UNKNOWN 0x0u
#define PARTICIPANT_MESSAGE_DATA_KIND_AUTOMATIC_LIVELINESS_UPDATE 0x1u
#define PARTICIPANT_MESSAGE_DATA_KIND_MANUAL_LIVELINESS_UPDATE 0x2u