@@ -61,7 +61,8 @@ long heap_size = 1024*1024 * (sizeof(mp_uint_t) / 4);
6161
6262STATIC void stderr_print_strn (void * env , const char * str , mp_uint_t len ) {
6363 (void )env ;
64- fwrite (str , len , 1 , stderr );
64+ ssize_t dummy = write (STDERR_FILENO , str , len );
65+ (void )dummy ;
6566}
6667
6768const mp_print_t mp_stderr_print = {NULL , stderr_print_strn };
@@ -84,6 +85,7 @@ STATIC int handle_uncaught_exception(mp_obj_t exc) {
8485
8586 // Report all other exceptions
8687 mp_obj_print_exception (& mp_stderr_print , exc );
88+ mp_printf (& mp_stderr_print , exc );
8789 return 1 ;
8890}
8991
@@ -492,7 +494,7 @@ int main(int argc, char **argv) {
492494
493495 if (mp_obj_is_package (mod )) {
494496 // TODO
495- fprintf ( stderr , "%s: -m for packages not yet implemented\n" , argv [0 ]);
497+ mp_printf ( & mp_stderr_print , "%s: -m for packages not yet implemented\n" , argv [0 ]);
496498 exit (1 );
497499 }
498500 ret = 0 ;
@@ -515,7 +517,7 @@ int main(int argc, char **argv) {
515517 char * pathbuf = malloc (PATH_MAX );
516518 char * basedir = realpath (argv [a ], pathbuf );
517519 if (basedir == NULL ) {
518- fprintf ( stderr , "%s: can't open file '%s': [Errno %d] " , argv [0 ], argv [a ], errno );
520+ mp_printf ( & mp_stderr_print , "%s: can't open file '%s': [Errno %d] " , argv [0 ], argv [a ], errno );
519521 perror ("" );
520522 // CPython exits with 2 in such case
521523 ret = 2 ;
@@ -577,7 +579,7 @@ uint mp_import_stat(const char *path) {
577579int DEBUG_printf (const char * fmt , ...) {
578580 va_list ap ;
579581 va_start (ap , fmt );
580- int ret = vfprintf ( stderr , fmt , ap );
582+ int ret = mp_vprintf ( & mp_stderr_print , fmt , ap );
581583 va_end (ap );
582584 return ret ;
583585}
0 commit comments