From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id 2FC06384640F; Fri, 16 Apr 2021 01:04:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FC06384640F Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Iain Buclaw To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/ibuclaw/heads/mingw)] Fix hello world with std.stdio X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/users/ibuclaw/heads/mingw X-Git-Oldrev: 397c4149ca94b37e6ff43999dfab589937c5b833 X-Git-Newrev: 9944c62109181e208981f41c3c93599a625fe4d5 Message-Id: <20210416010411.2FC06384640F@sourceware.org> Date: Fri, 16 Apr 2021 01:04:11 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Apr 2021 01:04:11 -0000 https://gcc.gnu.org/g:9944c62109181e208981f41c3c93599a625fe4d5 commit 9944c62109181e208981f41c3c93599a625fe4d5 Author: Iain Buclaw Date: Wed Mar 24 22:11:10 2021 +0100 Fix hello world with std.stdio Diff: --- libphobos/libdruntime/config/mingw/msvc.c | 34 +++++----- libphobos/libdruntime/core/stdc/stdio.d | 108 +++++++++++++++++++++++++++--- 2 files changed, 117 insertions(+), 25 deletions(-) diff --git a/libphobos/libdruntime/config/mingw/msvc.c b/libphobos/libdruntime/config/mingw/msvc.c index 25b15a06950..4ca77e58f5a 100644 --- a/libphobos/libdruntime/config/mingw/msvc.c +++ b/libphobos/libdruntime/config/mingw/msvc.c @@ -23,32 +23,32 @@ a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ +#ifdef __MINGW32__ +#include <_mingw.h> +#endif #include -/* The symbols for stdin, stdout, and stderr are defined for D in the - core.stdc.stdio module. Save the macros and redeclare them here. */ -#define c_stdin stdin -#undef stdin -extern FILE *stdin; +/* The D runtime library defines stdin, stdout, and stderr as extern(C) symbols + in the core.stdc.stdio module, and require initializing at start-up. */ +__attribute__((weakref ("stdin"))) +static FILE *core_stdc_stdin; -#define c_stdout stdout -#undef stdout -extern FILE *stdout; +__attribute__((weakref ("stdout"))) +static FILE *core_stdc_stdout; -#define c_stderr stderr -#undef stderr -extern FILE *stderr; +__attribute__((weakref ("stderr"))) +static FILE *core_stdc_stderr; -/* Set to 1 if run-time is using ucrtbase.dll. */ +/* Set to 1 if runtime is using libucrt.dll. */ unsigned char msvcUsesUCRT; void init_msvc() { -#if __MSVCRT_VERSION__ >= 0x1400 + core_stdc_stdin = stdin; + core_stdc_stdout = stdout; + core_stdc_stderr = stderr; + +#if __MSVCRT_VERSION__ >= 0xE00 msvcUsedUCRT = 1; #endif - - stdin = c_stdin; - stdout = c_stdout; - stderr = c_stderr; } diff --git a/libphobos/libdruntime/core/stdc/stdio.d b/libphobos/libdruntime/core/stdc/stdio.d index 532a0803f55..6cd7851f96c 100644 --- a/libphobos/libdruntime/core/stdc/stdio.d +++ b/libphobos/libdruntime/core/stdc/stdio.d @@ -391,7 +391,21 @@ else version (CRuntime_Microsoft) /// struct _iobuf { + version (MinGW) + { + char* _ptr; + int _cnt; + char* _base; + int _flag; + int _file; + int _charbuf; + int _bufsiz; + char* _tmpfname; + } + else + { void* undefined; + } } /// @@ -1347,7 +1361,7 @@ version (CRuntime_DigitalMars) /// pure int fileno()(FILE* stream) { return stream._file; } } - /// + /// pragma(printf) int _snprintf(scope char* s, size_t n, scope const char* fmt, scope const ...); /// @@ -1358,6 +1372,25 @@ version (CRuntime_DigitalMars) int _vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); /// alias _vsnprintf vsnprintf; + + // + // Digital Mars under-the-hood C I/O functions. + // + + /// + int _fputc_nlock(int c, FILE* fp); + /// + int _fputwc_nlock(int c, FILE* fp); + /// + int _fgetc_nlock(FILE* fp); + /// + int _fgetwc_nlock(FILE* fp); + /// + int __fp_lock(FILE* fp); + /// + void __fp_unlock(FILE* fp); + /// + int setmode(int fd, int mode); } else version (CRuntime_Microsoft) { @@ -1373,7 +1406,10 @@ else version (CRuntime_Microsoft) /// pure int ferror(FILE* stream); /// - pure int fileno(FILE* stream); + pure int _fileno(FILE* stream); + /// + alias fileno = _fileno; + } version (MinGW) @@ -1410,16 +1446,72 @@ else version (CRuntime_Microsoft) int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); } + // + // Microsoft under-the-hood C I/O functions + // Uses _iobuf* for the unshared version of FILE*, + // usable when the FILE is locked. + // + + version (MinGW) + { + private int _filbuf(FILE*); + private int _flsbuf(int, FILE*); + /// - int _fputc_nolock(int c, FILE *fp); + int _fputc_nolock(int c, FILE* fp) + { + pragma(inline, true); + fp._cnt = fp._cnt - 1; + if (fp._cnt >= 0) + { + immutable ch = cast(char)c; + *fp._ptr = ch; + fp._ptr = fp._ptr + 1; + return ch & 0xFF; + } + else + return _flsbuf(c, fp); + } /// - int _fgetc_nolock(FILE *fp); - + int _fgetc_nolock(FILE* fp) + { + pragma(inline, true); + fp._cnt = fp._cnt - 1; + if (fp._cnt >= 0) + { + immutable ch = *fp._ptr; + fp._ptr = fp._ptr + 1; + return ch & 0xFF; + } + else + return _filbuf(fp); + } + } + else + { /// - int _lock_file(FILE *fp); + int _fputc_nolock(int c, FILE* fp); /// - int _unlock_file(FILE *fp); - + int _fgetc_nolock(FILE* fp); + } + /// + int _fputwc_nolock(int c, FILE* fp); + /// + int _fgetwc_nolock(FILE* fp); + /// + void _lock_file(FILE* fp); + /// + void _unlock_file(FILE* fp); + /// + int _setmode(int fd, int mode); + /// + FILE* _fdopen(int fd, const (char)* mode); + /// + FILE* _wfdopen(int fd, const (wchar)* mode); + /// + int _fseeki64(FILE* stream, long offset, int origin); + /// + long _ftelli64(FILE* stream); /// intptr_t _get_osfhandle(int fd); ///