Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.97k stars 560 forks source link

[PATCH] remove Winsock lib dep and reentr.c from Win32 gcc miniperl #16542

Open p5pRT opened 6 years ago

p5pRT commented 6 years ago

Migrated from rt.perl.org#133166 (status was 'open')

Searchable as RT133166$

p5pRT commented 6 years ago

From @bulk88

Created by @bulk88

See attached patch.

Timing details. Command executed was "timeit gmake test-prep". Most of the numbers went down with this patch. Compiler used was "gcc version 4.9.2 (i686-posix-sjlj\, built by strawberryperl.com project)" with WinXP on a Core 2 Duo 2.6 GHZ. I intentionally tested without -j2 (IE serial build) to get the numbers more stable.

before

Version Number​: Windows NT 5.1 (Build 2600) Exit Time​: 3​:10 pm\, Monday\, April 30 2018 Elapsed Time​: 0​:07​:05.390 Process Time​: 0​:00​:00.453 System Calls​: 8875279 Context Switches​: 1970401 Page Faults​: 6917075 Bytes Read​: 2206418004 Bytes Written​: 166497901 Bytes Other​: 382647133

Version Number​: Windows NT 5.1 (Build 2600) Exit Time​: 3​:28 pm\, Monday\, April 30 2018 Elapsed Time​: 0​:07​:04.875 Process Time​: 0​:00​:00.390 System Calls​: 8870031 Context Switches​: 1970373 Page Faults​: 6926813 Bytes Read​: 2206423972 Bytes Written​: 166629960 Bytes Other​: 386246605

Version Number​: Windows NT 5.1 (Build 2600) Exit Time​: 4​:04 pm\, Monday\, April 30 2018 Elapsed Time​: 0​:07​:06.140 Process Time​: 0​:00​:00.343 System Calls​: 8874378 Context Switches​: 2024489 Page Faults​: 6987235 Bytes Read​: 2206152316 Bytes Written​: 166831336 Bytes Other​: 391573104

after

Version Number​: Windows NT 5.1 (Build 2600) Exit Time​: 2​:32 pm\, Monday\, April 30 2018 Elapsed Time​: 0​:07​:01.812 Process Time​: 0​:00​:00.250 System Calls​: 8691965 Context Switches​: 1939719 Page Faults​: 6823885 Bytes Read​: 2164443224 Bytes Written​: 163538059 Bytes Other​: 375781945

Version Number​: Windows NT 5.1 (Build 2600) Exit Time​: 2​:45 pm\, Monday\, April 30 2018 Elapsed Time​: 0​:07​:00.750 Process Time​: 0​:00​:00.343 System Calls​: 8720894 Context Switches​: 1937938 Page Faults​: 6776938 Bytes Read​: 2164873543 Bytes Written​: 166441030 Bytes Other​: 389824653

Perl Info ``` --- Flags: category=core severity=low --- Site configuration information for perl 5.27.9: Configured by Administrator at Tue Jan 30 20:34:30 2018. Summary of my perl5 (revision 5 version 27 subversion 9) configuration: Platform: osname=MSWin32 osvers=5.2.3790 archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended useposix=true d_sigaction=undef useithreads=define usemultiplicity=define use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n default_inc_excludes_dot=define bincompat5005=undef Compiler: cc='cl' ccflags ='-nologo -GF -W3 -O1 -MD -Zi -DNDEBUG -GL -DWIN32 -D_CONSOLE -DNO_STRICT -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DWIN32_NO_REGISTRY' optimize='-O1 -MD -Zi -DNDEBUG -GL' cppflags='-DWIN32' ccversion='15.00.30729.01' gccversion='' gccosandvers='' intsize=4 longsize=4 ptrsize=4 doublesize=8 byteorder=1234 doublekind=3 d_longlong=undef longlongsize=8 d_longdbl=define longdblsize=8 longdblkind=0 ivtype='long' ivsize=4 nvtype='double' nvsize=8 Off_t='__int64' lseeksize=8 alignbytes=8 prototype=define Linker and Libraries: ld='link' ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf -ltcg -libpath:"c:\perl\lib\CORE" -machine:x86' libpth="C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib" libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib libc=msvcrt.lib so=dll useshrplib=true libperl=perl527.lib gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs dlext=dll d_dlsymun=undef ccdlflags=' ' cccdlflags=' ' lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf -ltcg -libpath:"c:\perl\lib\CORE" -machine:x86' --- @INC for perl 5.27.9: lib C:/p527/srcnew/lib --- Environment for perl 5.27.9: CYGWIN=tty HOME (unset) LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH=/usr/lib/x86:/usr/X11R6/lib LOGDIR (unset) PATH=C:\WINDOWS\system32;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin;C:\Perl\bin;C:\WINDOWS;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files (x86)\Git\bin;C:\sp3220\c\bin; PERL_BADLANG (unset) SHELL (unset) ```
p5pRT commented 6 years ago

From @bulk88

