Skip to content

Commit 98d8d59

Browse files
pfalcondpgeorge
authored andcommitted
unix: Allow -X heapsize number take 'w' specifier for word size adjustment.
The specifier should go after the number, before size suffix like 'k' or 'm'. E.g.: "-X heapsize=100wk" will use 100K heap on 32-bit system and 200K - on 64-bit.
1 parent 7860c2a commit 98d8d59

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

unix/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,24 @@ void pre_process_options(int argc, char **argv) {
314314
char *end;
315315
heap_size = strtol(argv[a + 1] + sizeof("heapsize=") - 1, &end, 0);
316316
// Don't bring unneeded libc dependencies like tolower()
317+
// If there's 'w' immediately after number, adjust it for
318+
// target word size. Note that it should be *before* size
319+
// suffix like K or M, to avoid confusion with kilowords,
320+
// etc. the size is still in bytes, just can be adjusted
321+
// for word size (taking 32bit as baseline).
322+
bool word_adjust = false;
323+
if ((*end | 0x20) == 'w') {
324+
word_adjust = true;
325+
end++;
326+
}
317327
if ((*end | 0x20) == 'k') {
318328
heap_size *= 1024;
319329
} else if ((*end | 0x20) == 'm') {
320330
heap_size *= 1024 * 1024;
321331
}
332+
if (word_adjust) {
333+
heap_size = heap_size * BYTES_PER_WORD / 4;
334+
}
322335
#endif
323336
} else {
324337
exit(usage(argv));

0 commit comments

Comments
 (0)