From: Gurusamy Sarathy Date: Thu, 30 Dec 1999 05:44:21 +0000 (+0000) Subject: enable the PERL_BINMODE_SCRIPTS behavior by default on Windows X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c39cd00800303e8967294e98aa4c427a1872a251;p=p5sagit%2Fp5-mst-13.2.git enable the PERL_BINMODE_SCRIPTS behavior by default on Windows to allow ByteLoader to work; the DATA filehandles continue to be left open in text mode for compatibility p4raw-id: //depot/perl@4739 --- diff --git a/embed.h b/embed.h index aa5b8bc..95f3dd5 100644 --- a/embed.h +++ b/embed.h @@ -1077,8 +1077,8 @@ # if defined(CRIPPLED_CC) #define uni S_uni # endif -# if defined(WIN32) -#define win32_textfilter S_win32_textfilter +# if defined(PERL_CR_FILTER) +#define cr_textfilter S_cr_textfilter # endif #endif #if defined(PERL_IN_UNIVERSAL_C) || defined(PERL_DECL_PROT) @@ -2482,8 +2482,8 @@ # if defined(CRIPPLED_CC) #define uni(a,b) S_uni(aTHX_ a,b) # endif -# if defined(WIN32) -#define win32_textfilter(a,b,c) S_win32_textfilter(aTHX_ a,b,c) +# if defined(PERL_CR_FILTER) +#define cr_textfilter(a,b,c) S_cr_textfilter(aTHX_ a,b,c) # endif #endif #if defined(PERL_IN_UNIVERSAL_C) || defined(PERL_DECL_PROT) @@ -4830,9 +4830,9 @@ #define S_uni CPerlObj::S_uni #define uni S_uni # endif -# if defined(WIN32) -#define S_win32_textfilter CPerlObj::S_win32_textfilter -#define win32_textfilter S_win32_textfilter +# if defined(PERL_CR_FILTER) +#define S_cr_textfilter CPerlObj::S_cr_textfilter +#define cr_textfilter S_cr_textfilter # endif #endif #if defined(PERL_IN_UNIVERSAL_C) || defined(PERL_DECL_PROT) diff --git a/embed.pl b/embed.pl index 8419eea..f04de69 100755 --- a/embed.pl +++ b/embed.pl @@ -2169,8 +2169,8 @@ s |I32 |utf16rev_textfilter|int idx|SV *sv|int maxlen # if defined(CRIPPLED_CC) s |int |uni |I32 f|char *s # endif -# if defined(WIN32) -s |I32 |win32_textfilter |int idx|SV *sv|int maxlen +# if defined(PERL_CR_FILTER) +s |I32 |cr_textfilter |int idx|SV *sv|int maxlen # endif #endif diff --git a/objXSUB.h b/objXSUB.h index 36c9f7c..5c03183 100644 --- a/objXSUB.h +++ b/objXSUB.h @@ -3687,7 +3687,7 @@ #if defined(PERL_IN_TOKE_C) || defined(PERL_DECL_PROT) # if defined(CRIPPLED_CC) # endif -# if defined(WIN32) +# if defined(PERL_CR_FILTER) # endif #endif #if defined(PERL_IN_UNIVERSAL_C) || defined(PERL_DECL_PROT) diff --git a/pod/perldelta.pod b/pod/perldelta.pod index e7aac32..d070aa2 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -1043,6 +1043,10 @@ The C module is supported. Rudimentary support for building under command.com in Windows 95 has been added. +Scripts are read in binary mode by default to allow ByteLoader (and +the filter mechanism in general) to work properly. For compatibility, +the DATA filehandle continues to be set to text mode. + [TODO - GSAR] =head1 New tests diff --git a/proto.h b/proto.h index 634a573..06c834c 100644 --- a/proto.h +++ b/proto.h @@ -1095,8 +1095,8 @@ STATIC I32 S_utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen); # if defined(CRIPPLED_CC) STATIC int S_uni(pTHX_ I32 f, char *s); # endif -# if defined(WIN32) -STATIC I32 S_win32_textfilter(pTHX_ int idx, SV *sv, int maxlen); +# if defined(PERL_CR_FILTER) +STATIC I32 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen); # endif #endif diff --git a/sv.c b/sv.c index 918769b..d52003a 100644 --- a/sv.c +++ b/sv.c @@ -4058,10 +4058,6 @@ screamer2: } } -#ifdef WIN32 - win32_strip_return(sv); -#endif - return (SvCUR(sv) - append) ? SvPVX(sv) : Nullch; } diff --git a/toke.c b/toke.c index 452b20c..da3c7fd 100644 --- a/toke.c +++ b/toke.c @@ -304,15 +304,36 @@ S_depcom(pTHX) * utf16-to-utf8-reversed. */ -#ifdef WIN32 +#ifdef PERL_CR_FILTER +static void +strip_return(SV *sv) +{ + register char *s = SvPVX(sv); + register char *e = s + SvCUR(sv); + /* outer loop optimized to do nothing if there are no CR-LFs */ + while (s < e) { + if (*s++ == '\r' && *s == '\n') { + /* hit a CR-LF, need to copy the rest */ + register char *d = s - 1; + *d++ = *s++; + while (s < e) { + if (*s == '\r' && s[1] == '\n') + s++; + *d++ = *s++; + } + SvCUR(sv) -= s - d; + return; + } + } +} STATIC I32 -S_win32_textfilter(pTHX_ int idx, SV *sv, int maxlen) +S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) { - I32 count = FILTER_READ(idx+1, sv, maxlen); - if (count > 0 && !maxlen) - win32_strip_return(sv); - return count; + I32 count = FILTER_READ(idx+1, sv, maxlen); + if (count > 0 && !maxlen) + strip_return(sv); + return count; } #endif @@ -1872,9 +1893,9 @@ Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) STATIC char * S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append) { -#ifdef WIN32FILTER +#ifdef PERL_CR_FILTER if (!PL_rsfp_filters) { - filter_add(win32_textfilter,NULL); + filter_add(S_cr_textfilter,NULL); } #endif if (PL_rsfp_filters) { @@ -3785,6 +3806,26 @@ Perl_yylex(pTHX) IoTYPE(GvIOp(gv)) = '-'; else IoTYPE(GvIOp(gv)) = '<'; +#if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS) + /* if the script was opened in binmode, we need to revert + * it to text mode for compatibility. + * XXX this is a questionable hack at best. */ + { + Off_t loc = 0; + if (IoTYPE(GvIOp(gv)) == '<') { + loc = PerlIO_tell(PL_rsfp); + (void)PerlIO_seek(PL_rsfp, 0L, 0); + } + if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) { +#if defined(__BORLANDC__) + /* XXX see note in do_binmode() */ + ((FILE*)PL_rsfp)->flags |= _F_BIN; +#endif + if (loc > 0) + PerlIO_seek(PL_rsfp, loc, 0); + } + } +#endif PL_rsfp = Nullfp; } goto fake_eof; diff --git a/win32/Makefile b/win32/Makefile index b3c6e56..45f7146 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -147,28 +147,36 @@ CCINCDIR = $(CCHOME)\include CCLIBDIR = $(CCHOME)\lib # -# additional compiler flags can be specified here. +# Additional compiler flags can be specified here. # -# Adding -DPERL_POLLUTE enables support for old symbols, at the expense of -# extreme pollution. You most probably want this if you're compiling modules -# from CPAN, or other such serious uses of this experimental perl release. -# We don't enable this by default because we want the modules to get fixed -# instead of clinging to shortcuts like this one. + +# +# This should normally be disabled. Adding -DPERL_POLLUTE enables support +# for old symbols by default, at the expense of extreme pollution. You most +# probably just want to build modules that won't compile with +# perl Makefile.PL POLLUTE=1 +# instead of enabling this. Please report such modules to the respective +# authors. # #BUILDOPT = $(BUILDOPT) -DPERL_POLLUTE # -# enable this to disable the File::Glob implementation of CORE::glob +# This should normally be disabled. Enabling it will disable the File::Glob +# implementation of CORE::glob. # #BUILDOPT = $(BUILDOPT) -DPERL_EXTERNAL_GLOB -# Enabling this causes perl to do its own CR/LF conversions, and is required -# if you want to be able to use the bytecode compiler and ByteLoader -BUILDOPT = $(BUILDOPT) -DUSE_BINMODE_SCRIPTS +# +# This should normally be disabled. Enabling it causes perl to read scripts +# in text mode (which is the 5.005 behavior) and will break ByteLoader. +#BUILDOPT = $(BUILDOPT) -DUSE_TEXTMODE_SCRIPTS -# Enabling this runs a cloned toplevel interpreter (*EXPERIMENTAL*, fails tests) +# +# This should normally be disabled. Enabling it runs a cloned toplevel +# interpreter (*EXPERIMENTAL*, fails tests) #BUILDOPT = $(BUILDOPT) -DTOP_CLONE +# # specify semicolon-separated list of extra directories that modules will # look for libraries (spaces in path names need not be quoted) # diff --git a/win32/makefile.mk b/win32/makefile.mk index 228edca..ac43a16 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -166,26 +166,33 @@ CCINCDIR *= $(CCHOME)\include CCLIBDIR *= $(CCHOME)\lib # -# additional compiler flags can be specified here. +# Additional compiler flags can be specified here. # -# Adding -DPERL_POLLUTE enables support for old symbols, at the expense of -# extreme pollution. You most probably want this if you're compiling modules -# from CPAN, or other such serious uses of this experimental perl release. -# We don't enable this by default because we want the modules to get fixed -# instead of clinging to shortcuts like this one. + +# +# This should normally be disabled. Adding -DPERL_POLLUTE enables support +# for old symbols by default, at the expense of extreme pollution. You most +# probably just want to build modules that won't compile with +# perl Makefile.PL POLLUTE=1 +# instead of enabling this. Please report such modules to the respective +# authors. # #BUILDOPT += -DPERL_POLLUTE # -# enable this to disable the File::Glob implementation of CORE::glob +# This should normally be disabled. Enabling it will disable the File::Glob +# implementation of CORE::glob. # #BUILDOPT += -DPERL_EXTERNAL_GLOB -# Enabling this causes perl to do its own CR/LF conversions, and is required -# if you want to be able to use the bytecode compiler and ByteLoader -BUILDOPT += -DUSE_BINMODE_SCRIPTS +# +# This should normally be disabled. Enabling it causes perl to read scripts +# in text mode (which is the 5.005 behavior) and will break ByteLoader. +#BUILDOPT += -DUSE_TEXTMODE_SCRIPTS -# Enabling this runs a cloned toplevel interpreter (*EXPERIMENTAL*, fails tests) +# +# This should normally be disabled. Enabling it runs a cloned toplevel +# interpreter (*EXPERIMENTAL*, fails tests) #BUILDOPT += -DTOP_CLONE # diff --git a/win32/win32.c b/win32/win32.c index ae22a60..53288af 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -3688,31 +3688,6 @@ Perl_win32_init(int *argcp, char ***argvp) MALLOC_INIT; } -#ifdef USE_BINMODE_SCRIPTS - -void -win32_strip_return(SV *sv) -{ - char *s = SvPVX(sv); - char *e = s+SvCUR(sv); - char *d = s; - while (s < e) - { - if (*s == '\r' && s[1] == '\n') - { - *d++ = '\n'; - s += 2; - } - else - { - *d++ = *s++; - } - } - SvCUR_set(sv,d-SvPVX(sv)); -} - -#endif - #ifdef USE_ITHREADS # ifdef PERL_OBJECT diff --git a/win32/win32.h b/win32/win32.h index c953f5b..24ba7c6 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -325,12 +325,10 @@ typedef char * caddr_t; /* In malloc.c (core address). */ #define PERL_CORE #endif -#ifdef USE_BINMODE_SCRIPTS -#define PERL_SCRIPT_MODE "rb" -EXT void win32_strip_return(struct sv *sv); +#ifdef USE_TEXTMODE_SCRIPTS +# define PERL_SCRIPT_MODE "r" #else -#define PERL_SCRIPT_MODE "r" -#define win32_strip_return(sv) NOOP +# define PERL_SCRIPT_MODE "rb" #endif /*