Skip to content

Commit a05f5dd

Browse files
committed
Merge branch 'master' of github.com:micropython/micropython
2 parents e90eefc + ad1bac6 commit a05f5dd

3 files changed

Lines changed: 34 additions & 12 deletions

File tree

py/gc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <string.h>
33

44
#include "mpconfig.h"
5+
#include "misc.h"
56
#include "gc.h"
67

78
#if MICROPY_ENABLE_GC

tests/basics/string-format.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def test(fmt, *args):
5858
test("{:10.4f}", -123.456)
5959
test("{:10.4g}", 123.456)
6060
test("{:10.4g}", -123.456)
61+
test("{:e}", 100)
62+
test("{:f}", 200)
63+
test("{:g}", 300)
6164

6265
test("{:10.4E}", 123.456)
6366
test("{:10.4E}", -123.456)

unix/main.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdarg.h>
77
#include <sys/stat.h>
88
#include <sys/types.h>
9+
#include <errno.h>
910

1011
#include "nlr.h"
1112
#include "misc.h"
@@ -212,13 +213,24 @@ mp_obj_t test_obj_new(int value) {
212213
return o;
213214
}
214215

215-
int usage(void) {
216+
int usage(char **argv) {
216217
printf(
217-
"usage: py [-X <opt>] [-c <command>] [<filename>]\n"
218+
"usage: %s [-X <opt>] [-c <command>] [<filename>]\n"
218219
"\n"
219-
"Implementation specific options:\n"
220+
"Implementation specific options:\n", argv[0]
221+
);
222+
int impl_opts_cnt = 0;
223+
#if MICROPY_ENABLE_GC
224+
printf(
220225
" heapsize=<n> -- set the heap size for the GC\n"
221226
);
227+
impl_opts_cnt++;
228+
#endif
229+
230+
if (impl_opts_cnt == 0) {
231+
printf(" (none)\n");
232+
}
233+
222234
return 1;
223235
}
224236

@@ -249,15 +261,15 @@ void pre_process_options(int argc, char **argv) {
249261
if (argv[a][0] == '-') {
250262
if (strcmp(argv[a], "-X") == 0) {
251263
if (a + 1 >= argc) {
252-
exit(usage());
264+
exit(usage(argv));
253265
}
254266
if (0) {
255267
#if MICROPY_ENABLE_GC
256268
} else if (strncmp(argv[a + 1], "heapsize=", sizeof("heapsize=") - 1) == 0) {
257269
heap_size = strtol(argv[a + 1] + sizeof("heapsize=") - 1, NULL, 0);
258270
#endif
259271
} else {
260-
exit(usage());
272+
exit(usage(argv));
261273
}
262274
a++;
263275
}
@@ -358,24 +370,30 @@ int main(int argc, char **argv) {
358370
if (argv[a][0] == '-') {
359371
if (strcmp(argv[a], "-c") == 0) {
360372
if (a + 1 >= argc) {
361-
return usage();
373+
return usage(argv);
362374
}
363375
do_str(argv[a + 1]);
364376
executed = true;
365377
a += 1;
366378
} else if (strcmp(argv[a], "-X") == 0) {
367379
a += 1;
368380
} else {
369-
return usage();
381+
return usage(argv);
370382
}
371383
} else {
372-
// Set base dir of the script as first entry in sys.path
373384
char *basedir = realpath(argv[a], NULL);
374-
if (basedir != NULL) {
375-
char *p = strrchr(basedir, '/');
376-
path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir));
377-
free(basedir);
385+
if (basedir == NULL) {
386+
fprintf(stderr, "%s: can't open file '%s': [Errno %d] ", argv[0], argv[1], errno);
387+
perror("");
388+
// CPython exits with 2 in such case
389+
exit(2);
378390
}
391+
392+
// Set base dir of the script as first entry in sys.path
393+
char *p = strrchr(basedir, '/');
394+
path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir));
395+
free(basedir);
396+
379397
for (int i = a; i < argc; i++) {
380398
mp_obj_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
381399
}

0 commit comments

Comments
 (0)