Skip to content

Commit bb1d55a

Browse files
committed
Simplified the pack macros in Portability.h
Removed NANOLOG_PACK_ATTR and changed the NANOLOG_PACK_PUSH/POP macros to define _Pragma's for GCC. This unifies the structure between the MSC and GCC macros and simplifies usage across the code base.
1 parent b45c104 commit bb1d55a

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

runtime/Log.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016-2018 Stanford University
1+
/* Copyright (c) 2016-2020 Stanford University
22
*
33
* Permission to use, copy, modify, and distribute this software for any
44
* purpose with or without fee is hereby granted, provided that the above
@@ -226,7 +226,7 @@ namespace Log {
226226
struct UnknownHeader {
227227
uint8_t entryType:2;
228228
uint8_t other:6;
229-
} NANOLOG_PACK_ATTR;
229+
};
230230
NANOLOG_PACK_POP
231231

232232
static_assert(sizeof(UnknownHeader) == 1, "Unknown Header should have a"
@@ -256,7 +256,7 @@ namespace Log {
256256

257257
// Value returned by pack(timestamp)
258258
uint8_t additionalTimestampBytes:4;
259-
} NANOLOG_PACK_ATTR;
259+
};
260260
NANOLOG_PACK_POP
261261

262262
/**
@@ -295,7 +295,7 @@ namespace Log {
295295
static constexpr uint32_t maxSizeOfHeader() {
296296
return sizeof(BufferExtent) + sizeof(uint32_t);
297297
}
298-
} NANOLOG_PACK_ATTR;
298+
};
299299
NANOLOG_PACK_POP
300300

301301
/**
@@ -330,7 +330,7 @@ namespace Log {
330330
// in the log file.
331331
uint32_t totalMetadataEntries;
332332

333-
} NANOLOG_PACK_ATTR;
333+
};
334334
NANOLOG_PACK_POP
335335

336336
/**
@@ -351,7 +351,7 @@ namespace Log {
351351
// Total number of FormatMetadata encountered so far in the log
352352
// including this fragment (used as a sanity check only).
353353
uint32_t totalMetadataEntries;
354-
} NANOLOG_PACK_ATTR;
354+
};
355355
NANOLOG_PACK_POP
356356

357357
/**
@@ -373,7 +373,7 @@ namespace Log {
373373
// Length of the format string that is associated with this log
374374
// invocation and comes after filename.
375375
uint16_t formatStringLength;
376-
} NANOLOG_PACK_ATTR;
376+
};
377377
NANOLOG_PACK_POP
378378

379379
/**
@@ -401,7 +401,7 @@ namespace Log {
401401

402402
// Filename for the original source file containing the LOG statement
403403
char filename[];
404-
} NANOLOG_PACK_ATTR;
404+
};
405405
NANOLOG_PACK_POP
406406

407407
/**
@@ -426,7 +426,7 @@ namespace Log {
426426
// A fragment of the original LOG statement that contains at most
427427
// one format specifier.
428428
char formatFragment[];
429-
} NANOLOG_PACK_ATTR;
429+
};
430430
NANOLOG_PACK_POP
431431

432432

runtime/Packer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016-2018 Stanford University
1+
/* Copyright (c) 2016-2020 Stanford University
22
*
33
* Permission to use, copy, modify, and distribute this software for any
44
* purpose with or without fee is hereby granted, provided that the above
@@ -76,7 +76,7 @@ NANOLOG_PACK_PUSH
7676
struct TwoNibbles {
7777
uint8_t first:4;
7878
uint8_t second:4;
79-
} NANOLOG_PACK_ATTR;
79+
};
8080
NANOLOG_PACK_POP
8181

8282
/**
@@ -285,7 +285,7 @@ unpack(const char **in, uint8_t packNibble) {
285285
int bytes = packNibble == 0 ? 16 : packNibble;
286286
std::memcpy(&result, (*in), bytes);
287287
(*in) += bytes;
288-
288+
289289
return result;
290290
}
291291

runtime/Portability.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818
#endif
1919

2020
#ifdef _MSC_VER
21-
#define NANOLOG_PACK_ATTR
2221
#define NANOLOG_PACK_PUSH __pragma(pack(push, 1))
2322
#define NANOLOG_PACK_POP __pragma(pack(pop))
2423
#elif defined(__GNUC__)
25-
#define NANOLOG_PACK_ATTR __attribute__((__packed__))
26-
#define NANOLOG_PACK_PUSH
27-
#define NANOLOG_PACK_POP
24+
#define NANOLOG_PACK_PUSH _Pragma("pack(push, 1)")
25+
#define NANOLOG_PACK_POP _Pragma("pack(pop)")
2826
#else
29-
#define NANOLOG_PACK_ATTR
3027
#define NANOLOG_PACK_PUSH
3128
#define NANOLOG_PACK_POP
3229
#endif

0 commit comments

Comments
 (0)