Skip to content

Commit a2b6dc2

Browse files
committed
fix: apply antirez/sds#146
Needed to get it to work on MSVC
1 parent f320716 commit a2b6dc2

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/sds/sds.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,48 @@ extern const char *SDS_NOINIT;
4242

4343
typedef char *sds;
4444

45+
#ifdef _MSC_VER
46+
__pragma(pack(push, 1))
47+
#define _SDS_PACKED
48+
#else
49+
#define _SDS_PACKED __attribute__ ((__packed__))
50+
#endif
51+
4552
/* Note: sdshdr5 is never used, we just access the flags byte directly.
4653
* However is here to document the layout of type 5 SDS strings. */
47-
struct __attribute__ ((__packed__)) sdshdr5 {
54+
struct _SDS_PACKED sdshdr5 {
4855
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
4956
char buf[];
5057
};
51-
struct __attribute__ ((__packed__)) sdshdr8 {
58+
struct _SDS_PACKED sdshdr8 {
5259
uint8_t len; /* used */
5360
uint8_t alloc; /* excluding the header and null terminator */
5461
unsigned char flags; /* 3 lsb of type, 5 unused bits */
5562
char buf[];
5663
};
57-
struct __attribute__ ((__packed__)) sdshdr16 {
64+
struct _SDS_PACKED sdshdr16 {
5865
uint16_t len; /* used */
5966
uint16_t alloc; /* excluding the header and null terminator */
6067
unsigned char flags; /* 3 lsb of type, 5 unused bits */
6168
char buf[];
6269
};
63-
struct __attribute__ ((__packed__)) sdshdr32 {
70+
struct _SDS_PACKED sdshdr32 {
6471
uint32_t len; /* used */
6572
uint32_t alloc; /* excluding the header and null terminator */
6673
unsigned char flags; /* 3 lsb of type, 5 unused bits */
6774
char buf[];
6875
};
69-
struct __attribute__ ((__packed__)) sdshdr64 {
76+
struct _SDS_PACKED sdshdr64 {
7077
uint64_t len; /* used */
7178
uint64_t alloc; /* excluding the header and null terminator */
7279
unsigned char flags; /* 3 lsb of type, 5 unused bits */
7380
char buf[];
7481
};
7582

83+
#ifdef _MSC_VER
84+
__pragma(pack(pop))
85+
#endif
86+
7687
#define SDS_TYPE_5 0
7788
#define SDS_TYPE_8 1
7889
#define SDS_TYPE_16 2

0 commit comments

Comments
 (0)