mpy-cross: Use binary file translation mode for creating mpy files on windows

This is a fix for https://github.com/micropython/micropython/issues/2209:
by default a file created using open() uses text translation mode so writing
\n to it will result in the file having \r\n. This is obviously problematic
for binary .mpy files, so provide functions for setting the open mode
and use binary mode in mpy-cross' main().
This commit is contained in:
stijn
2016-07-22 11:54:26 +02:00
committed by Paul Sokolovsky
parent 43473372e6
commit 9bdb82ef6b
4 changed files with 97 additions and 0 deletions

View File

@@ -35,6 +35,9 @@
#include "py/runtime.h"
#include "py/gc.h"
#include "py/stackctrl.h"
#ifdef _WIN32
#include "windows/fmode.h"
#endif
// Command line options, with their defaults
STATIC uint emit_opt = MP_EMIT_OPT_NONE;
@@ -185,6 +188,9 @@ MP_NOINLINE int main_(int argc, char **argv) {
gc_init(heap, heap + heap_size);
mp_init();
#ifdef _WIN32
set_fmode_binary();
#endif
mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_init(mp_sys_argv, 0);