This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Win32 miniperl: delay loading for Winsock, and then remove it
authorDaniel Dragan <bulk88@hotmail.com>
Sat, 13 Oct 2012 23:37:33 +0000 (19:37 -0400)
committerSteve Hay <steve.m.hay@googlemail.com>
Wed, 31 Oct 2012 13:31:45 +0000 (13:31 +0000)
Slim down the image and speed up start up time for Win32 miniperl by
removing Winsock. Also if the build process on Win32 in the future
requires sockets, commenting one line in win32.h will turn sockets back on
for miniperl, but this time with delay loading on VC Perl. The only casulty
of no sockets for Win32 miniperl was figuring out the computer's name in
win32/config_sh.PL. A workaround by using an ENV var was implemented. The
purpose of this commit is to speed up the build process of Perl.

As said in the comment in win32.h, the WIN32_NO_SOCKETS macro is
incomplete in implementation. It is only removed winsock from being linked
in in miniperl, not full Perl. PERL_IMPLICIT_SYS (specifically PerlSock in
win32/perlhost.h) and makedef.pl's hard coded list of win32_* function
exports cause winsock to still be linked in with even with
WIN32_NO_SOCKETS on full perl. Both PERL_IMPLICIT_SYS (win32/perlhost.h)
and makedef.pl would require changes to remove winsock from being linked
in on full perl in the future.

win32/Makefile
win32/config_sh.PL
win32/makefile.mk
win32/win32.c
win32/win32.h
win32/win32sck.c

index 7a8f96d..40c6768 100644 (file)
@@ -957,7 +957,7 @@ $(CONFIGPM) : $(MINIPERL) ..\config.sh config_h.PL ..\minimod.pl
 
 $(MINIPERL) : $(MINIDIR) $(MINI_OBJ)
        $(LINK32) -subsystem:console -out:$@ @<<
 
 $(MINIPERL) : $(MINIDIR) $(MINI_OBJ)
        $(LINK32) -subsystem:console -out:$@ @<<
-       $(LINK_FLAGS) $(LIBFILES) $(MINI_OBJ)
+       $(LINK_FLAGS) $(DELAYLOAD) $(LIBFILES) $(MINI_OBJ)
 <<
        $(EMBED_EXE_MANI)
 
 <<
        $(EMBED_EXE_MANI)
 
index 3733c47..d866f76 100644 (file)
@@ -103,8 +103,12 @@ if (exists $opt{cc}) {
 }
 
 $opt{cf_by} = $ENV{USERNAME} unless $opt{cf_by};
 }
 
 $opt{cf_by} = $ENV{USERNAME} unless $opt{cf_by};
-$opt{cf_email} = $opt{cf_by} . '@' . (gethostbyname('localhost'))[0]
-       unless $opt{cf_email};
+if (!$opt{cf_email}) {
+    my $computername = eval{(gethostbyname('localhost'))[0]};
+# gethostbyname might not be implemented in miniperl
+    $computername = $ENV{COMPUTERNAME} if $@;    
+    $opt{cf_email} = $opt{cf_by} . '@' . $computername;
+}
 $opt{usemymalloc} = 'y' if $opt{d_mymalloc} eq 'define';
 
 $opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
 $opt{usemymalloc} = 'y' if $opt{d_mymalloc} eq 'define';
 
 $opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
index 2905cd6..aa3b880 100644 (file)
@@ -1086,7 +1086,7 @@ $(MINIPERL) : $(MINIDIR) $(MINI_OBJ) $(CRTIPMLIBS)
            $(mktmp $(LKPRE) $(MINI_OBJ) $(LIBFILES) $(LKPOST))
 .ELSE
        $(LINK32) -subsystem:console -out:$@ $(BLINK_FLAGS) \
            $(mktmp $(LKPRE) $(MINI_OBJ) $(LIBFILES) $(LKPOST))
 .ELSE
        $(LINK32) -subsystem:console -out:$@ $(BLINK_FLAGS) \
-           @$(mktmp $(LIBFILES) $(MINI_OBJ))
+           @$(mktmp $(DELAYLOAD) $(LIBFILES) $(MINI_OBJ))
        $(EMBED_EXE_MANI)
 .ENDIF
 
        $(EMBED_EXE_MANI)
 .ENDIF
 
index bfc02fd..5a932ca 100644 (file)
@@ -2726,7 +2726,11 @@ win32_freopen(const char *path, const char *mode, FILE *stream)
 DllExport int
 win32_fclose(FILE *pf)
 {
 DllExport int
 win32_fclose(FILE *pf)
 {
+#ifdef WIN32_NO_SOCKETS
+    return fclose(pf);
+#else
     return my_fclose(pf);      /* defined in win32sck.c */
     return my_fclose(pf);      /* defined in win32sck.c */
+#endif
 }
 
 DllExport int
 }
 
 DllExport int