0001-remove-Winsock-lib-dep-and-reentr.c-from-Win32-gcc-m.patch ```diff From 3d9a988b59814e86aa33e1599b924e919cde431a Mon Sep 17 00:00:00 2001 From: Daniel Dragan Date: Tue, 1 May 2018 01:07:50 -0400 Subject: [PATCH] remove Winsock lib dep and reentr.c from Win32 gcc miniperl This commit extends work done in commit 19253ae62c to remove winsock from the gcc miniperl. commit 19253ae62c only removed winsock from VC miniperl. -the gcc linker does NOT remove unrefed non-static functions from final binaries, so ws2_32.dll was still linked inside miniperl by references from dead code that was not eliminated by the linker. To fix this, not compiling win32sck.c and not linking it in seems to be the only solution. Other non perl devs have complained about this on various message boards and were told to use GCC LTO or simply the object file specification is an "all or nothing" file format and the linker "can't" look inside the obj file. Visual C can with its "comdat" attribute that is on by default but Mingw GCC has no analog feature. -func win32_uname, I think exists for XS code to use for posix compatibility, it is completly unused and unreferenced inside miniperl and full perl, but it contains to call to win32_gethostbyname that is inside win32sck.c but now we aren't compiling that, so #ifdef guard away the call to win32_gethostbyname to make it seem like win32_gethostbyname returned NULL. -funcs convert_errno_to_wsa_error and convert_wsa_error_to_errno aka win32_get_errno are int to int lookup tables and do not call other funcs and therefore do not link in ws2_32.dll so move them to win32.c. The alternative would be to not compile them on socketless (mini) perl, but I could imagine some kind of `wget` or `curl` returning 10*** series error codes through stderr and a PP wrapper then assigning the 10*** code to $! even though this perl doesn't have sockets, and thus using the WSA to E* error code translation code, and thus producing an observable difference in that module when run with mini and full perl. -remove win32_get_errno wrapper func and replace with a macro, less indirection machine code wise, I assume "win32_get_errno" was created so the code in win32_get_errno()'s only caller which is Perl_magic_set() in mg.c looks cleaner to non-win32 p5p devs and shows that it is win32 specific -the only caller of convert_errno_to_wsa_error() is in win32.c and now that convert_errno_to_wsa_error() was moved from win32sck.c to win32.c it can be marked static for CC efficiency (CC can inline or non-std calling convention it) -the #define NO_MATHOMS, by itself reduced disk size of miniperl.exe compiled with Mingw64 gcc 4.9.2 from 2190KB to 2177KB -perlapi.o and mathom.o are empty for miniperl, dont even bother to run the CC on them, this saves build time -Win32 API doesn't have *_r family of libc funcs since Win32 API was from day 1 designed to be thread-safe/reentrant, therefore reentr.o has empty stub functions whose only purpose is to export these 4 stubs error LNK2001: unresolved external symbol _Perl_reentrant_free error LNK2001: unresolved external symbol _Perl_reentrant_init error LNK2001: unresolved external symbol _Perl_reentrant_retry error LNK2001: unresolved external symbol _Perl_reentrant_size so just remove the only ref to these 4 funcs and dont compile reentr.c in any build config on win32 anymore. -ifdef out the prototypes and #define Perl_* wrappers for reenterant api so unprotected usage of these 4 funcs breaks more visibly and less symbols inside the CC's identifier DB since they were removed at preproc time -remove PL_reentrant_retint var from interp struct if not using reenterant API since the var isn't used unless we have reenterant APIs to wrap, this saves an int of memory and couple cpu instructions on disk in perl_clone_using -there is additional info in the RT ticket associated with this patch --- embed.fnc | 2 + embed.h | 10 +- intrpvar.h | 2 + makedef.pl | 4 + proto.h | 14 +-- sv.c | 2 + win32/GNUmakefile | 22 +++-- win32/Makefile | 21 +++-- win32/makefile.mk | 22 +++-- win32/win32.c | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++---- win32/win32.h | 15 ++- win32/win32sck.c | 257 ------------------------------------------------- 12 files changed, 338 insertions(+), 311 deletions(-) diff --git a/embed.fnc b/embed.fnc index a3e1fda..a3b76d8 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1283,10 +1283,12 @@ p |void |rpeep |NULLOK OP* o : Defined in doio.c, used only in pp_hot.c dopM |PerlIO*|start_glob |NN SV *tmpglob|NN IO *io +#ifdef USE_REENTRANT_API Ap |void |reentrant_size Ap |void |reentrant_init Ap |void |reentrant_free Anp |void* |reentrant_retry|NN const char *f|... +#endif : "Very" special - can't use the O flag for this one: : (The rename from perl_atexit to Perl_call_atexit was in 864dbfa3ca8032ef) diff --git a/embed.h b/embed.h index 8b73201..7ecd145 100644 --- a/embed.h +++ b/embed.h @@ -615,10 +615,6 @@ #define re_compile(a,b) Perl_re_compile(aTHX_ a,b) #define re_intuit_start(a,b,c,d,e,f,g) Perl_re_intuit_start(aTHX_ a,b,c,d,e,f,g) #define re_intuit_string(a) Perl_re_intuit_string(aTHX_ a) -#define reentrant_free() Perl_reentrant_free(aTHX) -#define reentrant_init() Perl_reentrant_init(aTHX) -#define reentrant_retry Perl_reentrant_retry -#define reentrant_size() Perl_reentrant_size(aTHX) #define reg_named_buff_all(a,b) Perl_reg_named_buff_all(aTHX_ a,b) #define reg_named_buff_exists(a,b,c) Perl_reg_named_buff_exists(aTHX_ a,b,c) #define reg_named_buff_fetch(a,b,c) Perl_reg_named_buff_fetch(aTHX_ a,b,c) @@ -1072,6 +1068,12 @@ #define quadmath_format_needed Perl_quadmath_format_needed #define quadmath_format_single Perl_quadmath_format_single #endif +#if defined(USE_REENTRANT_API) +#define reentrant_free() Perl_reentrant_free(aTHX) +#define reentrant_init() Perl_reentrant_init(aTHX) +#define reentrant_retry Perl_reentrant_retry +#define reentrant_size() Perl_reentrant_size(aTHX) +#endif #if defined(WIN32) || defined(__SYMBIAN32__) || defined(VMS) #define do_aspawn(a,b,c) Perl_do_aspawn(aTHX_ a,b,c) #define do_spawn(a) Perl_do_spawn(aTHX_ a) diff --git a/intrpvar.h b/intrpvar.h index f7b6ee3..c9b5e6f 100644 --- a/intrpvar.h +++ b/intrpvar.h @@ -341,7 +341,9 @@ PERLVAR(I, perldb, U32) PERLVAR(I, signals, U32) /* Using which pre-5.8 signals */ +#ifdef USE_REENTRANT_API PERLVAR(I, reentrant_retint, int) /* Integer return value from reentrant functions */ +#endif /* pseudo environmental stuff */ PERLVAR(I, origargc, int) diff --git a/makedef.pl b/makedef.pl index dbd756d..1255a0b 100644 --- a/makedef.pl +++ b/makedef.pl @@ -321,6 +321,10 @@ unless ($define{PERL_SAWAMPERSAND}) { unless ($define{'USE_REENTRANT_API'}) { ++$skip{PL_reentrant_buffer}; + ++$skip{Perl_reentrant_free}; + ++$skip{Perl_reentrant_init}; + ++$skip{Perl_reentrant_retry}; + ++$skip{Perl_reentrant_size}; } if ($define{'MYMALLOC'}) { diff --git a/proto.h b/proto.h index 705e7d9..e42722c 100644 --- a/proto.h +++ b/proto.h @@ -2768,12 +2768,6 @@ PERL_CALLCONV REGEXP* Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_cou PERL_CALLCONV Malloc_t Perl_realloc(Malloc_t where, MEM_SIZE nbytes) __attribute__warn_unused_result__; -PERL_CALLCONV void Perl_reentrant_free(pTHX); -PERL_CALLCONV void Perl_reentrant_init(pTHX); -PERL_CALLCONV void* Perl_reentrant_retry(const char *f, ...); -#define PERL_ARGS_ASSERT_REENTRANT_RETRY \ - assert(f) -PERL_CALLCONV void Perl_reentrant_size(pTHX); #ifndef NO_MATHOMS PERL_CALLCONV OP* Perl_ref(pTHX_ OP* o, I32 type); #endif @@ -6465,6 +6459,14 @@ PERL_CALLCONV const char* Perl_quadmath_format_single(const char* format); #define PERL_ARGS_ASSERT_QUADMATH_FORMAT_SINGLE \ assert(format) #endif +#if defined(USE_REENTRANT_API) +PERL_CALLCONV void Perl_reentrant_free(pTHX); +PERL_CALLCONV void Perl_reentrant_init(pTHX); +PERL_CALLCONV void* Perl_reentrant_retry(const char *f, ...); +#define PERL_ARGS_ASSERT_REENTRANT_RETRY \ + assert(f) +PERL_CALLCONV void Perl_reentrant_size(pTHX); +#endif #if defined(WIN32) PERL_CALLCONV_NO_RET void win32_croak_not_implemented(const char * fname) __attribute__noreturn__; diff --git a/sv.c b/sv.c index 0f0e666..8c10ed2 100644 --- a/sv.c +++ b/sv.c @@ -15325,7 +15325,9 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags, /* Not really needed/useful since the reenrant_retint is "volatile", * but do it for consistency's sake. */ +#ifdef USE_REENTRANT_API PL_reentrant_retint = proto_perl->Ireentrant_retint; +#endif /* Hooks to shared SVs and locks. */ PL_sharehook = proto_perl->Isharehook; diff --git a/win32/GNUmakefile b/win32/GNUmakefile index de34db2..a5f82a4 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -1026,14 +1026,11 @@ MICROCORE_SRC = \ ..\mro_core.c \ ..\locale.c \ ..\keywords.c \ - ..\mathoms.c \ ..\mg.c \ ..\numeric.c \ ..\pad.c \ - ..\perlapi.c \ ..\perly.c \ ..\pp_sort.c \ - ..\reentr.c \ ..\run.c \ ..\scope.c \ ..\taint.c \ @@ -1041,20 +1038,24 @@ MICROCORE_SRC = \ ..\universal.c \ ..\util.c -EXTRACORE_SRC += perllib.c +EXTRACORE_SRC = \ + perllib.c \ + ..\mathoms.c \ + ..\perlapi.c \ + ..\perlio.c ifeq ($(PERL_MALLOC),define) EXTRACORE_SRC += ..\malloc.c endif -EXTRACORE_SRC += ..\perlio.c - WIN32_SRC = \ .\win32.c \ - .\win32sck.c \ .\win32thread.c \ .\fcrypt.c +WIN32EXTRA_SRC = \ + .\win32sck.c + # We need this for miniperl build unless we override canned # config.h #define building mini\* #ifeq ($(USE_PERLIO)" == "define" @@ -1114,6 +1115,7 @@ HAVE_COREDIR = .coreheaders MICROCORE_OBJ = $(MICROCORE_SRC:.c=$(o)) CORE_OBJ = $(MICROCORE_OBJ) $(EXTRACORE_SRC:.c=$(o)) WIN32_OBJ = $(WIN32_SRC:.c=$(o)) +WIN32EXTRA_OBJ = $(WIN32EXTRA_SRC:.c=$(o)) MINICORE_OBJ = $(subst ..\,mini\,$(MICROCORE_OBJ)) \ $(MINIDIR)\miniperlmain$(o) \ @@ -1126,7 +1128,7 @@ PERLDLL_OBJ = $(CORE_OBJ) PERLEXE_OBJ = perlmain$(o) PERLEXEST_OBJ = perlmainst$(o) -PERLDLL_OBJ += $(WIN32_OBJ) $(DLL_OBJ) +PERLDLL_OBJ += $(WIN32_OBJ) $(WIN32EXTRA_OBJ) $(DLL_OBJ) ifneq ($(USE_SETARGV),) SETARGV_OBJ = setargv$(o) @@ -1498,6 +1500,8 @@ $(MINI_OBJ) : $(MINIDIR)\.exists $(CORE_NOCFG_H) $(WIN32_OBJ) : $(CORE_H) +$(WIN32EXTRA_OBJ): $(CORE_H) + $(CORE_OBJ) : $(CORE_H) $(DLL_OBJ) : $(CORE_H) @@ -1941,7 +1945,7 @@ _clean : -if exist $(UNIDATADIR1) rmdir /s /q $(UNIDATADIR1) -if exist $(UNIDATADIR2) rmdir /s /q $(UNIDATADIR2) -@erase $(UNIDATAFILES) - -@erase $(WIN32_OBJ) + -@erase $(WIN32_OBJ) $(WIN32EXTRA_OBJ) -@erase $(DLL_OBJ) -@erase ..\*$(o) ..\*$(a) ..\*.exp *$(o) *$(a) *.exp *.res -@erase ..\t\*.exe ..\t\*.dll ..\t\*.bat diff --git a/win32/Makefile b/win32/Makefile index 85f75b9..ac6d320 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -780,13 +780,11 @@ MICROCORE_SRC = \ ..\hv.c \ ..\locale.c \ ..\keywords.c \ - ..\mathoms.c \ ..\mg.c \ ..\numeric.c \ ..\op.c \ ..\pad.c \ ..\perl.c \ - ..\perlapi.c \ ..\perly.c \ ..\pp.c \ ..\pp_ctl.c \ @@ -794,7 +792,6 @@ MICROCORE_SRC = \ ..\pp_pack.c \ ..\pp_sort.c \ ..\pp_sys.c \ - ..\reentr.c \ ..\regcomp.c \ ..\regexec.c \ ..\run.c \ @@ -807,21 +804,25 @@ MICROCORE_SRC = \ ..\utf8.c \ ..\util.c -EXTRACORE_SRC = $(EXTRACORE_SRC) perllib.c +EXTRACORE_SRC = \ + perllib.c \ + ..\mathoms.c \ + ..\perlapi.c \ + ..\perlio.c !IF "$(PERL_MALLOC)" == "define" EXTRACORE_SRC = $(EXTRACORE_SRC) ..\malloc.c !ENDIF -EXTRACORE_SRC = $(EXTRACORE_SRC) ..\perlio.c - WIN32_SRC = \ .\win32.c \ .\win32io.c \ - .\win32sck.c \ .\win32thread.c \ .\fcrypt.c +WIN32EXTRA_SRC = \ + .\win32sck.c + CORE_NOCFG_H = \ ..\av.h \ ..\cop.h \ @@ -873,6 +874,7 @@ GENERATED_HEADERS = $(UUDMAP_H) $(BITCOUNT_H) $(MG_DATA_H) MICROCORE_OBJ = $(MICROCORE_SRC:.c=.obj) CORE_OBJ = $(MICROCORE_OBJ) $(EXTRACORE_SRC:.c=.obj) WIN32_OBJ = $(WIN32_SRC:.c=.obj) +WIN32EXTRA_OBJ = $(WIN32EXTRA_SRC:.c=.obj) MINICORE_OBJ = $(MICROCORE_OBJ:..\=.\mini\) \ $(MINIDIR)\miniperlmain$(o) \ $(MINIDIR)\perlio$(o) @@ -885,7 +887,7 @@ PERLDLL_OBJ = $(CORE_OBJ) PERLEXE_OBJ = perlmain$(o) PERLEXEST_OBJ = perlmainst$(o) -PERLDLL_OBJ = $(PERLDLL_OBJ) $(WIN32_OBJ) $(DLL_OBJ) +PERLDLL_OBJ = $(PERLDLL_OBJ) $(WIN32_OBJ) $(WIN32EXTRA_OBJ) $(DLL_OBJ) !IF "$(USE_SETARGV)" != "" SETARGV_OBJ = setargv$(o) @@ -1130,6 +1132,7 @@ perllib$(o) : perllib.c .\perlhost.h .\vdir.h .\vmem.h $(MINI_OBJ) : $(CORE_NOCFG_H) $(WIN32_OBJ) : $(CORE_H) +$(WIN32EXTRA_OBJ): $(CORE_H) $(CORE_OBJ) : $(CORE_H) $(DLL_OBJ) : $(CORE_H) @@ -1504,7 +1507,7 @@ _clean : -if exist $(UNIDATADIR1) rmdir /s /q $(UNIDATADIR1) -if exist $(UNIDATADIR2) rmdir /s /q $(UNIDATADIR2) -@$(DEL) $(UNIDATAFILES) - -@$(DEL) $(WIN32_OBJ) + -@$(DEL) $(WIN32_OBJ) $(WIN32EXTRA_OBJ) -@$(DEL) $(DLL_OBJ) -@$(DEL) ..\*$(o) ..\*.lib ..\*.exp *$(o) *.lib *.exp *.res -@$(DEL) ..\t\*.exe ..\t\*.dll ..\t\*.bat diff --git a/win32/makefile.mk b/win32/makefile.mk index be8c4b5..0e93ab8 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -1008,14 +1008,11 @@ MICROCORE_SRC = \ ..\mro_core.c \ ..\locale.c \ ..\keywords.c \ - ..\mathoms.c \ ..\mg.c \ ..\numeric.c \ ..\pad.c \ - ..\perlapi.c \ ..\perly.c \ ..\pp_sort.c \ - ..\reentr.c \ ..\run.c \ ..\scope.c \ ..\taint.c \ @@ -1023,21 +1020,27 @@ MICROCORE_SRC = \ ..\universal.c \ ..\util.c -EXTRACORE_SRC += perllib.c +EXTRACORE_SRC = \ + perllib.c \ + ..\mathoms.c \ + ..\perlapi.c \ + ..\perlio.c .IF "$(PERL_MALLOC)" == "define" EXTRACORE_SRC += ..\malloc.c .ENDIF -EXTRACORE_SRC += ..\perlio.c + WIN32_SRC = \ .\win32.c \ .\win32io.c \ - .\win32sck.c \ .\win32thread.c \ .\fcrypt.c +WIN32EXTRA_SRC = \ + .\win32sck.c + CORE_NOCFG_H = \ ..\av.h \ ..\cop.h \ @@ -1091,6 +1094,7 @@ HAVE_COREDIR = .\.coreheaders MICROCORE_OBJ = $(MICROCORE_SRC:db:+$(o)) CORE_OBJ = $(MICROCORE_OBJ) $(EXTRACORE_SRC:db:+$(o)) WIN32_OBJ = $(WIN32_SRC:db:+$(o)) +WIN32EXTRA_OBJ = $(WIN32EXTRA_SRC:db:+$(o)) MINICORE_OBJ = $(MINIDIR)\{$(MICROCORE_OBJ:f) miniperlmain$(o) perlio$(o)} MINIWIN32_OBJ = $(MINIDIR)\{$(WIN32_OBJ:f)} MINI_OBJ = $(MINICORE_OBJ) $(MINIWIN32_OBJ) @@ -1100,7 +1104,7 @@ PERLDLL_OBJ = $(CORE_OBJ) PERLEXE_OBJ = perlmain$(o) PERLEXEST_OBJ = perlmainst$(o) -PERLDLL_OBJ += $(WIN32_OBJ) $(DLL_OBJ) +PERLDLL_OBJ += $(WIN32_OBJ) $(WIN32EXTRA_OBJ) $(DLL_OBJ) .IF "$(USE_SETARGV)" != "" SETARGV_OBJ = setargv$(o) @@ -1467,6 +1471,8 @@ $(MINI_OBJ) : $(MINIDIR)\.exists $(CORE_NOCFG_H) $(WIN32_OBJ) : $(CORE_H) +$(WIN32EXTRA_OBJ): $(CORE_H) + $(CORE_OBJ) : $(CORE_H) $(DLL_OBJ) : $(CORE_H) @@ -1899,7 +1905,7 @@ _clean : -if exist $(UNIDATADIR1) rmdir /s /q $(UNIDATADIR1) -if exist $(UNIDATADIR2) rmdir /s /q $(UNIDATADIR2) -@erase $(UNIDATAFILES) - -@erase $(WIN32_OBJ) + -@erase $(WIN32_OBJ) $(WIN32EXTRA_OBJ) -@erase $(DLL_OBJ) -@erase ..\*$(o) ..\*$(a) ..\*.exp *$(o) *$(a) *.exp *.res -@erase ..\t\*.exe ..\t\*.dll ..\t\*.bat diff --git a/win32/win32.c b/win32/win32.c index be904eb..2f8fe71 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2056,7 +2056,9 @@ win32_gettimeofday(struct timeval *tp, void *not_used) DllExport int win32_uname(struct utsname *name) { +#ifdef HAS_GETHOSTBYNAME struct hostent *hep; +#endif STRLEN nodemax = sizeof(name->nodename)-1; /* sysname */ @@ -2088,6 +2090,7 @@ win32_uname(struct utsname *name) sprintf(buf, " (%s)", g_osver.szCSDVersion); } +#ifdef HAS_GETHOSTBYNAME /* nodename */ hep = win32_gethostbyname("localhost"); if (hep) { @@ -2100,7 +2103,9 @@ win32_uname(struct utsname *name) name->nodename[nodemax] = '\0'; } } - else { + else +#endif + { DWORD sz = nodemax; if (!GetComputerName(name->nodename, &sz)) *name->nodename = '\0'; @@ -2549,21 +2554,6 @@ win32_flock(int fd, int oper) #undef LK_LEN -extern int convert_wsa_error_to_errno(int wsaerr); /* in win32sck.c */ - -/* Get the errno value corresponding to the given err. This function is not - * intended to handle conversion of general GetLastError() codes. It only exists - * to translate Windows sockets error codes from WSAGetLastError(). Such codes - * used to be assigned to errno/$! in earlier versions of perl; this function is - * used to catch any old Perl code which is still trying to assign such values - * to $! and convert them to errno values instead. - */ -int -win32_get_errno(int err) -{ - return convert_wsa_error_to_errno(err); -} - /* * redirected io subsystem for all XS modules * @@ -2613,9 +2603,263 @@ win32_feof(FILE *fp) return (feof(fp)); } +/* Translate WSAExxx values to corresponding Exxx values where possible. Not all + * WSAExxx constants have corresponding Exxx constants in (even in + * VC++ 2010 and above, which have expanded with more values), but + * most missing constants are provided by win32/include/sys/errno2.h. The few + * that are not are returned unchanged. + * + * The list of possible WSAExxx values used here comes from the MSDN page + * titled "Windows Sockets Error Codes". + * + * (Note: Only the WSAExxx values are handled here; other WSAxxx values are + * returned unchanged. The return value normally ends up in errno/$! and at + * the Perl code level may be tested against the Exxx constants exported by + * the Errno and POSIX modules, which have never handled the other WSAxxx + * values themselves, apparently without any ill effect so far.) + */ +int +convert_wsa_error_to_errno(int wsaerr) +{ + switch (wsaerr) { + case WSAEINTR: + return EINTR; + case WSAEBADF: + return EBADF; + case WSAEACCES: + return EACCES; + case WSAEFAULT: + return EFAULT; + case WSAEINVAL: + return EINVAL; + case WSAEMFILE: + return EMFILE; + case WSAEWOULDBLOCK: + return EWOULDBLOCK; + case WSAEINPROGRESS: + return EINPROGRESS; + case WSAEALREADY: + return EALREADY; + case WSAENOTSOCK: + return ENOTSOCK; + case WSAEDESTADDRREQ: + return EDESTADDRREQ; + case WSAEMSGSIZE: + return EMSGSIZE; + case WSAEPROTOTYPE: + return EPROTOTYPE; + case WSAENOPROTOOPT: + return ENOPROTOOPT; + case WSAEPROTONOSUPPORT: + return EPROTONOSUPPORT; + case WSAESOCKTNOSUPPORT: + return ESOCKTNOSUPPORT; + case WSAEOPNOTSUPP: + return EOPNOTSUPP; + case WSAEPFNOSUPPORT: + return EPFNOSUPPORT; + case WSAEAFNOSUPPORT: + return EAFNOSUPPORT; + case WSAEADDRINUSE: + return EADDRINUSE; + case WSAEADDRNOTAVAIL: + return EADDRNOTAVAIL; + case WSAENETDOWN: + return ENETDOWN; + case WSAENETUNREACH: + return ENETUNREACH; + case WSAENETRESET: + return ENETRESET; + case WSAECONNABORTED: + return ECONNABORTED; + case WSAECONNRESET: + return ECONNRESET; + case WSAENOBUFS: + return ENOBUFS; + case WSAEISCONN: + return EISCONN; + case WSAENOTCONN: + return ENOTCONN; + case WSAESHUTDOWN: + return ESHUTDOWN; + case WSAETOOMANYREFS: + return ETOOMANYREFS; + case WSAETIMEDOUT: + return ETIMEDOUT; + case WSAECONNREFUSED: + return ECONNREFUSED; + case WSAELOOP: + return ELOOP; + case WSAENAMETOOLONG: + return ENAMETOOLONG; + case WSAEHOSTDOWN: + return WSAEHOSTDOWN; /* EHOSTDOWN is not defined */ + case WSAEHOSTUNREACH: + return EHOSTUNREACH; + case WSAENOTEMPTY: + return ENOTEMPTY; + case WSAEPROCLIM: + return EPROCLIM; + case WSAEUSERS: + return EUSERS; + case WSAEDQUOT: + return EDQUOT; + case WSAESTALE: + return ESTALE; + case WSAEREMOTE: + return EREMOTE; + case WSAEDISCON: + return WSAEDISCON; /* EDISCON is not defined */ + case WSAENOMORE: + return WSAENOMORE; /* ENOMORE is not defined */ +#ifdef WSAECANCELLED + case WSAECANCELLED: /* New in WinSock2 */ + return ECANCELED; +#endif + case WSAEINVALIDPROCTABLE: + return WSAEINVALIDPROCTABLE; /* EINVALIDPROCTABLE is not defined */ + case WSAEINVALIDPROVIDER: + return WSAEINVALIDPROVIDER; /* EINVALIDPROVIDER is not defined */ + case WSAEPROVIDERFAILEDINIT: + return WSAEPROVIDERFAILEDINIT; /* EPROVIDERFAILEDINIT is not defined */ + case WSAEREFUSED: + return WSAEREFUSED; /* EREFUSED is not defined */ + } + + return wsaerr; +} + #ifdef ERRNO_HAS_POSIX_SUPPLEMENT -extern int convert_errno_to_wsa_error(int err); /* in win32sck.c */ +/* Translate Exxx values in the POSIX supplement range defined in VC++ 2010 and + * above (EADDRINUSE <= err <= EWOULDBLOCK) to corresponding WSAExxx values. Not + * all such Exxx constants have corresponding WSAExxx constants in ; + * we just use ERROR_INVALID_FUNCTION for those that are missing but do not + * really expect to encounter them anyway in the context in which this function + * is called. + * Some versions of MinGW/gcc-4.8 and above also define most, but not all, of + * these extra Exxx values. The missing ones are all cases for which there is no + * corresponding WSAExxx constant anyway, so we simply omit the cases for them + * here. + * Other Exxx values (err < sys_nerr) are returned unchanged. + */ +static int +convert_errno_to_wsa_error(int err) +{ + switch (err) { + case EADDRINUSE: + return WSAEADDRINUSE; + case EADDRNOTAVAIL: + return WSAEADDRNOTAVAIL; + case EAFNOSUPPORT: + return WSAEAFNOSUPPORT; + case EALREADY: + return WSAEALREADY; +#ifdef EBADMSG + case EBADMSG: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case ECANCELED: +#ifdef WSAECANCELLED + return WSAECANCELLED; /* New in WinSock2 */ +#else + return ERROR_INVALID_FUNCTION; +#endif + case ECONNABORTED: + return WSAECONNABORTED; + case ECONNREFUSED: + return WSAECONNREFUSED; + case ECONNRESET: + return WSAECONNRESET; + case EDESTADDRREQ: + return WSAEDESTADDRREQ; + case EHOSTUNREACH: + return WSAEHOSTUNREACH; +#ifdef EIDRM + case EIDRM: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case EINPROGRESS: + return WSAEINPROGRESS; + case EISCONN: + return WSAEISCONN; + case ELOOP: + return WSAELOOP; + case EMSGSIZE: + return WSAEMSGSIZE; + case ENETDOWN: + return WSAENETDOWN; + case ENETRESET: + return WSAENETRESET; + case ENETUNREACH: + return WSAENETUNREACH; + case ENOBUFS: + return WSAENOBUFS; +#ifdef ENODATA + case ENODATA: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif +#ifdef ENOLINK + case ENOLINK: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif +#ifdef ENOMSG + case ENOMSG: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case ENOPROTOOPT: + return WSAENOPROTOOPT; +#ifdef ENOSR + case ENOSR: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; #endif +#ifdef ENOSTR + case ENOSTR: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case ENOTCONN: + return WSAENOTCONN; +#ifdef ENOTRECOVERABLE + case ENOTRECOVERABLE: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case ENOTSOCK: + return WSAENOTSOCK; + case ENOTSUP: + return ERROR_INVALID_FUNCTION; + case EOPNOTSUPP: + return WSAEOPNOTSUPP; +#ifdef EOTHER + case EOTHER: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case EOVERFLOW: + return ERROR_INVALID_FUNCTION; + case EOWNERDEAD: + return ERROR_INVALID_FUNCTION; + case EPROTO: + return ERROR_INVALID_FUNCTION; + case EPROTONOSUPPORT: + return WSAEPROTONOSUPPORT; + case EPROTOTYPE: + return WSAEPROTOTYPE; +#ifdef ETIME + case ETIME: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case ETIMEDOUT: + return WSAETIMEDOUT; +#ifdef ETXTBSY + case ETXTBSY: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case EWOULDBLOCK: + return WSAEWOULDBLOCK; + } + + return err; +} +#endif /* ERRNO_HAS_POSIX_SUPPLEMENT */ + /* * Since the errors returned by the socket error function diff --git a/win32/win32.h b/win32/win32.h index c7c07db..de40fae 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -29,6 +29,9 @@ /* allow minitest to work */ # define PERL_TEXTMODE_SCRIPTS + +/* dont compile mathom funcs when miniperl doesn't load XS */ +# define NO_MATHOMS #endif #ifdef WIN32_NO_SOCKETS @@ -486,7 +489,17 @@ extern char * win32_get_vendorlib(const char *pl, STRLEN *const len); extern void win32_delete_internal_host(void *h); #endif -extern int win32_get_errno(int err); +/* Get the errno value corresponding to the given err. This macro/func is not + * intended to handle conversion of general GetLastError() codes. It only exists + * to translate Windows sockets error codes from WSAGetLastError(). Such codes + * used to be assigned to errno/$! in earlier versions of perl; this function is + * used to catch any old Perl code which is still trying to assign such values + * to $! and convert them to errno values instead. + */ +#ifdef PERL_CORE +# define win32_get_errno(x) convert_wsa_error_to_errno((x)) +extern int convert_wsa_error_to_errno(int err); +#endif extern const char * const staticlinkmodules[]; diff --git a/win32/win32sck.c b/win32/win32sck.c index d9d7f36..531ee2b 100644 --- a/win32/win32sck.c +++ b/win32/win32sck.c @@ -68,263 +68,6 @@ EndSockets(void) WSACleanup(); } -/* Translate WSAExxx values to corresponding Exxx values where possible. Not all - * WSAExxx constants have corresponding Exxx constants in (even in - * VC++ 2010 and above, which have expanded with more values), but - * most missing constants are provided by win32/include/sys/errno2.h. The few - * that are not are returned unchanged. - * - * The list of possible WSAExxx values used here comes from the MSDN page - * titled "Windows Sockets Error Codes". - * - * (Note: Only the WSAExxx values are handled here; other WSAxxx values are - * returned unchanged. The return value normally ends up in errno/$! and at - * the Perl code level may be tested against the Exxx constants exported by - * the Errno and POSIX modules, which have never handled the other WSAxxx - * values themselves, apparently without any ill effect so far.) - */ -int -convert_wsa_error_to_errno(int wsaerr) -{ - switch (wsaerr) { - case WSAEINTR: - return EINTR; - case WSAEBADF: - return EBADF; - case WSAEACCES: - return EACCES; - case WSAEFAULT: - return EFAULT; - case WSAEINVAL: - return EINVAL; - case WSAEMFILE: - return EMFILE; - case WSAEWOULDBLOCK: - return EWOULDBLOCK; - case WSAEINPROGRESS: - return EINPROGRESS; - case WSAEALREADY: - return EALREADY; - case WSAENOTSOCK: - return ENOTSOCK; - case WSAEDESTADDRREQ: - return EDESTADDRREQ; - case WSAEMSGSIZE: - return EMSGSIZE; - case WSAEPROTOTYPE: - return EPROTOTYPE; - case WSAENOPROTOOPT: - return ENOPROTOOPT; - case WSAEPROTONOSUPPORT: - return EPROTONOSUPPORT; - case WSAESOCKTNOSUPPORT: - return ESOCKTNOSUPPORT; - case WSAEOPNOTSUPP: - return EOPNOTSUPP; - case WSAEPFNOSUPPORT: - return EPFNOSUPPORT; - case WSAEAFNOSUPPORT: - return EAFNOSUPPORT; - case WSAEADDRINUSE: - return EADDRINUSE; - case WSAEADDRNOTAVAIL: - return EADDRNOTAVAIL; - case WSAENETDOWN: - return ENETDOWN; - case WSAENETUNREACH: - return ENETUNREACH; - case WSAENETRESET: - return ENETRESET; - case WSAECONNABORTED: - return ECONNABORTED; - case WSAECONNRESET: - return ECONNRESET; - case WSAENOBUFS: - return ENOBUFS; - case WSAEISCONN: - return EISCONN; - case WSAENOTCONN: - return ENOTCONN; - case WSAESHUTDOWN: - return ESHUTDOWN; - case WSAETOOMANYREFS: - return ETOOMANYREFS; - case WSAETIMEDOUT: - return ETIMEDOUT; - case WSAECONNREFUSED: - return ECONNREFUSED; - case WSAELOOP: - return ELOOP; - case WSAENAMETOOLONG: - return ENAMETOOLONG; - case WSAEHOSTDOWN: - return WSAEHOSTDOWN; /* EHOSTDOWN is not defined */ - case WSAEHOSTUNREACH: - return EHOSTUNREACH; - case WSAENOTEMPTY: - return ENOTEMPTY; - case WSAEPROCLIM: - return EPROCLIM; - case WSAEUSERS: - return EUSERS; - case WSAEDQUOT: - return EDQUOT; - case WSAESTALE: - return ESTALE; - case WSAEREMOTE: - return EREMOTE; - case WSAEDISCON: - return WSAEDISCON; /* EDISCON is not defined */ - case WSAENOMORE: - return WSAENOMORE; /* ENOMORE is not defined */ -#ifdef WSAECANCELLED - case WSAECANCELLED: /* New in WinSock2 */ - return ECANCELED; -#endif - case WSAEINVALIDPROCTABLE: - return WSAEINVALIDPROCTABLE; /* EINVALIDPROCTABLE is not defined */ - case WSAEINVALIDPROVIDER: - return WSAEINVALIDPROVIDER; /* EINVALIDPROVIDER is not defined */ - case WSAEPROVIDERFAILEDINIT: - return WSAEPROVIDERFAILEDINIT; /* EPROVIDERFAILEDINIT is not defined */ - case WSAEREFUSED: - return WSAEREFUSED; /* EREFUSED is not defined */ - } - - return wsaerr; -} - -#ifdef ERRNO_HAS_POSIX_SUPPLEMENT -/* Translate Exxx values in the POSIX supplement range defined in VC++ 2010 and - * above (EADDRINUSE <= err <= EWOULDBLOCK) to corresponding WSAExxx values. Not - * all such Exxx constants have corresponding WSAExxx constants in ; - * we just use ERROR_INVALID_FUNCTION for those that are missing but do not - * really expect to encounter them anyway in the context in which this function - * is called. - * Some versions of MinGW/gcc-4.8 and above also define most, but not all, of - * these extra Exxx values. The missing ones are all cases for which there is no - * corresponding WSAExxx constant anyway, so we simply omit the cases for them - * here. - * Other Exxx values (err < sys_nerr) are returned unchanged. - */ -int -convert_errno_to_wsa_error(int err) -{ - switch (err) { - case EADDRINUSE: - return WSAEADDRINUSE; - case EADDRNOTAVAIL: - return WSAEADDRNOTAVAIL; - case EAFNOSUPPORT: - return WSAEAFNOSUPPORT; - case EALREADY: - return WSAEALREADY; -#ifdef EBADMSG - case EBADMSG: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case ECANCELED: -#ifdef WSAECANCELLED - return WSAECANCELLED; /* New in WinSock2 */ -#else - return ERROR_INVALID_FUNCTION; -#endif - case ECONNABORTED: - return WSAECONNABORTED; - case ECONNREFUSED: - return WSAECONNREFUSED; - case ECONNRESET: - return WSAECONNRESET; - case EDESTADDRREQ: - return WSAEDESTADDRREQ; - case EHOSTUNREACH: - return WSAEHOSTUNREACH; -#ifdef EIDRM - case EIDRM: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case EINPROGRESS: - return WSAEINPROGRESS; - case EISCONN: - return WSAEISCONN; - case ELOOP: - return WSAELOOP; - case EMSGSIZE: - return WSAEMSGSIZE; - case ENETDOWN: - return WSAENETDOWN; - case ENETRESET: - return WSAENETRESET; - case ENETUNREACH: - return WSAENETUNREACH; - case ENOBUFS: - return WSAENOBUFS; -#ifdef ENODATA - case ENODATA: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif -#ifdef ENOLINK - case ENOLINK: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif -#ifdef ENOMSG - case ENOMSG: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case ENOPROTOOPT: - return WSAENOPROTOOPT; -#ifdef ENOSR - case ENOSR: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif -#ifdef ENOSTR - case ENOSTR: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case ENOTCONN: - return WSAENOTCONN; -#ifdef ENOTRECOVERABLE - case ENOTRECOVERABLE: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case ENOTSOCK: - return WSAENOTSOCK; - case ENOTSUP: - return ERROR_INVALID_FUNCTION; - case EOPNOTSUPP: - return WSAEOPNOTSUPP; -#ifdef EOTHER - case EOTHER: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case EOVERFLOW: - return ERROR_INVALID_FUNCTION; - case EOWNERDEAD: - return ERROR_INVALID_FUNCTION; - case EPROTO: - return ERROR_INVALID_FUNCTION; - case EPROTONOSUPPORT: - return WSAEPROTONOSUPPORT; - case EPROTOTYPE: - return WSAEPROTOTYPE; -#ifdef ETIME - case ETIME: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case ETIMEDOUT: - return WSAETIMEDOUT; -#ifdef ETXTBSY - case ETXTBSY: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case EWOULDBLOCK: - return WSAEWOULDBLOCK; - } - - return err; -} -#endif /* ERRNO_HAS_POSIX_SUPPLEMENT */ - void start_sockets(void) { -- 2.5.0.windows.1 ```
p5pRT commented 6 years ago

