• stephanelsmith's avatar
    extmod/vfs_posix_file: Fix flush handling on macOS. · 1c047742
    stephanelsmith authored
    On macOS, if running micropython from subprocess.check_output, then a
    stdout.flush() raises error 45.
    
    Here's a test case.  This will run fine on linux, but crashes on macOS with
    error 45.
    
        import sys
        import subprocess
        import tempfile
        with tempfile.NamedTemporaryFile('w') as fp:
            fp.write('''
        import sys
        sys.stdout.write('hello world')
        sys.stdout.flush()
        print('')
        ''')
            fp.flush()
            print('py3')
            o = subprocess.check_output(f'python3 {fp.name}'.split())
            print(o)
            print('upy')
            o = subprocess.check_output(f'micropython {fp.name}'.split())
            print(o)
    
    On macOS:
    
        py3
        b'hello world\n'
        upy
        Traceback (most recent call last):
          File "...", line 4, in <module>
        OSError: 45
    
    On unix:
    
        py3
        b'hello world\n'
        upy
        b'hello world\n'
    Signed-off-by: default avatarstephanelsmith <stephane.smith@titansensor.com>
    1c047742
vfs_posix_file.c 9.74 KB