@@ -3245,7 +3249,11 @@ extern int my_close(int);        /* in win32sck.c */
 DllExport int
 win32_close(int fd)
 {
 DllExport int
 win32_close(int fd)
 {
+#ifdef WIN32_NO_SOCKETS
+    return close(fd);
+#else
     return my_close(fd);
     return my_close(fd);
+#endif
 }
 
 DllExport int
 }
 
 DllExport int
index 0474c61..3065867 100644 (file)
 #  define _WIN32_WINNT 0x0500     /* needed for CreateHardlink() etc. */
 #endif
 
 #  define _WIN32_WINNT 0x0500     /* needed for CreateHardlink() etc. */
 #endif
 
+#ifdef PERL_IS_MINIPERL
+/* this macro will remove Winsock only on miniperl, PERL_IMPLICIT_SYS and
+ * makedef.pl create dependencies that will keep Winsock linked in even with
+ * this macro defined, even though sockets will be umimplemented from a script
+ * level in full perl
+ */
+#  define WIN32_NO_SOCKETS
+#endif
+
+#ifdef WIN32_NO_SOCKETS
+#  undef HAS_SOCKET
+#  undef HAS_GETPROTOBYNAME
+#  undef HAS_GETPROTOBYNUMBER
+#  undef HAS_GETPROTOENT
+#  undef HAS_GETNETBYNAME
+#  undef HAS_GETNETBYADDR
+#  undef HAS_GETNETENT
+#  undef HAS_GETSERVBYNAME
+#  undef HAS_GETSERVBYPORT
+#  undef HAS_GETSERVENT
+#  undef HAS_GETHOSTBYNAME
+#  undef HAS_GETHOSTBYADDR
+#  undef HAS_GETHOSTENT
+#  undef HAS_SELECT
+#  undef HAS_IOCTL
+#  undef HAS_NTOHL
+#  undef HAS_HTONL
+#  undef HAS_HTONS
+#  undef HAS_NTOHS
+#  define WIN32SCK_IS_STDSCK
+#endif
+
 #if defined(PERL_IMPLICIT_SYS)
 #  define DYNAMIC_ENV_FETCH
 #  define HAS_GETENV_LEN
 #if defined(PERL_IMPLICIT_SYS)
 #  define DYNAMIC_ENV_FETCH
 #  define HAS_GETENV_LEN
@@ -166,8 +198,10 @@ struct utsname {
 #define  OP_BINARY     O_BINARY        /* mistake in in pp_sys.c? */
 
 /* read() and write() aren't transparent for socket handles */
 #define  OP_BINARY     O_BINARY        /* mistake in in pp_sys.c? */
 
 /* read() and write() aren't transparent for socket handles */
-#define PERL_SOCK_SYSREAD_IS_RECV
-#define PERL_SOCK_SYSWRITE_IS_SEND
+#ifndef WIN32_NO_SOCKETS
+#  define PERL_SOCK_SYSREAD_IS_RECV
+#  define PERL_SOCK_SYSWRITE_IS_SEND
+#endif
 
 #define PERL_NO_FORCE_LINK             /* no need for PL_force_link_funcs */
 
 
 #define PERL_NO_FORCE_LINK             /* no need for PL_force_link_funcs */
 
index 479d99e..9032a6d 100644 (file)
@@ -82,31 +82,50 @@ start_sockets(void)
     wsock_started = 1;
 }
 
     wsock_started = 1;
 }
 
+/* in no sockets Win32 builds, this fowards to replacements in util.c, dTHX
+ * is required
+ */
 u_long
 win32_htonl(u_long hostlong)
 {
 u_long
 win32_htonl(u_long hostlong)
 {
+#ifdef MYSWAP
+    dTHX;
+#else
     StartSockets();
     StartSockets();
+#endif
     return htonl(hostlong);
 }
 
 u_short
 win32_htons(u_short hostshort)
 {
     return htonl(hostlong);
 }
 
 u_short
 win32_htons(u_short hostshort)
 {
+#ifdef MYSWAP
+    dTHX;
+#else
     StartSockets();
     StartSockets();
+#endif
     return htons(hostshort);
 }
 
 u_long
 win32_ntohl(u_long netlong)
 {
     return htons(hostshort);
 }
 
 u_long
 win32_ntohl(u_long netlong)
 {
+#ifdef MYSWAP
+    dTHX;
+#else
     StartSockets();
     StartSockets();
+#endif
     return ntohl(netlong);
 }
 
 u_short
 win32_ntohs(u_short netshort)
 {
     return ntohl(netlong);
 }
 
 u_short
 win32_ntohs(u_short netshort)
 {
+#ifdef MYSWAP
+    dTHX;
+#else
     StartSockets();
     StartSockets();
+#endif
     return ntohs(netshort);
 }
 
     return ntohs(netshort);
 }