Skip to content

Commit

Permalink
perl: update ucrt io hack patch.
Browse files Browse the repository at this point in the history
This now more closely aligns with what they're already doing for MSVC
using UCRT, and fixes the socket tests.  Fixes msys2#9175
  • Loading branch information
jeremyd2019 committed Jul 20, 2021
1 parent 7d7b7d8 commit 98d139f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 148 deletions.
200 changes: 53 additions & 147 deletions mingw-w64-perl/008-ucrt-stdio-internals.patch
@@ -1,185 +1,91 @@
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -347,14 +347,30 @@
--- build-x86_64-perl-5.32.1/win32/win32.h.orig 2021-07-19 13:57:38.683449300 -0700
+++ build-x86_64-perl-5.32.1/win32/win32.h 2021-07-19 13:58:59.636505400 -0700
@@ -302,8 +302,10 @@
__PL_nan_u = { 0x7FF8000000000000UI64 };
#define NV_NAN ((NV)__PL_nan_u.__d)

+#endif /* _MSC_VER */
+
/* The CRT was rewritten in VS2015. */
-#if _MSC_VER >= 1900
+#if (defined(_MSC_VER) && _MSC_VER >= 1900) || defined(_UCRT)

/* No longer declared in stdio.h */
EXTERN_C char *gets(char* buffer);
@@ -338,11 +340,7 @@
#define PERLIO_FILE_flag(f) ((int)(((__crt_stdio_stream_data*)(f))->_flags))
#define PERLIO_FILE_file(f) (*(int*)(&((__crt_stdio_stream_data*)(f))->_file))

-#endif
-
-#endif /* _MSC_VER */
-
-#if (!defined(_MSC_VER)) || (defined(_MSC_VER) && _MSC_VER < 1900)
+#else

/* Note: PERLIO_FILE_ptr/base/cnt are not actually used for GCC or <VS2015
* since FILE_ptr/base/cnt do the same thing anyway but it doesn't hurt to
* define them all here for completeness. */
-#define PERLIO_FILE_flag_RD _IOREAD /* 0x001 */
-#define PERLIO_FILE_flag_WR _IOWRT /* 0x002 */
-#define PERLIO_FILE_flag_RW _IORW /* 0x080 */
-#define PERLIO_FILE_ptr(f) ((f)->_ptr)
-#define PERLIO_FILE_base(f) ((f)->_base)
-#define PERLIO_FILE_cnt(f) ((f)->_cnt)
-#define PERLIO_FILE_flag(f) ((f)->_flag)
-#define PERLIO_FILE_file(f) ((f)->_file)
+
+#ifndef _STUPID_INTERNAL_STDIO_HACK
+#define _STUPID_INTERNAL_STDIO_HACK
+typedef struct
+{
+ char* _ptr;
+ char* _base;
+ int _cnt;
+ long _flags;
+ long _file;
+ int _charbuf;
+ int _bufsiz;
+ char* _tmpfname;
+} __crt_stdio_stream_data;
+#endif /* _STUPID_INTERNAL_STDIO_HACK */
+
+#define PERLIO_FILE_flag_RD 0x0001 /* _IOREAD */
+#define PERLIO_FILE_flag_WR 0x0002 /* _IOWRITE */
+#define PERLIO_FILE_flag_RW 0x0004 /* _IOUPDATE */
+#define PERLIO_FILE_ptr(f) (((__crt_stdio_stream_data*)(f))->_ptr)
+#define PERLIO_FILE_base(f) (((__crt_stdio_stream_data*)(f))->_base)
+#define PERLIO_FILE_cnt(f) (((__crt_stdio_stream_data*)(f))->_cnt)
+#define PERLIO_FILE_flag(f) ((int)(((__crt_stdio_stream_data*)(f))->_flags))
+#define PERLIO_FILE_file(f) (*(int*)(&((__crt_stdio_stream_data*)(f))->_file))
@@ -614,7 +612,7 @@
* the rewritten CRT in VS2015 so they are removed once again for VS2015
* onwards, which will therefore suffer from the reintroduction of the
* close socket bug. */
-#if (!defined(_MSC_VER)) || (defined(_MSC_VER) && _MSC_VER < 1900)
+#if !defined(_UCRT) && (!defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1900))

#endif
#ifdef PERL_CORE

