Bug #13546
closedstd steams are closed in Windows app.
Description
We are embedding Ruby VM into a windows app ( msvc2015 CRT ). VM fails to initialize in Init_IO with 'closed stream', when initing stdin, stdout and stderr. Debugging shows that fileno() call for stdin and stderr returns -2 value and it is not and error according to MSDN:
https://msdn.microsoft.com/en-us/en-en/library/zs6wbdhx.aspx
"If stdout or stderr is not associated with an output stream (for example, in a Windows application without a console window), the file descriptor returned is -2. In previous versions, the file descriptor returned was -1. This change allows applications to distinguish this condition from an error."
Applying following patch to rb_io_check_closed seems to resolve the issue:
#ifdef _WIN32 if ((fptr->fd < 0) && (fptr->fd != -2) ) { #else if (fptr->fd < 0) { #endif rb_raise(rb_eIOError, closed_stream); }
Updated by nobu (Nobuyoshi Nakada) over 8 years ago
- Description updated (diff)
- Status changed from Open to Feedback
Do you call ruby_sysinit?
Updated by alex (Alex Epifanov) over 8 years ago
nobu (Nobuyoshi Nakada) wrote:
Do you call
ruby_sysinit?
Our initialization code looks like this:
RUBY_INIT_STACK; ruby_init(); #if defined(WIN32) rb_w32_sysinit(NULL,NULL); #endif
Updated by nobu (Nobuyoshi Nakada) over 8 years ago
- Status changed from Feedback to Rejected
Where do you define WIN32?
Note that the predefined macro is _WIN32.
And the call to rb_w32_sysinit must be before ruby_init, and the arguments must not be NULL.