File tree Expand file tree Collapse file tree 3 files changed +20
-7
lines changed
Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -1899,11 +1899,17 @@ def default_setting(name, new_default):
18991899 ]
19001900
19011901 if settings .FILESYSTEM and not settings .STANDALONE_WASM :
1902- # to flush streams on FS exit, we need to be able to call fflush
1903- # we only include it if the runtime is exitable, or when ASSERTIONS
1902+ # To flush streams on FS exit, we need to be able to call __stdio_exit,
1903+ # this is a streamlined fflush variant that avoids performing any unnecessary
1904+ # operations and which never unlocks the files or open file list, so we can
1905+ # be sure no other threads write new data to a stream's buffer after it's
1906+ # already flushed. This function is only included if the runtime is exitable.
1907+ if settings .EXIT_RUNTIME :
1908+ settings .EXPORTED_FUNCTIONS += ['___stdio_exit' ]
1909+ # Include the fflush function when ASSERTIONS is enabled.
19041910 # (ASSERTIONS will check that streams do not need to be flushed,
19051911 # helping people see when they should have enabled EXIT_RUNTIME)
1906- if settings .EXIT_RUNTIME or settings . ASSERTIONS :
1912+ if settings .ASSERTIONS :
19071913 settings .EXPORTED_FUNCTIONS += ['_fflush' ]
19081914
19091915 if settings .SUPPORT_ERRNO :
Original file line number Diff line number Diff line change @@ -1514,9 +1514,10 @@ FS.staticInit();` +
15141514 } ,
15151515 quit : function ( ) {
15161516 FS . init . initialized = false ;
1517- // force-flush all streams, so we get musl std streams printed out
1518- var fflush = Module [ '_fflush' ] ;
1519- if ( fflush ) fflush ( 0 ) ;
1517+ // ensure the musl std streams are printed out by
1518+ // calling the streamlined fflush variant
1519+ var stdio_exit = Module [ '___stdio_exit' ] ;
1520+ if ( stdio_exit ) stdio_exit ( ) ;
15201521 // close all of our streams
15211522 for ( var i = 0 ; i < FS . streams . length ; i ++ ) {
15221523 var stream = FS . streams [ i ] ;
Original file line number Diff line number Diff line change @@ -182,8 +182,14 @@ var WasiLibrary = {
182182
183183#if SYSCALLS_REQUIRE_FILESYSTEM == 0 && ( ! MINIMAL_RUNTIME || EXIT_RUNTIME )
184184 $flush_NO_FILESYSTEM: function ( ) {
185- // flush anything remaining in the buffers during shutdown
185+ // flush anything remaining in the buffers during shutdown.
186+ // Only call the streamlined fflush variant when ASSERTIONS are disabled
187+ // to ensure that the warning for unflushed content is still displayed.
188+ #if ASSERTIONS
186189 if ( typeof _fflush !== 'undefined' ) _fflush ( { { { pointerT( 0 ) } } } ) ;
190+ #else
191+ if ( typeof ___stdio_exit !== 'undefined' ) ___stdio_exit ( ) ;
192+ #endif
187193 var buffers = SYSCALLS . buffers ;
188194 if ( buffers [ 1 ] . length ) SYSCALLS . printChar ( 1 , { { { charCode ( "\n" ) } } } ) ;
189195 if ( buffers [ 2 ] . length ) SYSCALLS . printChar ( 2 , { { { charCode ( "\n" ) } } } ) ;
You can’t perform that action at this time.
0 commit comments