ruby-changes:42663
From: naruse <ko1@a...>
Date: Sun, 24 Apr 2016 02:49:49 +0900 (JST)
Subject: [ruby-changes:42663] naruse:r54737 (trunk): Support MSVC14 and 15 [Bug #11118]
naruse 2016-04-24 03:46:26 +0900 (Sun, 24 Apr 2016) New Revision: 54737 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54737 Log: Support MSVC14 and 15 [Bug #11118] Search _pioinfo which is not exported after MSVC14. [Bug #12014] [GH-884] Modified files: trunk/win32/mkexports.rb trunk/win32/win32.c Index: win32/win32.c =================================================================== --- win32/win32.c (revision 54736) +++ win32/win32.c (revision 54737) @@ -2317,6 +2317,21 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2317 #endif /* License: Ruby's */ +#if RUBY_MSVCRT_VERSION >= 140 +typedef struct { + CRITICAL_SECTION lock; + intptr_t osfhnd; // underlying OS file HANDLE + __int64 startpos; // File position that matches buffer start + unsigned char osfile; // Attributes of file (e.g., open in text mode?) + char textmode; + char _pipe_lookahead; + + uint8_t unicode : 1; // Was the file opened as unicode? + uint8_t utf8translations : 1; // Buffer contains translations other than CRLF + uint8_t dbcsBufferUsed : 1; // Is the dbcsBuffer in use? + char dbcsBuffer; // Buffer for the lead byte of DBCS when converting from DBCS to Unicode +} ioinfo; +#else typedef struct { intptr_t osfhnd; /* underlying OS file HANDLE */ char osfile; /* attributes of file (e.g., open in text mode?) */ @@ -2328,16 +2343,22 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2343 char pipech2[2]; #endif } ioinfo; +#endif #if !defined _CRTIMP || defined __MINGW32__ #undef _CRTIMP #define _CRTIMP __declspec(dllimport) #endif +#if RUBY_MSVCRT_VERSION >= 140 +static ioinfo ** __pioinfo = NULL; +#define IOINFO_L2E 6 +#else EXTERN_C _CRTIMP ioinfo * __pioinfo[]; +#define IOINFO_L2E 5 +#endif static inline ioinfo* _pioinfo(int); -#define IOINFO_L2E 5 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E) #define _osfhnd(i) (_pioinfo(i)->osfhnd) #define _osfile(i) (_pioinfo(i)->osfile) @@ -2352,6 +2373,39 @@ static size_t pioinfo_extra = 0; /* work https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2373 static void set_pioinfo_extra(void) { +#if RUBY_MSVCRT_VERSION >= 140 + /* get __pioinfo addr with _isatty */ + HMODULE mod = GetModuleHandle("ucrtbase.dll"); + char *p = (char*)GetProcAddress(mod, "_isatty"); + char *pend = p + 100; + /* _osfile(fh) & FDEV /*0x40*/ +#if _WIN64 + int32_t rel; + char *rip; + /* lea rdx,[__pioinfo's addr in RIP-relative 32bit addr] */ +# define PIOINFO_MARK "\x48\x8d\x15" +#else + /* mov eax,dword ptr [eax*4+100EB430h] */ +# define PIOINFO_MARK "\x8B\x04\x85" +#endif + for (p; p < pend; p++) { + if (memcmp(p, PIOINFO_MARK, strlen(PIOINFO_MARK)) == 0) { + goto found; + } + } + fprintf(stderr, "unexpected ucrtbase.dll\n"); + _exit(1); + + found: + p += strlen(PIOINFO_MARK); +#if _WIN64 + rel = *(int32_t*)(p); + rip = p + sizeof(int32_t); + __pioinfo = (ioinfo**)(rip + rel); +#else + __pioinfo = (ioinfo**)(p); +#endif +#else int fd; fd = _open("NUL", O_RDONLY); @@ -2366,6 +2420,7 @@ set_pioinfo_extra(void) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2420 /* not found, maybe something wrong... */ pioinfo_extra = 0; } +#endif } #else #define pioinfo_extra 0 Index: win32/mkexports.rb =================================================================== --- win32/mkexports.rb (revision 54736) +++ win32/mkexports.rb (revision 54737) @@ -114,6 +114,7 @@ class Exports::Mswin < Exports https://github.com/ruby/ruby/blob/trunk/win32/mkexports.rb#L114 when /OBJECT/, /LIBRARY/ next if /^[[:xdigit:]]+ 0+ UNDEF / =~ l next unless /External/ =~ l + next if /(?:_local_stdio_printf_options|v(f|sn?)printf_l)\Z/ =~ l next unless l.sub!(/.*?\s(\(\)\s+)?External\s+\|\s+/, '') is_data = !$1 if noprefix or /^[@_]/ =~ l -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/