Skip to content

Commit 2e65831

Browse files
committed
add int64 support to toolchain, and fix errors
Add `UINT64_T_ARG` and `INT64_T_ARG` macros for printf arguments, similar to `SIZE_T_ARG` and `PTRDIFF_T_ARG`. In the process, fix some issues with the toolchain: in certain CI runs the toolchain headers were being #included multiple times, and certain CI runs produced collisions between clang definitions and gcc definitions. Resolve these issues with `#pragma once` and preprocessor guards in the event of both gcc and clang being active. Also remove toolchain.h from sexp_container.cpp since it is already #included via pstypes.h.
1 parent a28b152 commit 2e65831

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

code/globalincs/toolchain/clang.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* include toolchain.h which will pull in the file appropriate to
1717
* the detected toolchain.
1818
*/
19+
#pragma once
1920

2021
#if defined(__clang__)
2122

@@ -63,6 +64,9 @@
6364
#define SIZE_T_ARG "%zu"
6465
#define PTRDIFF_T_ARG "%zd"
6566

67+
#define UINT64_T_ARG "%" PRIu64
68+
#define INT64_T_ARG "%" PRId64
69+
6670
#define likely(x) __builtin_expect((long) !!(x), 1L)
6771
#define unlikely(x) __builtin_expect((long) !!(x), 0L)
6872

code/globalincs/toolchain/doxygen.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* or otherwise commercially exploit the source or things you created based on
66
* the source.
77
*/
8+
#pragma once
89

910
#if defined(DOXYGEN)
1011
/**
@@ -46,6 +47,22 @@
4647
*/
4748
#define PTRDIFF_T_ARG "%zd"
4849

50+
/**
51+
* @brief Format specifier for a @c uint64_t argument
52+
*
53+
* Due to different runtimes using different format specifier for these types
54+
* it's necessary to hide these changes behind a macro.
55+
*/
56+
#define UINT64_T_ARG "%" PRIu64
57+
58+
/**
59+
* @brief Format specifier for an @c int64_t argument
60+
*
61+
* Due to different runtimes using different format specifier for these types
62+
* it's necessary to hide these changes behind a macro.
63+
*/
64+
#define INT64_T_ARG "%" PRId64
65+
4966
/**
5067
* @brief Attribute for forcing a static variable to be instantiated
5168
*

code/globalincs/toolchain/gcc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
* include toolchain.h which will pull in the file appropriate to
1717
* the detected toolchain.
1818
*/
19+
#pragma once
1920

20-
#if defined(__GNUC__)
21+
// per toolchain.h, clang takes precedence over gcc if they are both defined
22+
#if defined(__GNUC__) && !defined(__clang__)
2123

2224
#define SCP_FORMAT_STRING
2325
#define SCP_FORMAT_STRING_ARGS(x,y) __attribute__((format(printf, x, y)))
@@ -62,6 +64,9 @@
6264
#define SIZE_T_ARG "%zu"
6365
#define PTRDIFF_T_ARG "%zd"
6466

67+
#define UINT64_T_ARG "%" PRIu64
68+
#define INT64_T_ARG "%" PRId64
69+
6570
#define likely(x) __builtin_expect((long) !!(x), 1L)
6671
#define unlikely(x) __builtin_expect((long) !!(x), 0L)
6772

code/globalincs/toolchain/mingw.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* include toolchain.h which will pull in the file appropriate to
1717
* the detected toolchain.
1818
*/
19+
#pragma once
1920

2021
#if defined(__MINGW32__)
2122

@@ -59,6 +60,9 @@
5960
#define SIZE_T_ARG "%zu"
6061
#define PTRDIFF_T_ARG "%zd"
6162

63+
#define UINT64_T_ARG "%" PRIu64
64+
#define INT64_T_ARG "%" PRId64
65+
6266
#define likely(x) __builtin_expect((long) !!(x), 1L)
6367
#define unlikely(x) __builtin_expect((long) !!(x), 0L)
6468

code/globalincs/toolchain/msvc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* include toolchain.h which will pull in the file appropriate to
1717
* the detected toolchain.
1818
*/
19+
#pragma once
1920

2021
#if defined(_MSC_VER)
2122

@@ -60,6 +61,9 @@
6061
#define SIZE_T_ARG "%Iu"
6162
#define PTRDIFF_T_ARG "%Id"
6263

64+
#define UINT64_T_ARG "%I64u"
65+
#define INT64_T_ARG "%I64d"
66+
6367
#define likely(x) (x)
6468
#define unlikely(x) (x)
6569

code/parse/sexp_container.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include "gamesequence/gamesequence.h"
1212
#include "globalincs/pstypes.h"
13-
#include "globalincs/toolchain.h"
1413
#include "mission/missiongoals.h"
1514
#include "parse/generic_log.h"
1615
#include "parse/parselo.h"

0 commit comments

Comments
 (0)