ruby-changes:38297
From: naruse <ko1@a...>
Date: Fri, 24 Apr 2015 07:58:28 +0900 (JST)
Subject: [ruby-changes:38297] naruse:r50378 (trunk): * win32/win32.c (_filbuf): msvc14 doesn't have it, use _fgetc_nolock.
naruse 2015-04-24 07:58:11 +0900 (Fri, 24 Apr 2015) New Revision: 50378 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50378 Log: * win32/win32.c (_filbuf): msvc14 doesn't have it, use _fgetc_nolock. * win32/win32.c (_flsbuf): msvc14 doesn't have it, use _fputc_nolock. * win32/win32.c (vcruntime_file): define vcruntime_file on msvc14 because it doesn't export FILE's internal structure. * win32/win32.c (FILE_COUNT): added to abstract FILE->_cnt. * win32/win32.c (FILE_READPTR): added to abstract FILE->_ptr. * win32/win32.c (FILE_FILENO): added to abstract FILE->_file. * win32/win32.c (init_stdhandle): use FILE_FILENO. * win32/win32.c (rb_w32_getc): use FILE_COUNT and FILE_READPTR. * win32/win32.c (rb_w32_putc): ditto. Modified files: trunk/ChangeLog trunk/win32/win32.c Index: ChangeLog =================================================================== --- ChangeLog (revision 50377) +++ ChangeLog (revision 50378) @@ -1,3 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Apr 24 06:47:19 2015 NARUSE, Yui <naruse@r...> + + * win32/win32.c (_filbuf): msvc14 doesn't have it, use _fgetc_nolock. + + * win32/win32.c (_flsbuf): msvc14 doesn't have it, use _fputc_nolock. + + * win32/win32.c (vcruntime_file): define vcruntime_file on msvc14 + because it doesn't export FILE's internal structure. + + * win32/win32.c (FILE_COUNT): added to abstract FILE->_cnt. + + * win32/win32.c (FILE_READPTR): added to abstract FILE->_ptr. + + * win32/win32.c (FILE_FILENO): added to abstract FILE->_file. + + * win32/win32.c (init_stdhandle): use FILE_FILENO. + + * win32/win32.c (rb_w32_getc): use FILE_COUNT and FILE_READPTR. + + * win32/win32.c (rb_w32_putc): ditto. + Fri Apr 24 06:37:07 2015 NARUSE, Yui <naruse@r...> * win32/win32.c (dupfd): use _set_osfhnd. Index: win32/win32.c =================================================================== --- win32/win32.c (revision 50377) +++ win32/win32.c (revision 50378) @@ -95,6 +95,10 @@ static char *w32_getenv(const char *name https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L95 # define enough_to_get(n) (--(n) >= 0) # define enough_to_put(n) (++(n) < 0) #else +# if RUBY_MSVCRT_VERSION >= 140 +# define _filbuf _fgetc_nolock +# define _flsbuf _fputc_nolock +# endif # define enough_to_get(n) (--(n) >= 0) # define enough_to_put(n) (--(n) >= 0) #endif @@ -2255,6 +2259,32 @@ rb_w32_closedir(DIR *dirp) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2259 # define STHREAD_ONLY(x) x #endif +#if RUBY_MSVCRT_VERSION >= 140 +typedef struct { + union + { + FILE _public_file; + char* _ptr; + }; + + char* _base; + int _cnt; + long _flags; + long _file; + int _charbuf; + int _bufsiz; + char* _tmpfname; + CRITICAL_SECTION _lock; +} vcruntime_file; +#define FILE_COUNT(stream) ((vcruntime_file*)stream)->_cnt +#define FILE_READPTR(stream) ((vcruntime_file*)stream)->_ptr +#define FILE_FILENO(stream) ((vcruntime_file*)stream)->_file +#else +#define FILE_COUNT(stream) stream->_cnt +#define FILE_READPTR(stream) stream->_ptr +#define FILE_FILENO(stream) stream->_file +#endif + /* License: Ruby's */ typedef struct { intptr_t osfhnd; /* underlying OS file HANDLE */ @@ -2395,16 +2425,16 @@ init_stdhandle(void) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2425 (fd)) if (fileno(stdin) < 0) { - stdin->_file = open_null(0); + FILE_FILENO(stdin) = open_null(0); } else { setmode(fileno(stdin), O_BINARY); } if (fileno(stdout) < 0) { - stdout->_file = open_null(1); + FILE_FILENO(stdout) = open_null(1); } if (fileno(stderr) < 0) { - stderr->_file = open_null(2); + FILE_FILENO(stderr) = open_null(2); } if (nullfd >= 0 && !keep) close(nullfd); setvbuf(stderr, NULL, _IONBF, 0); @@ -5629,18 +5659,14 @@ read(int fd, void *buf, size_t size) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5659 } #endif - -#define FILE_COUNT _cnt -#define FILE_READPTR _ptr - #undef fgetc /* License: Ruby's */ int rb_w32_getc(FILE* stream) { int c; - if (enough_to_get(stream->FILE_COUNT)) { - c = (unsigned char)*stream->FILE_READPTR++; + if (enough_to_get(FILE_COUNT(stream))) { + c = (unsigned char)*FILE_READPTR(stream)++; } else { c = _filbuf(stream); @@ -5659,8 +5685,8 @@ rb_w32_getc(FILE* stream) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5685 int rb_w32_putc(int c, FILE* stream) { - if (enough_to_put(stream->FILE_COUNT)) { - c = (unsigned char)(*stream->FILE_READPTR++ = (char)c); + if (enough_to_put(FILE_COUNT(stream))) { + c = (unsigned char)(*FILE_READPTR(stream)++ = (char)c); } else { c = _flsbuf(c, stream); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/