@@ -636,7 +652,7 @@
* #if above).)
*/
#if ! (_MSC_VER < 1400 || (_MSC_VER >= 1500 && _MSC_VER <= 1700) \
- || defined(__MINGW32__))
+ || !defined(_UCRT))
/* size of ioinfo struct is determined at runtime */
# define WIN32_DYN_IOINFO_SIZE
#endif
@@ -645,32 +661,18 @@
/*
* Control structure for lowio file handles
*/
+
typedef struct {
- intptr_t osfhnd;/* underlying OS file HANDLE */
- char osfile; /* attributes of file (e.g., open in text mode?) */
- char pipech; /* one char buffer for handles opened on pipes */
- int lockinitflag;
- CRITICAL_SECTION lock;
-/* this struct definition breaks ABI compatibility with
- * not using, cl.exe's native VS version specitfic CRT. */
-# if _MSC_VER >= 1400 && _MSC_VER < 1500
-# error "This ioinfo struct is incomplete for Visual C 2005"
-# endif
-/* VS2005 CRT has at least 3 different definitions of this struct based on the
- * CRT DLL's build number. */
-# if _MSC_VER >= 1500
-# ifndef _SAFECRT_IMPL
- /* Not used in the safecrt downlevel. We do not define them, so we cannot
- * use them accidentally */
- char textmode : 7;/* __IOINFO_TM_ANSI or __IOINFO_TM_UTF8 or __IOINFO_TM_UTF16LE */
- char unicode : 1; /* Was the file opened as unicode? */
- char pipech2[2]; /* 2 more peak ahead chars for UNICODE mode */
- __int64 startpos; /* File position that matches buffer start */
- BOOL utf8translations; /* Buffer contains translations other than CRLF*/
- char dbcsBuffer; /* Buffer for the lead byte of dbcs when converting from dbcs to unicode */
- BOOL dbcsBufferUsed; /* Bool for the lead byte buffer is used or not */
-# endif
-# endif
+ CRITICAL_SECTION lock;
+ intptr_t osfhnd;
+ __int64 startpos;
+ unsigned char osfile;
+ char textmode;
+ char _pipe_lookahead[3];
+ uint8_t unicode : 1;
+ uint8_t utf8translations : 1;
+ uint8_t dbcsBufferUsed : 1;
+ char mbBuffer[MB_LEN_MAX];
} ioinfo;
#else
typedef intptr_t ioinfo;
@@ -679,13 +681,13 @@
/*
* Array of arrays of control structures for lowio files.
*/
-EXTERN_C _CRTIMP ioinfo* __pioinfo[];
+EXTERN_C ioinfo* __pioinfo[128];
@@ -714,7 +712,7 @@

/*
* Definition of IOINFO_L2E, the log base 2 of the number of elements in each
* array of ioinfo structs.
*/
-#define IOINFO_L2E 5
+#define IOINFO_L2E 6
#endif /* PERL_CORE */

-#endif /* !defined(_MSC_VER) || _MSC_VER<1900 */
+#endif /* !defined(_UCRT) && (!defined(_MSC_VER) || _MSC_VER<1900) */