From @steve-m-hay

Thanks for the patch. I applied it to blead (updated version attached since it no longer applies cleanly) but it fails to build for me​:

g++ APItest.def -o ..\..\lib\auto\XS\APItest\APItest.dll -mdll -s -L"c​:\perl\lib\CORE" -L"C​:\Dev\Software\MinGW-w64\x64\7.1.0\lib" APItest.o XSUB-undef-XS_VERSION.o XSUB-redefined-macros.o core.o exception.o notcore.o "..\..\lib\CORE\libperl529.a" -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 -Wl\,--enable-auto-image-base APItest.o​:APItest.c​:(.text+0x5ce5)​: undefined reference to `__imp_Perl_to_utf8_title' APItest.o​:APItest.c​:(.text+0xadd5)​: undefined reference to `__imp_Perl_to_utf8_upper' APItest.o​:APItest.c​:(.text+0xb495)​: undefined reference to `__imp_Perl_to_utf8_fold' APItest.o​:APItest.c​:(.text+0xbd05)​: undefined reference to `__imp_Perl_to_utf8_lower' collect2.exe​: error​: ld returned 1 exit status dmake​: Error code 129\, while making '..\..\lib\auto\XS\APItest\APItest.dll' Unsuccessful make(ext/XS-APItest)​: code=65280 at ..\make_ext.pl line 570. dmake​: Error code 130\, while making 'Extensions'

This is using gcc-7.1.0 x64 from mingw-w64.org. I can provide more details if required\, but this compiler builds blead OK without this patch applied.

p5pRT commented 6 years ago

From @steve-m-hay

0001-remove-Winsock-lib-dep-and-reentr.c-from-Win32-gcc-m.patch ```diff From 9d1f9728b101768ab84b2912c113569dd83006b6 Mon Sep 17 00:00:00 2001 From: Daniel Dragan Date: Tue, 1 May 2018 01:07:50 -0400 Subject: [PATCH] remove Winsock lib dep and reentr.c from Win32 gcc miniperl This commit extends work done in commit 19253ae62c to remove winsock from the gcc miniperl. commit 19253ae62c only removed winsock from VC miniperl. -the gcc linker does NOT remove unrefed non-static functions from final binaries, so ws2_32.dll was still linked inside miniperl by references from dead code that was not eliminated by the linker. To fix this, not compiling win32sck.c and not linking it in seems to be the only solution. Other non perl devs have complained about this on various message boards and were told to use GCC LTO or simply the object file specification is an "all or nothing" file format and the linker "can't" look inside the obj file. Visual C can with its "comdat" attribute that is on by default but Mingw GCC has no analog feature. -func win32_uname, I think exists for XS code to use for posix compatibility, it is completly unused and unreferenced inside miniperl and full perl, but it contains to call to win32_gethostbyname that is inside win32sck.c but now we aren't compiling that, so #ifdef guard away the call to win32_gethostbyname to make it seem like win32_gethostbyname returned NULL. -funcs convert_errno_to_wsa_error and convert_wsa_error_to_errno aka win32_get_errno are int to int lookup tables and do not call other funcs and therefore do not link in ws2_32.dll so move them to win32.c. The alternative would be to not compile them on socketless (mini) perl, but I could imagine some kind of `wget` or `curl` returning 10*** series error codes through stderr and a PP wrapper then assigning the 10*** code to $! even though this perl doesn't have sockets, and thus using the WSA to E* error code translation code, and thus producing an observable difference in that module when run with mini and full perl. -remove win32_get_errno wrapper func and replace with a macro, less indirection machine code wise, I assume "win32_get_errno" was created so the code in win32_get_errno()'s only caller which is Perl_magic_set() in mg.c looks cleaner to non-win32 p5p devs and shows that it is win32 specific -the only caller of convert_errno_to_wsa_error() is in win32.c and now that convert_errno_to_wsa_error() was moved from win32sck.c to win32.c it can be marked static for CC efficiency (CC can inline or non-std calling convention it) -the #define NO_MATHOMS, by itself reduced disk size of miniperl.exe compiled with Mingw64 gcc 4.9.2 from 2190KB to 2177KB -perlapi.o and mathom.o are empty for miniperl, dont even bother to run the CC on them, this saves build time -Win32 API doesn't have *_r family of libc funcs since Win32 API was from day 1 designed to be thread-safe/reentrant, therefore reentr.o has empty stub functions whose only purpose is to export these 4 stubs error LNK2001: unresolved external symbol _Perl_reentrant_free error LNK2001: unresolved external symbol _Perl_reentrant_init error LNK2001: unresolved external symbol _Perl_reentrant_retry error LNK2001: unresolved external symbol _Perl_reentrant_size so just remove the only ref to these 4 funcs and dont compile reentr.c in any build config on win32 anymore. -ifdef out the prototypes and #define Perl_* wrappers for reenterant api so unprotected usage of these 4 funcs breaks more visibly and less symbols inside the CC's identifier DB since they were removed at preproc time -remove PL_reentrant_retint var from interp struct if not using reenterant API since the var isn't used unless we have reenterant APIs to wrap, this saves an int of memory and couple cpu instructions on disk in perl_clone_using -there is additional info in the RT ticket associated with this patch --- embed.fnc | 2 + embed.h | 10 +- intrpvar.h | 2 + makedef.pl | 4 + proto.h | 14 +-- sv.c | 2 + win32/GNUmakefile | 22 +++-- win32/Makefile | 21 +++-- win32/makefile.mk | 22 +++-- win32/win32.c | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++---- win32/win32.h | 15 ++- win32/win32sck.c | 257 ------------------------------------------------- 12 files changed, 338 insertions(+), 311 deletions(-) diff --git a/embed.fnc b/embed.fnc index 1548248038..bc53bd3dc7 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1289,10 +1289,12 @@ p |void |rpeep |NULLOK OP* o : Defined in doio.c, used only in pp_hot.c dopM |PerlIO*|start_glob |NN SV *tmpglob|NN IO *io +#ifdef USE_REENTRANT_API Ap |void |reentrant_size Ap |void |reentrant_init Ap |void |reentrant_free Anp |void* |reentrant_retry|NN const char *f|... +#endif : "Very" special - can't use the O flag for this one: : (The rename from perl_atexit to Perl_call_atexit was in 864dbfa3ca8032ef) diff --git a/embed.h b/embed.h index a2873b9144..9b8dd79dd9 100644 --- a/embed.h +++ b/embed.h @@ -620,10 +620,6 @@ #define re_compile(a,b) Perl_re_compile(aTHX_ a,b) #define re_intuit_start(a,b,c,d,e,f,g) Perl_re_intuit_start(aTHX_ a,b,c,d,e,f,g) #define re_intuit_string(a) Perl_re_intuit_string(aTHX_ a) -#define reentrant_free() Perl_reentrant_free(aTHX) -#define reentrant_init() Perl_reentrant_init(aTHX) -#define reentrant_retry Perl_reentrant_retry -#define reentrant_size() Perl_reentrant_size(aTHX) #define reg_named_buff_all(a,b) Perl_reg_named_buff_all(aTHX_ a,b) #define reg_named_buff_exists(a,b,c) Perl_reg_named_buff_exists(aTHX_ a,b,c) #define reg_named_buff_fetch(a,b,c) Perl_reg_named_buff_fetch(aTHX_ a,b,c) @@ -1077,6 +1073,12 @@ #define quadmath_format_needed Perl_quadmath_format_needed #define quadmath_format_single Perl_quadmath_format_single #endif +#if defined(USE_REENTRANT_API) +#define reentrant_free() Perl_reentrant_free(aTHX) +#define reentrant_init() Perl_reentrant_init(aTHX) +#define reentrant_retry Perl_reentrant_retry +#define reentrant_size() Perl_reentrant_size(aTHX) +#endif #if defined(WIN32) || defined(__SYMBIAN32__) || defined(VMS) #define do_aspawn(a,b,c) Perl_do_aspawn(aTHX_ a,b,c) #define do_spawn(a) Perl_do_spawn(aTHX_ a) diff --git a/intrpvar.h b/intrpvar.h index fad1eaafbb..c419aec127 100644 --- a/intrpvar.h +++ b/intrpvar.h @@ -341,7 +341,9 @@ PERLVAR(I, perldb, U32) PERLVAR(I, signals, U32) /* Using which pre-5.8 signals */ +#ifdef USE_REENTRANT_API PERLVAR(I, reentrant_retint, int) /* Integer return value from reentrant functions */ +#endif /* pseudo environmental stuff */ PERLVAR(I, origargc, int) diff --git a/makedef.pl b/makedef.pl index 661b71de7e..f4e82b4994 100644 --- a/makedef.pl +++ b/makedef.pl @@ -321,6 +321,10 @@ unless ($define{PERL_SAWAMPERSAND}) { unless ($define{'USE_REENTRANT_API'}) { ++$skip{PL_reentrant_buffer}; + ++$skip{Perl_reentrant_free}; + ++$skip{Perl_reentrant_init}; + ++$skip{Perl_reentrant_retry}; + ++$skip{Perl_reentrant_size}; } if ($define{'MYMALLOC'}) { diff --git a/proto.h b/proto.h index b94a47d9fd..a76228556d 100644 --- a/proto.h +++ b/proto.h @@ -2793,12 +2793,6 @@ PERL_CALLCONV REGEXP* Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_cou PERL_CALLCONV Malloc_t Perl_realloc(Malloc_t where, MEM_SIZE nbytes) __attribute__warn_unused_result__; -PERL_CALLCONV void Perl_reentrant_free(pTHX); -PERL_CALLCONV void Perl_reentrant_init(pTHX); -PERL_CALLCONV void* Perl_reentrant_retry(const char *f, ...); -#define PERL_ARGS_ASSERT_REENTRANT_RETRY \ - assert(f) -PERL_CALLCONV void Perl_reentrant_size(pTHX); #ifndef NO_MATHOMS PERL_CALLCONV OP* Perl_ref(pTHX_ OP* o, I32 type); #endif @@ -6492,6 +6486,14 @@ PERL_CALLCONV const char* Perl_quadmath_format_single(const char* format); #define PERL_ARGS_ASSERT_QUADMATH_FORMAT_SINGLE \ assert(format) #endif +#if defined(USE_REENTRANT_API) +PERL_CALLCONV void Perl_reentrant_free(pTHX); +PERL_CALLCONV void Perl_reentrant_init(pTHX); +PERL_CALLCONV void* Perl_reentrant_retry(const char *f, ...); +#define PERL_ARGS_ASSERT_REENTRANT_RETRY \ + assert(f) +PERL_CALLCONV void Perl_reentrant_size(pTHX); +#endif #if defined(WIN32) PERL_CALLCONV_NO_RET void win32_croak_not_implemented(const char * fname) __attribute__noreturn__; diff --git a/sv.c b/sv.c index 92ce540a3c..2bdd94a838 100644 --- a/sv.c +++ b/sv.c @@ -15261,7 +15261,9 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags, /* Not really needed/useful since the reenrant_retint is "volatile", * but do it for consistency's sake. */ +#ifdef USE_REENTRANT_API PL_reentrant_retint = proto_perl->Ireentrant_retint; +#endif /* Hooks to shared SVs and locks. */ PL_sharehook = proto_perl->Isharehook; diff --git a/win32/GNUmakefile b/win32/GNUmakefile index a016a391d2..62c5b8f2a8 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -1029,14 +1029,11 @@ MICROCORE_SRC = \ ..\mro_core.c \ ..\locale.c \ ..\keywords.c \ - ..\mathoms.c \ ..\mg.c \ ..\numeric.c \ ..\pad.c \ - ..\perlapi.c \ ..\perly.c \ ..\pp_sort.c \ - ..\reentr.c \ ..\run.c \ ..\scope.c \ ..\taint.c \ @@ -1044,20 +1041,24 @@ MICROCORE_SRC = \ ..\universal.c \ ..\util.c -EXTRACORE_SRC += perllib.c +EXTRACORE_SRC = \ + perllib.c \ + ..\mathoms.c \ + ..\perlapi.c \ + ..\perlio.c ifeq ($(PERL_MALLOC),define) EXTRACORE_SRC += ..\malloc.c endif -EXTRACORE_SRC += ..\perlio.c - WIN32_SRC = \ .\win32.c \ - .\win32sck.c \ .\win32thread.c \ .\fcrypt.c +WIN32EXTRA_SRC = \ + .\win32sck.c + # We need this for miniperl build unless we override canned # config.h #define building mini\* #ifeq ($(USE_PERLIO)" == "define" @@ -1117,6 +1118,7 @@ HAVE_COREDIR = .coreheaders MICROCORE_OBJ = $(MICROCORE_SRC:.c=$(o)) CORE_OBJ = $(MICROCORE_OBJ) $(EXTRACORE_SRC:.c=$(o)) WIN32_OBJ = $(WIN32_SRC:.c=$(o)) +WIN32EXTRA_OBJ = $(WIN32EXTRA_SRC:.c=$(o)) MINICORE_OBJ = $(subst ..\,mini\,$(MICROCORE_OBJ)) \ $(MINIDIR)\miniperlmain$(o) \ @@ -1129,7 +1131,7 @@ PERLDLL_OBJ = $(CORE_OBJ) PERLEXE_OBJ = perlmain$(o) PERLEXEST_OBJ = perlmainst$(o) -PERLDLL_OBJ += $(WIN32_OBJ) $(DLL_OBJ) +PERLDLL_OBJ += $(WIN32_OBJ) $(WIN32EXTRA_OBJ) $(DLL_OBJ) ifneq ($(USE_SETARGV),) SETARGV_OBJ = setargv$(o) @@ -1502,6 +1504,8 @@ $(MINI_OBJ) : $(MINIDIR)\.exists $(CORE_NOCFG_H) $(WIN32_OBJ) : $(CORE_H) +$(WIN32EXTRA_OBJ): $(CORE_H) + $(CORE_OBJ) : $(CORE_H) $(DLL_OBJ) : $(CORE_H) @@ -1945,7 +1949,7 @@ _clean : -if exist $(UNIDATADIR1) rmdir /s /q $(UNIDATADIR1) -if exist $(UNIDATADIR2) rmdir /s /q $(UNIDATADIR2) -@erase $(UNIDATAFILES) - -@erase $(WIN32_OBJ) + -@erase $(WIN32_OBJ) $(WIN32EXTRA_OBJ) -@erase $(DLL_OBJ) -@erase ..\*$(o) ..\*$(a) ..\*.exp *$(o) *$(a) *.exp *.res -@erase ..\t\*.exe ..\t\*.dll ..\t\*.bat diff --git a/win32/Makefile b/win32/Makefile index 45de6ac0cb..b34d68e838 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -787,13 +787,11 @@ MICROCORE_SRC = \ ..\hv.c \ ..\locale.c \ ..\keywords.c \ - ..\mathoms.c \ ..\mg.c \ ..\numeric.c \ ..\op.c \ ..\pad.c \ ..\perl.c \ - ..\perlapi.c \ ..\perly.c \ ..\pp.c \ ..\pp_ctl.c \ @@ -801,7 +799,6 @@ MICROCORE_SRC = \ ..\pp_pack.c \ ..\pp_sort.c \ ..\pp_sys.c \ - ..\reentr.c \ ..\regcomp.c \ ..\regexec.c \ ..\run.c \ @@ -814,21 +811,25 @@ MICROCORE_SRC = \ ..\utf8.c \ ..\util.c -EXTRACORE_SRC = $(EXTRACORE_SRC) perllib.c +EXTRACORE_SRC = \ + perllib.c \ + ..\mathoms.c \ + ..\perlapi.c \ + ..\perlio.c !IF "$(PERL_MALLOC)" == "define" EXTRACORE_SRC = $(EXTRACORE_SRC) ..\malloc.c !ENDIF -EXTRACORE_SRC = $(EXTRACORE_SRC) ..\perlio.c - WIN32_SRC = \ .\win32.c \ .\win32io.c \ - .\win32sck.c \ .\win32thread.c \ .\fcrypt.c +WIN32EXTRA_SRC = \ + .\win32sck.c + CORE_NOCFG_H = \ ..\av.h \ ..\cop.h \ @@ -880,6 +881,7 @@ GENERATED_HEADERS = $(UUDMAP_H) $(BITCOUNT_H) $(MG_DATA_H) MICROCORE_OBJ = $(MICROCORE_SRC:.c=.obj) CORE_OBJ = $(MICROCORE_OBJ) $(EXTRACORE_SRC:.c=.obj) WIN32_OBJ = $(WIN32_SRC:.c=.obj) +WIN32EXTRA_OBJ = $(WIN32EXTRA_SRC:.c=.obj) MINICORE_OBJ = $(MICROCORE_OBJ:..\=.\mini\) \ $(MINIDIR)\miniperlmain$(o) \ $(MINIDIR)\perlio$(o) @@ -892,7 +894,7 @@ PERLDLL_OBJ = $(CORE_OBJ) PERLEXE_OBJ = perlmain$(o) PERLEXEST_OBJ = perlmainst$(o) -PERLDLL_OBJ = $(PERLDLL_OBJ) $(WIN32_OBJ) $(DLL_OBJ) +PERLDLL_OBJ = $(PERLDLL_OBJ) $(WIN32_OBJ) $(WIN32EXTRA_OBJ) $(DLL_OBJ) !IF "$(USE_SETARGV)" != "" SETARGV_OBJ = setargv$(o) @@ -1140,6 +1142,7 @@ perllib$(o) : perllib.c .\perlhost.h .\vdir.h .\vmem.h $(MINI_OBJ) : $(MINIDIR)\.exists $(CORE_NOCFG_H) $(WIN32_OBJ) : $(CORE_H) +$(WIN32EXTRA_OBJ): $(CORE_H) $(CORE_OBJ) : $(CORE_H) $(DLL_OBJ) : $(CORE_H) @@ -1514,7 +1517,7 @@ _clean : -if exist $(UNIDATADIR1) rmdir /s /q $(UNIDATADIR1) -if exist $(UNIDATADIR2) rmdir /s /q $(UNIDATADIR2) -@$(DEL) $(UNIDATAFILES) - -@$(DEL) $(WIN32_OBJ) + -@$(DEL) $(WIN32_OBJ) $(WIN32EXTRA_OBJ) -@$(DEL) $(DLL_OBJ) -@$(DEL) ..\*$(o) ..\*.lib ..\*.exp *$(o) *.lib *.exp *.res -@$(DEL) ..\t\*.exe ..\t\*.dll ..\t\*.bat diff --git a/win32/makefile.mk b/win32/makefile.mk index f84fc538fd..50cb85f76b 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -1013,14 +1013,11 @@ MICROCORE_SRC = \ ..\mro_core.c \ ..\locale.c \ ..\keywords.c \ - ..\mathoms.c \ ..\mg.c \ ..\numeric.c \ ..\pad.c \ - ..\perlapi.c \ ..\perly.c \ ..\pp_sort.c \ - ..\reentr.c \ ..\run.c \ ..\scope.c \ ..\taint.c \ @@ -1028,21 +1025,27 @@ MICROCORE_SRC = \ ..\universal.c \ ..\util.c -EXTRACORE_SRC += perllib.c +EXTRACORE_SRC = \ + perllib.c \ + ..\mathoms.c \ + ..\perlapi.c \ + ..\perlio.c .IF "$(PERL_MALLOC)" == "define" EXTRACORE_SRC += ..\malloc.c .ENDIF -EXTRACORE_SRC += ..\perlio.c + WIN32_SRC = \ .\win32.c \ .\win32io.c \ - .\win32sck.c \ .\win32thread.c \ .\fcrypt.c +WIN32EXTRA_SRC = \ + .\win32sck.c + CORE_NOCFG_H = \ ..\av.h \ ..\cop.h \ @@ -1096,6 +1099,7 @@ HAVE_COREDIR = .\.coreheaders MICROCORE_OBJ = $(MICROCORE_SRC:db:+$(o)) CORE_OBJ = $(MICROCORE_OBJ) $(EXTRACORE_SRC:db:+$(o)) WIN32_OBJ = $(WIN32_SRC:db:+$(o)) +WIN32EXTRA_OBJ = $(WIN32EXTRA_SRC:db:+$(o)) MINICORE_OBJ = $(MINIDIR)\{$(MICROCORE_OBJ:f) miniperlmain$(o) perlio$(o)} MINIWIN32_OBJ = $(MINIDIR)\{$(WIN32_OBJ:f)} MINI_OBJ = $(MINICORE_OBJ) $(MINIWIN32_OBJ) @@ -1105,7 +1109,7 @@ PERLDLL_OBJ = $(CORE_OBJ) PERLEXE_OBJ = perlmain$(o) PERLEXEST_OBJ = perlmainst$(o) -PERLDLL_OBJ += $(WIN32_OBJ) $(DLL_OBJ) +PERLDLL_OBJ += $(WIN32_OBJ) $(WIN32EXTRA_OBJ) $(DLL_OBJ) .IF "$(USE_SETARGV)" != "" SETARGV_OBJ = setargv$(o) @@ -1472,6 +1476,8 @@ $(MINI_OBJ) : $(MINIDIR)\.exists $(CORE_NOCFG_H) $(WIN32_OBJ) : $(CORE_H) +$(WIN32EXTRA_OBJ): $(CORE_H) + $(CORE_OBJ) : $(CORE_H) $(DLL_OBJ) : $(CORE_H) @@ -1904,7 +1910,7 @@ _clean : -if exist $(UNIDATADIR1) rmdir /s /q $(UNIDATADIR1) -if exist $(UNIDATADIR2) rmdir /s /q $(UNIDATADIR2) -@erase $(UNIDATAFILES) - -@erase $(WIN32_OBJ) + -@erase $(WIN32_OBJ) $(WIN32EXTRA_OBJ) -@erase $(DLL_OBJ) -@erase ..\*$(o) ..\*$(a) ..\*.exp *$(o) *$(a) *.exp *.res -@erase ..\t\*.exe ..\t\*.dll ..\t\*.bat diff --git a/win32/win32.c b/win32/win32.c index c7656c631b..6abed0680c 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2056,7 +2056,9 @@ win32_gettimeofday(struct timeval *tp, void *not_used) DllExport int win32_uname(struct utsname *name) { +#ifdef HAS_GETHOSTBYNAME struct hostent *hep; +#endif STRLEN nodemax = sizeof(name->nodename)-1; /* sysname */ @@ -2088,6 +2090,7 @@ win32_uname(struct utsname *name) sprintf(buf, " (%s)", g_osver.szCSDVersion); } +#ifdef HAS_GETHOSTBYNAME /* nodename */ hep = win32_gethostbyname("localhost"); if (hep) { @@ -2100,7 +2103,9 @@ win32_uname(struct utsname *name) name->nodename[nodemax] = '\0'; } } - else { + else +#endif + { DWORD sz = nodemax; if (!GetComputerName(name->nodename, &sz)) *name->nodename = '\0'; @@ -2549,21 +2554,6 @@ win32_flock(int fd, int oper) #undef LK_LEN -extern int convert_wsa_error_to_errno(int wsaerr); /* in win32sck.c */ - -/* Get the errno value corresponding to the given err. This function is not - * intended to handle conversion of general GetLastError() codes. It only exists - * to translate Windows sockets error codes from WSAGetLastError(). Such codes - * used to be assigned to errno/$! in earlier versions of perl; this function is - * used to catch any old Perl code which is still trying to assign such values - * to $! and convert them to errno values instead. - */ -int -win32_get_errno(int err) -{ - return convert_wsa_error_to_errno(err); -} - /* * redirected io subsystem for all XS modules * @@ -2613,9 +2603,263 @@ win32_feof(FILE *fp) return (feof(fp)); } +/* Translate WSAExxx values to corresponding Exxx values where possible. Not all + * WSAExxx constants have corresponding Exxx constants in (even in + * VC++ 2010 and above, which have expanded with more values), but + * most missing constants are provided by win32/include/sys/errno2.h. The few + * that are not are returned unchanged. + * + * The list of possible WSAExxx values used here comes from the MSDN page + * titled "Windows Sockets Error Codes". + * + * (Note: Only the WSAExxx values are handled here; other WSAxxx values are + * returned unchanged. The return value normally ends up in errno/$! and at + * the Perl code level may be tested against the Exxx constants exported by + * the Errno and POSIX modules, which have never handled the other WSAxxx + * values themselves, apparently without any ill effect so far.) + */ +int +convert_wsa_error_to_errno(int wsaerr) +{ + switch (wsaerr) { + case WSAEINTR: + return EINTR; + case WSAEBADF: + return EBADF; + case WSAEACCES: + return EACCES; + case WSAEFAULT: + return EFAULT; + case WSAEINVAL: + return EINVAL; + case WSAEMFILE: + return EMFILE; + case WSAEWOULDBLOCK: + return EWOULDBLOCK; + case WSAEINPROGRESS: + return EINPROGRESS; + case WSAEALREADY: + return EALREADY; + case WSAENOTSOCK: + return ENOTSOCK; + case WSAEDESTADDRREQ: + return EDESTADDRREQ; + case WSAEMSGSIZE: + return EMSGSIZE; + case WSAEPROTOTYPE: + return EPROTOTYPE; + case WSAENOPROTOOPT: + return ENOPROTOOPT; + case WSAEPROTONOSUPPORT: + return EPROTONOSUPPORT; + case WSAESOCKTNOSUPPORT: + return ESOCKTNOSUPPORT; + case WSAEOPNOTSUPP: + return EOPNOTSUPP; + case WSAEPFNOSUPPORT: + return EPFNOSUPPORT; + case WSAEAFNOSUPPORT: + return EAFNOSUPPORT; + case WSAEADDRINUSE: + return EADDRINUSE; + case WSAEADDRNOTAVAIL: + return EADDRNOTAVAIL; + case WSAENETDOWN: + return ENETDOWN; + case WSAENETUNREACH: + return ENETUNREACH; + case WSAENETRESET: + return ENETRESET; + case WSAECONNABORTED: + return ECONNABORTED; + case WSAECONNRESET: + return ECONNRESET; + case WSAENOBUFS: + return ENOBUFS; + case WSAEISCONN: + return EISCONN; + case WSAENOTCONN: + return ENOTCONN; + case WSAESHUTDOWN: + return ESHUTDOWN; + case WSAETOOMANYREFS: + return ETOOMANYREFS; + case WSAETIMEDOUT: + return ETIMEDOUT; + case WSAECONNREFUSED: + return ECONNREFUSED; + case WSAELOOP: + return ELOOP; + case WSAENAMETOOLONG: + return ENAMETOOLONG; + case WSAEHOSTDOWN: + return WSAEHOSTDOWN; /* EHOSTDOWN is not defined */ + case WSAEHOSTUNREACH: + return EHOSTUNREACH; + case WSAENOTEMPTY: + return ENOTEMPTY; + case WSAEPROCLIM: + return EPROCLIM; + case WSAEUSERS: + return EUSERS; + case WSAEDQUOT: + return EDQUOT; + case WSAESTALE: + return ESTALE; + case WSAEREMOTE: + return EREMOTE; + case WSAEDISCON: + return WSAEDISCON; /* EDISCON is not defined */ + case WSAENOMORE: + return WSAENOMORE; /* ENOMORE is not defined */ +#ifdef WSAECANCELLED + case WSAECANCELLED: /* New in WinSock2 */ + return ECANCELED; +#endif + case WSAEINVALIDPROCTABLE: + return WSAEINVALIDPROCTABLE; /* EINVALIDPROCTABLE is not defined */ + case WSAEINVALIDPROVIDER: + return WSAEINVALIDPROVIDER; /* EINVALIDPROVIDER is not defined */ + case WSAEPROVIDERFAILEDINIT: + return WSAEPROVIDERFAILEDINIT; /* EPROVIDERFAILEDINIT is not defined */ + case WSAEREFUSED: + return WSAEREFUSED; /* EREFUSED is not defined */ + } + + return wsaerr; +} + #ifdef ERRNO_HAS_POSIX_SUPPLEMENT -extern int convert_errno_to_wsa_error(int err); /* in win32sck.c */ +/* Translate Exxx values in the POSIX supplement range defined in VC++ 2010 and + * above (EADDRINUSE <= err <= EWOULDBLOCK) to corresponding WSAExxx values. Not + * all such Exxx constants have corresponding WSAExxx constants in ; + * we just use ERROR_INVALID_FUNCTION for those that are missing but do not + * really expect to encounter them anyway in the context in which this function + * is called. + * Some versions of MinGW/gcc-4.8 and above also define most, but not all, of + * these extra Exxx values. The missing ones are all cases for which there is no + * corresponding WSAExxx constant anyway, so we simply omit the cases for them + * here. + * Other Exxx values (err < sys_nerr) are returned unchanged. + */ +static int +convert_errno_to_wsa_error(int err) +{ + switch (err) { + case EADDRINUSE: + return WSAEADDRINUSE; + case EADDRNOTAVAIL: + return WSAEADDRNOTAVAIL; + case EAFNOSUPPORT: + return WSAEAFNOSUPPORT; + case EALREADY: + return WSAEALREADY; +#ifdef EBADMSG + case EBADMSG: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case ECANCELED: +#ifdef WSAECANCELLED + return WSAECANCELLED; /* New in WinSock2 */ +#else + return ERROR_INVALID_FUNCTION; +#endif + case ECONNABORTED: + return WSAECONNABORTED; + case ECONNREFUSED: + return WSAECONNREFUSED; + case ECONNRESET: + return WSAECONNRESET; + case EDESTADDRREQ: + return WSAEDESTADDRREQ; + case EHOSTUNREACH: + return WSAEHOSTUNREACH; +#ifdef EIDRM + case EIDRM: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case EINPROGRESS: + return WSAEINPROGRESS; + case EISCONN: + return WSAEISCONN; + case ELOOP: + return WSAELOOP; + case EMSGSIZE: + return WSAEMSGSIZE; + case ENETDOWN: + return WSAENETDOWN; + case ENETRESET: + return WSAENETRESET; + case ENETUNREACH: + return WSAENETUNREACH; + case ENOBUFS: + return WSAENOBUFS; +#ifdef ENODATA + case ENODATA: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif +#ifdef ENOLINK + case ENOLINK: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif +#ifdef ENOMSG + case ENOMSG: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case ENOPROTOOPT: + return WSAENOPROTOOPT; +#ifdef ENOSR + case ENOSR: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; #endif +#ifdef ENOSTR + case ENOSTR: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case ENOTCONN: + return WSAENOTCONN; +#ifdef ENOTRECOVERABLE + case ENOTRECOVERABLE: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case ENOTSOCK: + return WSAENOTSOCK; + case ENOTSUP: + return ERROR_INVALID_FUNCTION; + case EOPNOTSUPP: + return WSAEOPNOTSUPP; +#ifdef EOTHER + case EOTHER: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case EOVERFLOW: + return ERROR_INVALID_FUNCTION; + case EOWNERDEAD: + return ERROR_INVALID_FUNCTION; + case EPROTO: + return ERROR_INVALID_FUNCTION; + case EPROTONOSUPPORT: + return WSAEPROTONOSUPPORT; + case EPROTOTYPE: + return WSAEPROTOTYPE; +#ifdef ETIME + case ETIME: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case ETIMEDOUT: + return WSAETIMEDOUT; +#ifdef ETXTBSY + case ETXTBSY: /* Not defined in gcc-4.8.0 */ + return ERROR_INVALID_FUNCTION; +#endif + case EWOULDBLOCK: + return WSAEWOULDBLOCK; + } + + return err; +} +#endif /* ERRNO_HAS_POSIX_SUPPLEMENT */ + /* * Since the errors returned by the socket error function diff --git a/win32/win32.h b/win32/win32.h index ee1d889851..361599a722 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -29,6 +29,9 @@ /* allow minitest to work */ # define PERL_TEXTMODE_SCRIPTS + +/* dont compile mathom funcs when miniperl doesn't load XS */ +# define NO_MATHOMS #endif #ifdef WIN32_NO_SOCKETS @@ -484,7 +487,17 @@ extern char * win32_get_vendorlib(const char *pl, STRLEN *const len); extern void win32_delete_internal_host(void *h); #endif -extern int win32_get_errno(int err); +/* Get the errno value corresponding to the given err. This macro/func is not + * intended to handle conversion of general GetLastError() codes. It only exists + * to translate Windows sockets error codes from WSAGetLastError(). Such codes + * used to be assigned to errno/$! in earlier versions of perl; this function is + * used to catch any old Perl code which is still trying to assign such values + * to $! and convert them to errno values instead. + */ +#ifdef PERL_CORE +# define win32_get_errno(x) convert_wsa_error_to_errno((x)) +extern int convert_wsa_error_to_errno(int err); +#endif extern const char * const staticlinkmodules[]; diff --git a/win32/win32sck.c b/win32/win32sck.c index d9d7f3692b..531ee2b035 100644 --- a/win32/win32sck.c +++ b/win32/win32sck.c @@ -68,263 +68,6 @@ EndSockets(void) WSACleanup(); } -/* Translate WSAExxx values to corresponding Exxx values where possible. Not all - * WSAExxx constants have corresponding Exxx constants in (even in - * VC++ 2010 and above, which have expanded with more values), but - * most missing constants are provided by win32/include/sys/errno2.h. The few - * that are not are returned unchanged. - * - * The list of possible WSAExxx values used here comes from the MSDN page - * titled "Windows Sockets Error Codes". - * - * (Note: Only the WSAExxx values are handled here; other WSAxxx values are - * returned unchanged. The return value normally ends up in errno/$! and at - * the Perl code level may be tested against the Exxx constants exported by - * the Errno and POSIX modules, which have never handled the other WSAxxx - * values themselves, apparently without any ill effect so far.) - */ -int -convert_wsa_error_to_errno(int wsaerr) -{ - switch (wsaerr) { - case WSAEINTR: - return EINTR; - case WSAEBADF: - return EBADF; - case WSAEACCES: - return EACCES; - case WSAEFAULT: - return EFAULT; - case WSAEINVAL: - return EINVAL; - case WSAEMFILE: - return EMFILE; - case WSAEWOULDBLOCK: - return EWOULDBLOCK; - case WSAEINPROGRESS: - return EINPROGRESS; - case WSAEALREADY: - return EALREADY; - case WSAENOTSOCK: - return ENOTSOCK; - case WSAEDESTADDRREQ: - return EDESTADDRREQ; - case WSAEMSGSIZE: - return EMSGSIZE; - case WSAEPROTOTYPE: - return EPROTOTYPE; - case WSAENOPROTOOPT: - return ENOPROTOOPT; - case WSAEPROTONOSUPPORT: - return EPROTONOSUPPORT; - case WSAESOCKTNOSUPPORT: - return ESOCKTNOSUPPORT; - case WSAEOPNOTSUPP: - return EOPNOTSUPP; - case WSAEPFNOSUPPORT: - return EPFNOSUPPORT; - case WSAEAFNOSUPPORT: - return EAFNOSUPPORT; - case WSAEADDRINUSE: - return EADDRINUSE; - case WSAEADDRNOTAVAIL: - return EADDRNOTAVAIL; - case WSAENETDOWN: - return ENETDOWN; - case WSAENETUNREACH: - return ENETUNREACH; - case WSAENETRESET: - return ENETRESET; - case WSAECONNABORTED: - return ECONNABORTED; - case WSAECONNRESET: - return ECONNRESET; - case WSAENOBUFS: - return ENOBUFS; - case WSAEISCONN: - return EISCONN; - case WSAENOTCONN: - return ENOTCONN; - case WSAESHUTDOWN: - return ESHUTDOWN; - case WSAETOOMANYREFS: - return ETOOMANYREFS; - case WSAETIMEDOUT: - return ETIMEDOUT; - case WSAECONNREFUSED: - return ECONNREFUSED; - case WSAELOOP: - return ELOOP; - case WSAENAMETOOLONG: - return ENAMETOOLONG; - case WSAEHOSTDOWN: - return WSAEHOSTDOWN; /* EHOSTDOWN is not defined */ - case WSAEHOSTUNREACH: - return EHOSTUNREACH; - case WSAENOTEMPTY: - return ENOTEMPTY; - case WSAEPROCLIM: - return EPROCLIM; - case WSAEUSERS: - return EUSERS; - case WSAEDQUOT: - return EDQUOT; - case WSAESTALE: - return ESTALE; - case WSAEREMOTE: - return EREMOTE; - case WSAEDISCON: - return WSAEDISCON; /* EDISCON is not defined */ - case WSAENOMORE: - return WSAENOMORE; /* ENOMORE is not defined */ -#ifdef WSAECANCELLED - case WSAECANCELLED: /* New in WinSock2 */ - return ECANCELED; -#endif - case WSAEINVALIDPROCTABLE: - return WSAEINVALIDPROCTABLE; /* EINVALIDPROCTABLE is not defined */ - case WSAEINVALIDPROVIDER: - return WSAEINVALIDPROVIDER; /* EINVALIDPROVIDER is not defined */ - case WSAEPROVIDERFAILEDINIT: - return WSAEPROVIDERFAILEDINIT; /* EPROVIDERFAILEDINIT is not defined */ - case WSAEREFUSED: - return WSAEREFUSED; /* EREFUSED is not defined */ - } - - return wsaerr; -} - -#ifdef ERRNO_HAS_POSIX_SUPPLEMENT -/* Translate Exxx values in the POSIX supplement range defined in VC++ 2010 and - * above (EADDRINUSE <= err <= EWOULDBLOCK) to corresponding WSAExxx values. Not - * all such Exxx constants have corresponding WSAExxx constants in ; - * we just use ERROR_INVALID_FUNCTION for those that are missing but do not - * really expect to encounter them anyway in the context in which this function - * is called. - * Some versions of MinGW/gcc-4.8 and above also define most, but not all, of - * these extra Exxx values. The missing ones are all cases for which there is no - * corresponding WSAExxx constant anyway, so we simply omit the cases for them - * here. - * Other Exxx values (err < sys_nerr) are returned unchanged. - */ -int -convert_errno_to_wsa_error(int err) -{ - switch (err) { - case EADDRINUSE: - return WSAEADDRINUSE; - case EADDRNOTAVAIL: - return WSAEADDRNOTAVAIL; - case EAFNOSUPPORT: - return WSAEAFNOSUPPORT; - case EALREADY: - return WSAEALREADY; -#ifdef EBADMSG - case EBADMSG: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case ECANCELED: -#ifdef WSAECANCELLED - return WSAECANCELLED; /* New in WinSock2 */ -#else - return ERROR_INVALID_FUNCTION; -#endif - case ECONNABORTED: - return WSAECONNABORTED; - case ECONNREFUSED: - return WSAECONNREFUSED; - case ECONNRESET: - return WSAECONNRESET; - case EDESTADDRREQ: - return WSAEDESTADDRREQ; - case EHOSTUNREACH: - return WSAEHOSTUNREACH; -#ifdef EIDRM - case EIDRM: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case EINPROGRESS: - return WSAEINPROGRESS; - case EISCONN: - return WSAEISCONN; - case ELOOP: - return WSAELOOP; - case EMSGSIZE: - return WSAEMSGSIZE; - case ENETDOWN: - return WSAENETDOWN; - case ENETRESET: - return WSAENETRESET; - case ENETUNREACH: - return WSAENETUNREACH; - case ENOBUFS: - return WSAENOBUFS; -#ifdef ENODATA - case ENODATA: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif -#ifdef ENOLINK - case ENOLINK: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif -#ifdef ENOMSG - case ENOMSG: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case ENOPROTOOPT: - return WSAENOPROTOOPT; -#ifdef ENOSR - case ENOSR: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif -#ifdef ENOSTR - case ENOSTR: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case ENOTCONN: - return WSAENOTCONN; -#ifdef ENOTRECOVERABLE - case ENOTRECOVERABLE: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case ENOTSOCK: - return WSAENOTSOCK; - case ENOTSUP: - return ERROR_INVALID_FUNCTION; - case EOPNOTSUPP: - return WSAEOPNOTSUPP; -#ifdef EOTHER - case EOTHER: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case EOVERFLOW: - return ERROR_INVALID_FUNCTION; - case EOWNERDEAD: - return ERROR_INVALID_FUNCTION; - case EPROTO: - return ERROR_INVALID_FUNCTION; - case EPROTONOSUPPORT: - return WSAEPROTONOSUPPORT; - case EPROTOTYPE: - return WSAEPROTOTYPE; -#ifdef ETIME - case ETIME: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case ETIMEDOUT: - return WSAETIMEDOUT; -#ifdef ETXTBSY - case ETXTBSY: /* Not defined in gcc-4.8.0 */ - return ERROR_INVALID_FUNCTION; -#endif - case EWOULDBLOCK: - return WSAEWOULDBLOCK; - } - - return err; -} -#endif /* ERRNO_HAS_POSIX_SUPPLEMENT */ - void start_sockets(void) { -- 2.15.1.windows.2 ```
p5pRT commented 6 years ago

The RT System itself - Status changed from 'new' to 'open'

jkeenan commented 2 years ago

@steve-m-hay, @bulk88 : Is this ticket closable?