From 72521a1c176506c044169038b68b83e5329a3dda Mon Sep 17 00:00:00 2001 From: stijn Date: Sat, 3 May 2014 11:28:29 +0200 Subject: [PATCH] mingw: Fix number of exponent digits in floating point formatting By default mingw outputs 3 digits instead of the standard 2 so all float tests using printf fail. Using setenv at the start of the program fixes this. To accomodate calling platform specific initialization a MICROPY_MAIN_INIT_FUNC macro is used which is called in mp_init() --- py/runtime.c | 5 +++++ windows/Makefile | 1 + windows/init.c | 5 +++++ windows/init.h | 1 + windows/mpconfigport.h | 2 ++ 5 files changed, 14 insertions(+) create mode 100644 windows/init.c create mode 100644 windows/init.h diff --git a/py/runtime.c b/py/runtime.c index 2928de8a7..ba78ec40f 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -42,6 +42,11 @@ const mp_obj_module_t mp_module___main__ = { }; void mp_init(void) { + // call port specific initialization if any +#ifdef MICROPY_PORT_INIT_FUNC + MICROPY_PORT_INIT_FUNC; +#endif + mp_emit_glue_init(); // init global module stuff diff --git a/windows/Makefile b/windows/Makefile index 351aad6f1..ce75a6098 100644 --- a/windows/Makefile +++ b/windows/Makefile @@ -31,6 +31,7 @@ SRC_C = \ unix/main.c \ unix/file.c \ realpath.c \ + init.c \ OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) diff --git a/windows/init.c b/windows/init.c new file mode 100644 index 000000000..78b8738f7 --- /dev/null +++ b/windows/init.c @@ -0,0 +1,5 @@ +#include + +void init() { + putenv("PRINTF_EXPONENT_DIGITS=2"); +} diff --git a/windows/init.h b/windows/init.h new file mode 100644 index 000000000..d081a2052 --- /dev/null +++ b/windows/init.h @@ -0,0 +1 @@ +void init(); diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h index d27c59cb3..94b333400 100644 --- a/windows/mpconfigport.h +++ b/windows/mpconfigport.h @@ -15,6 +15,7 @@ #define MICROPY_MOD_SYS_STDFILES (1) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) +#define MICROPY_PORT_INIT_FUNC init() // type definitions for the specific machine @@ -38,3 +39,4 @@ extern const struct _mp_obj_fun_native_t mp_builtin_open_obj; { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, #include "realpath.h" +#include "init.h"