Skip to content

Commit fcff466

Browse files
pfalcondpgeorge
authored andcommitted
unix: Allow -X heapsize= option take numbers with K & M suffixes.
For kilobytes and megabytes respectively.
1 parent 8204db6 commit fcff466

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

unix/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,14 @@ void pre_process_options(int argc, char **argv) {
269269
emit_opt = MP_EMIT_OPT_VIPER;
270270
#if MICROPY_ENABLE_GC
271271
} else if (strncmp(argv[a + 1], "heapsize=", sizeof("heapsize=") - 1) == 0) {
272-
heap_size = strtol(argv[a + 1] + sizeof("heapsize=") - 1, NULL, 0);
272+
char *end;
273+
heap_size = strtol(argv[a + 1] + sizeof("heapsize=") - 1, &end, 0);
274+
// Don't bring unneeded libc dependencies like tolower()
275+
if ((*end | 0x20) == 'k') {
276+
heap_size *= 1024;
277+
} else if ((*end | 0x20) == 'm') {
278+
heap_size *= 1024 * 1024;
279+
}
273280
#endif
274281
} else {
275282
exit(usage(argv));

0 commit comments

Comments
 (0)