summaryrefslogtreecommitdiffstatshomepage
path: root/unix/main.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-11-05 02:08:38 +0200
committerDamien George <damien.p.george@gmail.com>2014-11-05 22:47:30 +0000
commit98d8d59c33563f7a8306ac86c185dc1a2c43dce9 (patch)
tree17e322dd750c51c610ddee3de548a496006f7803 /unix/main.c
parent7860c2a68acd1ccd28cb4bb87819487fd6966a9e (diff)
downloadmicropython-98d8d59c33563f7a8306ac86c185dc1a2c43dce9.tar.gz
micropython-98d8d59c33563f7a8306ac86c185dc1a2c43dce9.zip
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.
Diffstat (limited to 'unix/main.c')
-rw-r--r--unix/main.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/unix/main.c b/unix/main.c
index 780f159efe..3e8de7902b 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -314,11 +314,24 @@ void pre_process_options(int argc, char **argv) {
char *end;
heap_size = strtol(argv[a + 1] + sizeof("heapsize=") - 1, &end, 0);
// Don't bring unneeded libc dependencies like tolower()
+ // If there's 'w' immediately after number, adjust it for
+ // target word size. Note that it should be *before* size
+ // suffix like K or M, to avoid confusion with kilowords,
+ // etc. the size is still in bytes, just can be adjusted
+ // for word size (taking 32bit as baseline).
+ bool word_adjust = false;
+ if ((*end | 0x20) == 'w') {
+ word_adjust = true;
+ end++;
+ }
if ((*end | 0x20) == 'k') {
heap_size *= 1024;
} else if ((*end | 0x20) == 'm') {
heap_size *= 1024 * 1024;
}
+ if (word_adjust) {
+ heap_size = heap_size * BYTES_PER_WORD / 4;
+ }
#endif
} else {
exit(usage(argv));