summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-02 19:55:26 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-02 19:55:26 +0100
commita05f5dd9528ba16df96d3ece581d5d0b2288b5ec (patch)
tree9e3a64d58929d4e133c250e020648d166e6689fd
parente90eefc84b5d2e844194e8d51937c1801d8768fe (diff)
parentad1bac63f714550bc6e2b0a718ee155288254b7a (diff)
downloadmicropython-a05f5dd9528ba16df96d3ece581d5d0b2288b5ec.tar.gz
micropython-a05f5dd9528ba16df96d3ece581d5d0b2288b5ec.zip
Merge branch 'master' of github.com:micropython/micropython
-rw-r--r--py/gc.c1
-rw-r--r--tests/basics/string-format.py3
-rw-r--r--unix/main.c42
3 files changed, 34 insertions, 12 deletions
diff --git a/py/gc.c b/py/gc.c
index 3a3fdb00a5..c319e9ffbf 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -2,6 +2,7 @@
#include <string.h>
#include "mpconfig.h"
+#include "misc.h"
#include "gc.h"
#if MICROPY_ENABLE_GC
diff --git a/tests/basics/string-format.py b/tests/basics/string-format.py
index 290030a9e3..8049c6f73b 100644
--- a/tests/basics/string-format.py
+++ b/tests/basics/string-format.py
@@ -58,6 +58,9 @@ test("{:10.4f}", 123.456)
test("{:10.4f}", -123.456)
test("{:10.4g}", 123.456)
test("{:10.4g}", -123.456)
+test("{:e}", 100)
+test("{:f}", 200)
+test("{:g}", 300)
test("{:10.4E}", 123.456)
test("{:10.4E}", -123.456)
diff --git a/unix/main.c b/unix/main.c
index 57eaa19976..228c4746a5 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -6,6 +6,7 @@
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <errno.h>
#include "nlr.h"
#include "misc.h"
@@ -212,13 +213,24 @@ mp_obj_t test_obj_new(int value) {
return o;
}
-int usage(void) {
+int usage(char **argv) {
printf(
-"usage: py [-X <opt>] [-c <command>] [<filename>]\n"
+"usage: %s [-X <opt>] [-c <command>] [<filename>]\n"
"\n"
-"Implementation specific options:\n"
+"Implementation specific options:\n", argv[0]
+);
+ int impl_opts_cnt = 0;
+#if MICROPY_ENABLE_GC
+ printf(
" heapsize=<n> -- set the heap size for the GC\n"
);
+ impl_opts_cnt++;
+#endif
+
+ if (impl_opts_cnt == 0) {
+ printf(" (none)\n");
+ }
+
return 1;
}
@@ -249,7 +261,7 @@ void pre_process_options(int argc, char **argv) {
if (argv[a][0] == '-') {
if (strcmp(argv[a], "-X") == 0) {
if (a + 1 >= argc) {
- exit(usage());
+ exit(usage(argv));
}
if (0) {
#if MICROPY_ENABLE_GC
@@ -257,7 +269,7 @@ void pre_process_options(int argc, char **argv) {
heap_size = strtol(argv[a + 1] + sizeof("heapsize=") - 1, NULL, 0);
#endif
} else {
- exit(usage());
+ exit(usage(argv));
}
a++;
}
@@ -358,7 +370,7 @@ int main(int argc, char **argv) {
if (argv[a][0] == '-') {
if (strcmp(argv[a], "-c") == 0) {
if (a + 1 >= argc) {
- return usage();
+ return usage(argv);
}
do_str(argv[a + 1]);
executed = true;
@@ -366,16 +378,22 @@ int main(int argc, char **argv) {
} else if (strcmp(argv[a], "-X") == 0) {
a += 1;
} else {
- return usage();
+ return usage(argv);
}
} else {
- // Set base dir of the script as first entry in sys.path
char *basedir = realpath(argv[a], NULL);
- if (basedir != NULL) {
- char *p = strrchr(basedir, '/');
- path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir));
- free(basedir);
+ if (basedir == NULL) {
+ fprintf(stderr, "%s: can't open file '%s': [Errno %d] ", argv[0], argv[1], errno);
+ perror("");
+ // CPython exits with 2 in such case
+ exit(2);
}
+
+ // Set base dir of the script as first entry in sys.path
+ char *p = strrchr(basedir, '/');
+ path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir));
+ free(basedir);
+
for (int i = a; i < argc; i++) {
mp_obj_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
}