Browse Source

main.c: Switch stderr printing from ANSI C to native POSIX.

pull/1620/head
Paul Sokolovsky 9 years ago
parent
commit
3a6b3d230c
  1. 10
      unix/main.c

10
unix/main.c

@ -61,7 +61,8 @@ long heap_size = 1024*1024 * (sizeof(mp_uint_t) / 4);
STATIC void stderr_print_strn(void *env, const char *str, mp_uint_t len) { STATIC void stderr_print_strn(void *env, const char *str, mp_uint_t len) {
(void)env; (void)env;
fwrite(str, len, 1, stderr); ssize_t dummy = write(STDERR_FILENO, str, len);
(void)dummy;
} }
const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; const mp_print_t mp_stderr_print = {NULL, stderr_print_strn};
@ -84,6 +85,7 @@ STATIC int handle_uncaught_exception(mp_obj_t exc) {
// Report all other exceptions // Report all other exceptions
mp_obj_print_exception(&mp_stderr_print, exc); mp_obj_print_exception(&mp_stderr_print, exc);
mp_printf(&mp_stderr_print, exc);
return 1; return 1;
} }
@ -492,7 +494,7 @@ int main(int argc, char **argv) {
if (mp_obj_is_package(mod)) { if (mp_obj_is_package(mod)) {
// TODO // TODO
fprintf(stderr, "%s: -m for packages not yet implemented\n", argv[0]); mp_printf(&mp_stderr_print, "%s: -m for packages not yet implemented\n", argv[0]);
exit(1); exit(1);
} }
ret = 0; ret = 0;
@ -515,7 +517,7 @@ int main(int argc, char **argv) {
char *pathbuf = malloc(PATH_MAX); char *pathbuf = malloc(PATH_MAX);
char *basedir = realpath(argv[a], pathbuf); char *basedir = realpath(argv[a], pathbuf);
if (basedir == NULL) { if (basedir == NULL) {
fprintf(stderr, "%s: can't open file '%s': [Errno %d] ", argv[0], argv[a], errno); mp_printf(&mp_stderr_print, "%s: can't open file '%s': [Errno %d] ", argv[0], argv[a], errno);
perror(""); perror("");
// CPython exits with 2 in such case // CPython exits with 2 in such case
ret = 2; ret = 2;
@ -577,7 +579,7 @@ uint mp_import_stat(const char *path) {
int DEBUG_printf(const char *fmt, ...) { int DEBUG_printf(const char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
int ret = vfprintf(stderr, fmt, ap); int ret = mp_vprintf(&mp_stderr_print, fmt, ap);
va_end(ap); va_end(ap);
return ret; return ret;
} }

Loading…
Cancel
Save