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):
1899
1899
]
1900
1900
1901
1901
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.
1904
1910
# (ASSERTIONS will check that streams do not need to be flushed,
1905
1911
# helping people see when they should have enabled EXIT_RUNTIME)
1906
- if settings .EXIT_RUNTIME or settings . ASSERTIONS :
1912
+ if settings .ASSERTIONS :
1907
1913
settings .EXPORTED_FUNCTIONS += ['_fflush' ]
1908
1914
1909
1915
if settings .SUPPORT_ERRNO :
Original file line number Diff line number Diff line change @@ -1514,9 +1514,10 @@ FS.staticInit();` +
1514
1514
} ,
1515
1515
quit : function ( ) {
1516
1516
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 ( ) ;
1520
1521
// close all of our streams
1521
1522
for ( var i = 0 ; i < FS . streams . length ; i ++ ) {
1522
1523
var stream = FS . streams [ i ] ;
Original file line number Diff line number Diff line change @@ -182,8 +182,14 @@ var WasiLibrary = {
182
182
183
183
#if SYSCALLS_REQUIRE_FILESYSTEM == 0 && ( ! MINIMAL_RUNTIME || EXIT_RUNTIME )
184
184
$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
186
189
if ( typeof _fflush !== 'undefined' ) _fflush ( { { { pointerT( 0 ) } } } ) ;
190
+ #else
191
+ if ( typeof ___stdio_exit !== 'undefined' ) ___stdio_exit ( ) ;
192
+ #endif
187
193
var buffers = SYSCALLS . buffers ;
188
194
if ( buffers [ 1 ] . length ) SYSCALLS . printChar ( 1 , { { { charCode ( "\n" ) } } } ) ;
189
195
if ( buffers [ 2 ] . length ) SYSCALLS . printChar ( 2 , { { { charCode ( "\n" ) } } } ) ;
You can’t perform that action at this time.
0 commit comments