/*
* Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
--- a/win32/config.gc
+++ b/win32/config.gc
/* IO.xs and POSIX.xs define PERLIO_NOT_STDIO to 1 */
#if defined(PERL_EXT_IO) || defined(PERL_EXT_POSIX)
--- build-x86_64-perl-5.32.1/win32/config.gc.orig 2021-07-19 14:23:16.089585800 -0700
+++ build-x86_64-perl-5.32.1/win32/config.gc 2021-07-19 14:24:17.714661700 -0700
@@ -1073,11 +1073,11 @@
startsh='#!/bin/sh'
static_ext=' '
stdchar='char'
-stdio_base='((fp)->_base)'
-stdio_bufsiz='((fp)->_cnt + (fp)->_ptr - (fp)->_base)'
-stdio_cnt='((fp)->_cnt)'
+stdio_base='(((__crt_stdio_stream_data*)(fp))->_base)'
+stdio_bufsiz='(((__crt_stdio_stream_data*)(fp))->_cnt + ((__crt_stdio_stream_data*)(fp))->_ptr - ((__crt_stdio_stream_data*)(fp))->_base)'
+stdio_cnt='(((__crt_stdio_stream_data*)(fp))->_cnt)'
+stdio_base='PERLIO_FILE_base(fp)'
+stdio_bufsiz='(PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))'
+stdio_cnt='PERLIO_FILE_cnt(fp)'
stdio_filbuf=''
-stdio_ptr='((fp)->_ptr)'
+stdio_ptr='(((__crt_stdio_stream_data*)(fp))->_ptr)'
+stdio_ptr='PERLIO_FILE_ptr(fp)'
stdio_stream_array=''
strerror_r_proto='0'
strings='/usr/include/string.h'
--- a/win32/config_H.gc
+++ b/win32/config_H.gc
@@ -1066,11 +1066,27 @@
* This symbol is defined if using the FILE_ptr macro as an lvalue
* to increase the pointer by n leaves File_cnt(fp) unchanged.
--- build-x86_64-perl-5.32.1/win32/config_H.gc.orig 2021-07-19 14:05:25.543619200 -0700
+++ build-x86_64-perl-5.32.1/win32/config_H.gc 2021-07-19 14:15:09.777236400 -0700
@@ -1068,9 +1068,9 @@
*/
+
+#ifndef _STUPID_INTERNAL_STDIO_HACK
+#define _STUPID_INTERNAL_STDIO_HACK
+typedef struct
+{
+ char* _ptr;
+ char* _base;
+ int _cnt;
+ long _flags;
+ long _file;
+ int _charbuf;
+ int _bufsiz;
+ char* _tmpfname;
+} __crt_stdio_stream_data;
+#endif /* _STUPID_INTERNAL_STDIO_HACK */
+
#define USE_STDIO_PTR /**/
#ifdef USE_STDIO_PTR
-#define FILE_ptr(fp) ((fp)->_ptr)
+#define FILE_ptr(fp) (((__crt_stdio_stream_data*)(fp))->_ptr)
+#define FILE_ptr(fp) PERLIO_FILE_ptr(fp)
#define STDIO_PTR_LVALUE /**/
-#define FILE_cnt(fp) ((fp)->_cnt)
+#define FILE_cnt(fp) (((__crt_stdio_stream_data*)(fp))->_cnt)
+#define FILE_cnt(fp) PERLIO_FILE_cnt(fp)
#define STDIO_CNT_LVALUE /**/
/*#define STDIO_PTR_LVAL_SETS_CNT / **/
#define STDIO_PTR_LVAL_NOCHANGE_CNT /**/
@@ -1098,8 +1114,8 @@
@@ -1098,8 +1098,8 @@
*/
#define USE_STDIO_BASE /**/
#ifdef USE_STDIO_BASE
-#define FILE_base(fp) ((fp)->_base)
-#define FILE_bufsiz(fp) ((fp)->_cnt + (fp)->_ptr - (fp)->_base)
+#define FILE_base(fp) (((__crt_stdio_stream_data*)(fp))->_base)
+#define FILE_bufsiz(fp) (((__crt_stdio_stream_data*)(fp))->_cnt + ((__crt_stdio_stream_data*)(fp))->_ptr - ((__crt_stdio_stream_data*)(fp))->_base)
+#define FILE_base(fp) PERLIO_FILE_base(fp)
+#define FILE_bufsiz(fp) (PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))
#endif

/* DOUBLESIZE:
--- a/win32/win32sck.c
+++ b/win32/win32sck.c
@@ -60,6 +60,8 @@

#ifdef WIN32_DYN_IOINFO_SIZE
EXTERN_C Size_t w32_ioinfo_size;
+#else
+ioinfo* __pioinfo[128] = { 0 };
#endif

EXTERN_C void
--- a/dist/threads/threads.xs
+++ a/dist/threads/threads.xs
@@ -15,7 +15,7 @@
Expand Down
2 changes: 1 addition & 1 deletion mingw-w64-perl/PKGBUILD
Expand Up @@ -707,7 +707,7 @@ sha256sums=('57cc47c735c8300a8ce2fa0643507b44c4ae59012bfdad0121313db639e02309'
'ecf7d1e70976b25aad329ef7f77ddd6ba6c2efed3b94e30946e250d03cdd6d2e'
'ff00fed8cd056e36d7f02a43f06feee10911fc2750773f139136426fb9af8b11'
'b05767965076b59585343f3ea242baebeca2128c9485694155468664add023d0'
'a54a67a4b66f396a0db8353b29d4af381b6485253ad510eb0f1895f57d17d231'
'f0d33f057794ced071cad450b6d532ccd0b1c21fa73dedbc3a3c08563b4ad1dd'
'd4d40153064f7fb541f5c526269af834d114b010250c549f2e0c71a553d2228a'
'0d282638480937cb5b679a2046caa88309e79262dca62805e562b542e159806e'
'9b6297d38f9fc1f34281f0f6c68c1b04009eb29b27f9c71d54c5047358388f55'
Expand Down

0 comments on commit 98d139f

Please sign in to comment.