summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorDaniel Dragan <bulk88@hotmail.com>2012-10-13 19:37:33 -0400
committerSteve Hay <steve.m.hay@googlemail.com>2012-10-31 13:31:45 +0000
commit19253ae62cd130797cb3e42f196ac26a6417e08c (patch)
tree84be33f7f26ce913616ca62c47e66abacdba0665 /win32
parent5c26a17602c4585ca111bd154f6c65c681cd0572 (diff)
downloadperl-19253ae62cd130797cb3e42f196ac26a6417e08c.tar.gz
Win32 miniperl: delay loading for Winsock, and then remove it
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.
Diffstat (limited to 'win32')
-rw-r--r--win32/Makefile2
-rw-r--r--win32/config_sh.PL8
-rw-r--r--win32/makefile.mk2
-rw-r--r--win32/win32.c8
-rw-r--r--win32/win32.h38
-rw-r--r--win32/win32sck.c19
6 files changed, 71 insertions, 6 deletions
diff --git a/win32/Makefile b/win32/Makefile
index 7a8f96d367..40c67683de 100644
--- a/win32/Makefile
+++ b/win32/Makefile
@@ -957,7 +957,7 @@ $(CONFIGPM) : $(MINIPERL) ..\config.sh config_h.PL ..\minimod.pl
$(MINIPERL) : $(MINIDIR) $(MINI_OBJ)
$(LINK32) -subsystem:console -out:$@ @<<
- $(LINK_FLAGS) $(LIBFILES) $(MINI_OBJ)
+ $(LINK_FLAGS) $(DELAYLOAD) $(LIBFILES) $(MINI_OBJ)
<<
$(EMBED_EXE_MANI)
diff --git a/win32/config_sh.PL b/win32/config_sh.PL
index 3733c47bec..d866f7624e 100644
--- a/win32/config_sh.PL
+++ b/win32/config_sh.PL
@@ -103,8 +103,12 @@ if (exists $opt{cc}) {
}
$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};
diff --git a/win32/makefile.mk b/win32/makefile.mk
index 2905cd6a94..aa3b880909 100644
--- a/win32/makefile.mk
+++ b/win32/makefile.mk
@@ -1086,7 +1086,7 @@ $(MINIPERL) : $(MINIDIR) $(MINI_OBJ) $(CRTIPMLIBS)
$(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
diff --git a/win32/win32.c b/win32/win32.c
index bfc02fdee6..5a932ca7f6 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2726,7 +2726,11 @@ win32_freopen(const char *path, const char *mode, FILE *stream)
DllExport int
win32_fclose(FILE *pf)
{
+#ifdef WIN32_NO_SOCKETS
+ return fclose(pf);
+#else
return my_fclose(pf); /* defined in win32sck.c */
+#endif
}
DllExport int
@@ -3245,7 +3249,11 @@ extern int my_close(int); /* in win32sck.c */
DllExport int
win32_close(int fd)
{
+#ifdef WIN32_NO_SOCKETS
+ return close(fd);
+#else
return my_close(fd);
+#endif
}
DllExport int
diff --git a/win32/win32.h b/win32/win32.h
index 0474c61bc9..3065867bd2 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -13,6 +13,38 @@
# 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
@@ -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 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 */
diff --git a/win32/win32sck.c b/win32/win32sck.c
index 479d99ea53..9032a6d7f5 100644
--- a/win32/win32sck.c
+++ b/win32/win32sck.c
@@ -82,31 +82,50 @@ start_sockets(void)
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)
{
+#ifdef MYSWAP
+ dTHX;
+#else
StartSockets();
+#endif
return htonl(hostlong);
}
u_short
win32_htons(u_short hostshort)
{
+#ifdef MYSWAP
+ dTHX;
+#else
StartSockets();
+#endif
return htons(hostshort);
}
u_long
win32_ntohl(u_long netlong)
{
+#ifdef MYSWAP
+ dTHX;
+#else
StartSockets();
+#endif
return ntohl(netlong);
}
u_short
win32_ntohs(u_short netshort)
{
+#ifdef MYSWAP
+ dTHX;
+#else
StartSockets();
+#endif
return ntohs(netshort);
}