From: Charlie Savage <redmine@...>
Date: 2009-02-15T16:24:24+09:00
Subject: [ruby-core:22134] [Bug #1162] Build Assertion Failure with VC+++ - Incorrect flushing of stdout/stderr

Issue #1162 has been updated by Charlie Savage.


Hi Nobu,

The error message is poor, but this is still a bug in ruby.  Let me show you the code:

Starting at Visual Studio 9.0\VC\crt\src\commit.c, line 51:

        if ( !FlushFileBuffers((HANDLE)_get_osfhandle(filedes)) ) {
                retval = GetLastError();
        }
        else {
                retval = 0;     /* return success */
        }

        /* map the OS return code to C errno value and return code */
        if (retval == 0)
                goto good;

        _doserrno = retval;

                }

        errno = EBADF;
        retval = -1;

        _ASSERTE(("Invalid file descriptor. File possibly closed by a different thread",0));

As Microsoft's documentation states (see link above), it is incorrect to pass stdout or stderr to FlushFileBuffers.  Therefore FlushFileBuffers fails and retval is set to 6 via the call to GetLastError.  From http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx:

ERROR_INVALID_HANDLE 6  0x6

So the assertion fails.  Bad error message I agree, but still a bug in Ruby. 

----------------------------------------
http://redmine.ruby-lang.org/issues/show/1162

----------------------------------------
http://redmine.ruby-lang.org