Skip to content

Commit 6a7f040

Browse files
authored
Merge pull request libgit2#5941 from NattyNarwhal/stdintification
stdintification: use int64_t and INT64_C instead of long long
2 parents 36e8030 + d6bea53 commit 6a7f040

File tree

14 files changed

+258
-267
lines changed

14 files changed

+258
-267
lines changed

src/commit_graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static int git_commit_graph_entry_get_byindex(
304304
e->generation = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ + 2 * sizeof(uint32_t))));
305305
e->commit_time = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ + 3 * sizeof(uint32_t))));
306306

307-
e->commit_time |= (e->generation & 0x3ull) << 32ull;
307+
e->commit_time |= (e->generation & UINT64_C(0x3)) << UINT64_C(32);
308308
e->generation >>= 2u;
309309
if (e->parent_indices[1] & 0x80000000u) {
310310
uint32_t extra_edge_list_pos = e->parent_indices[1] & 0x7fffffff;

src/diff_xdiff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/* xdiff cannot cope with large files. these files should not be passed to
1717
* xdiff. callers should treat these large files as binary.
1818
*/
19-
#define GIT_XDIFF_MAX_SIZE (1024LL * 1024 * 1023)
19+
#define GIT_XDIFF_MAX_SIZE (INT64_C(1024) * 1024 * 1023)
2020

2121
/* A git_xdiff_output is a git_patch_generate_output with extra fields
2222
* necessary to use libxdiff. Calling git_xdiff_init() will set the diff_cb

src/hash/sha1/generic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "hash/sha1.h"
1212

1313
struct git_hash_sha1_ctx {
14-
unsigned long long size;
14+
uint64_t size;
1515
unsigned int H[5];
1616
unsigned int W[16];
1717
};

src/hashsig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef uint64_t hashsig_state;
1717
#define HASHSIG_SCALE 100
1818

1919
#define HASHSIG_MAX_RUN 80
20-
#define HASHSIG_HASH_START 0x012345678ABCDEF0LL
20+
#define HASHSIG_HASH_START INT64_C(0x012345678ABCDEF0)
2121
#define HASHSIG_HASH_SHIFT 5
2222

2323
#define HASHSIG_HASH_MIX(S,CH) \

src/integer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ GIT_INLINE(int) git__is_ulong(int64_t p)
4343
}
4444

4545
/** @return true if p fits into the range of an int */
46-
GIT_INLINE(int) git__is_int(long long p)
46+
GIT_INLINE(int) git__is_int(int64_t p)
4747
{
4848
int r = (int)p;
49-
return p == (long long)r;
49+
return p == (int64_t)r;
5050
}
5151

5252
/* Use clang/gcc compiler intrinsics whenever possible */

src/khash.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,8 @@ int main() {
131131

132132
/* compiler specific configuration */
133133

134-
#if UINT_MAX == 0xffffffffu
135-
typedef unsigned int khint32_t;
136-
#elif ULONG_MAX == 0xffffffffu
137-
typedef unsigned long khint32_t;
138-
#endif
139-
140-
#if ULONG_MAX == ULLONG_MAX
141-
typedef unsigned long khint64_t;
142-
#else
143-
typedef unsigned long long khint64_t;
144-
#endif
134+
typedef uint32_t khint32_t;
135+
typedef uint64_t khint64_t;
145136

146137
#ifndef kh_inline
147138
#ifdef _MSC_VER

src/mwindow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
: 32 * 1024 * 1024)
2121

2222
#define DEFAULT_MAPPED_LIMIT \
23-
((1024 * 1024) * (sizeof(void*) >= 8 ? 8192ULL : 256UL))
23+
((1024 * 1024) * (sizeof(void*) >= 8 ? UINT64_C(8192) : UINT64_C(256)))
2424

2525
/* default is unlimited */
2626
#define DEFAULT_FILE_LIMIT 0

src/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
2424
#define bitsizeof(x) (CHAR_BIT * sizeof(x))
25-
#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
25+
#define MSB(x, bits) ((x) & (~UINT64_C(0) << (bitsizeof(x) - (bits))))
2626
#ifndef min
2727
# define min(a,b) ((a) < (b) ? (a) : (b))
2828
#endif

src/win32/w32_util.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ GIT_INLINE(void) git_win32__filetime_to_timespec(
7474
const FILETIME *ft,
7575
struct timespec *ts)
7676
{
77-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
78-
winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */
77+
int64_t winTime = ((int64_t)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
78+
winTime -= INT64_C(116444736000000000); /* Windows to Unix Epoch conversion */
7979
ts->tv_sec = (time_t)(winTime / 10000000);
8080
#ifdef GIT_USE_NSEC
8181
ts->tv_nsec = (winTime % 10000000) * 100;
@@ -87,11 +87,11 @@ GIT_INLINE(void) git_win32__filetime_to_timespec(
8787
GIT_INLINE(void) git_win32__timeval_to_filetime(
8888
FILETIME *ft, const struct p_timeval tv)
8989
{
90-
long long ticks = (tv.tv_sec * 10000000LL) +
91-
(tv.tv_usec * 10LL) + 116444736000000000LL;
90+
int64_t ticks = (tv.tv_sec * INT64_C(10000000)) +
91+
(tv.tv_usec * INT64_C(10)) + INT64_C(116444736000000000);
9292

93-
ft->dwHighDateTime = ((ticks >> 32) & 0xffffffffLL);
94-
ft->dwLowDateTime = (ticks & 0xffffffffLL);
93+
ft->dwHighDateTime = ((ticks >> 32) & INT64_C(0xffffffff));
94+
ft->dwLowDateTime = (ticks & INT64_C(0xffffffff));
9595
}
9696

9797
GIT_INLINE(void) git_win32__stat_init(

tests/core/encoding.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void test_core_encoding__decode(void)
1414
cl_assert(size == 4);
1515

1616
buf = (unsigned char *)"\xaa\xaa\xfe\xdc\xbaXY";
17-
cl_assert(git_decode_varint(buf, &size) == 1489279344088ULL);
17+
cl_assert(git_decode_varint(buf, &size) == UINT64_C(1489279344088));
1818
cl_assert(size == 6);
1919

2020
buf = (unsigned char *)"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xfe\xdc\xbaXY";
@@ -35,8 +35,8 @@ void test_core_encoding__encode(void)
3535
cl_assert(git_encode_varint(buf, 100, 267869656) == 4);
3636
cl_assert(!memcmp(buf, "\xfe\xdc\xbaX", 4));
3737

38-
cl_assert(git_encode_varint(buf, 100, 1489279344088ULL) == 6);
38+
cl_assert(git_encode_varint(buf, 100, UINT64_C(1489279344088)) == 6);
3939
cl_assert(!memcmp(buf, "\xaa\xaa\xfe\xdc\xbaX", 6));
4040

41-
cl_assert(git_encode_varint(buf, 1, 1489279344088ULL) == -1);
41+
cl_assert(git_encode_varint(buf, 1, UINT64_C(1489279344088)) == -1);
4242
}

0 commit comments

Comments
 (0)