1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50378 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2015-04-23 22:58:11 +00:00
parent cc622e2ac5
commit 3446537f1a
2 changed files with 58 additions and 11 deletions

View file

@ -1,3 +1,24 @@
Fri Apr 24 06:47:19 2015 NARUSE, Yui <naruse@ruby-lang.org>
* 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@ruby-lang.org>
* win32/win32.c (dupfd): use _set_osfhnd.

View file

@ -95,6 +95,10 @@ static char *w32_getenv(const char *name, UINT cp);
# 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)
# 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)
(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)
}
#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)
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);