Skip to content

Commit baaaee0

Browse files
committed
change memory parameters to signed integers to prevent signed to unsigned comparison
1 parent c8f56c6 commit baaaee0

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/gc.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -681,16 +681,16 @@ static int64_t last_gc_total_bytes = 0;
681681
// max_total_memory is a suggestion. We try very hard to stay
682682
// under this limit, but we will go above it rather than halting.
683683
#ifdef _P64
684-
typedef uint64_t memsize_t;
685-
static const size_t default_collect_interval = 5600 * 1024 * sizeof(void*);
686-
static const size_t max_collect_interval = 1250000000UL;
687-
static size_t total_mem;
684+
typedef int64_t memsize_t;
685+
static const int64_t default_collect_interval = 5600 * 1024 * sizeof(void*);
686+
static const int64_t max_collect_interval = 1250000000UL;
687+
static int64_t total_mem;
688688
// We expose this to the user/ci as jl_gc_set_max_memory
689689
static memsize_t max_total_memory = (memsize_t) 2 * 1024 * 1024 * 1024 * 1024 * 1024;
690690
#else
691-
typedef uint32_t memsize_t;
692-
static const size_t default_collect_interval = 3200 * 1024 * sizeof(void*);
693-
static const size_t max_collect_interval = 500000000UL;
691+
typedef int32_t memsize_t;
692+
static const int32_t default_collect_interval = 3200 * 1024 * sizeof(void*);
693+
static const int32_t max_collect_interval = 500000000UL;
694694
// Work really hard to stay within 2GB
695695
// Alternative is to risk running out of address space
696696
// on 32 bit architectures.
@@ -3948,13 +3948,17 @@ void jl_gc_init(void)
39483948

39493949
JL_DLLEXPORT void jl_gc_set_max_memory(uint64_t max_mem)
39503950
{
3951-
if (max_mem > 0
3952-
&& max_mem < (uint64_t)1 << (sizeof(memsize_t) * 8 - 1)) {
3951+
#ifdef _P64
3952+
const int64_t max_allowed_value = INT64_MAX;
3953+
#else
3954+
const int32_t max_allowed_value = INT32_MAX;
3955+
#endif
3956+
if (max_mem > 0 && max_mem < max_allowed_value) {
39533957
max_total_memory = max_mem;
39543958
}
39553959
}
39563960

3957-
JL_DLLEXPORT uint64_t jl_gc_get_max_memory(void)
3961+
JL_DLLEXPORT int64_t jl_gc_get_max_memory(void)
39583962
{
39593963
return max_total_memory;
39603964
}

src/julia.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ JL_DLLEXPORT void jl_free_stack(void *stkbuf, size_t bufsz);
10041004
JL_DLLEXPORT void jl_gc_use(jl_value_t *a);
10051005
// Set GC memory trigger in bytes for greedy memory collecting
10061006
JL_DLLEXPORT void jl_gc_set_max_memory(uint64_t max_mem);
1007-
JL_DLLEXPORT uint64_t jl_gc_get_max_memory(void);
1007+
JL_DLLEXPORT int64_t jl_gc_get_max_memory(void);
10081008

10091009
JL_DLLEXPORT void jl_clear_malloc_data(void);
10101010

0 commit comments

Comments
 (0)