From: Jarkko Hietaniemi Date: Mon, 7 Jul 2003 14:08:16 +0000 (+0000) Subject: Retract #20056, #20055, #20052, #20050, #20048: the changes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=263df5f176be8146ec259953e28e2b87bb448e1d;p=p5sagit%2Fp5-mst-13.2.git Retract #20056, #20055, #20052, #20050, #20048: the changes are just breaking more than they are fixing. p4raw-id: //depot/perl@20057 --- diff --git a/ext/Digest/MD5/MD5.xs b/ext/Digest/MD5/MD5.xs index 9b60753..0bf05f0 100644 --- a/ext/Digest/MD5/MD5.xs +++ b/ext/Digest/MD5/MD5.xs @@ -621,7 +621,7 @@ addfile(self, fh) MD5_CTX* context = get_md5_ctx(self); STRLEN fill = context->bytes_low & 0x3F; unsigned char buffer[4096]; - SSize_t n; + int n; CODE: if (fh) { if (fill) { @@ -630,19 +630,18 @@ addfile(self, fh) * first. */ STRLEN missing = 64 - fill; - n = PerlIO_read(fh, buffer, missing); - if (n >= 0) + if ( (n = PerlIO_read(fh, buffer, missing))) MD5Update(context, buffer, n); else XSRETURN(1); /* self */ } /* Process blocks until EOF or error */ - while ( (n = PerlIO_read(fh, buffer, sizeof(buffer))) > 0 ) { + while ( (n = PerlIO_read(fh, buffer, sizeof(buffer)))) { MD5Update(context, buffer, n); } - if (n < 0 && PerlIO_error(fh)) { + if (PerlIO_error(fh)) { croak("Reading from filehandle failed"); } } diff --git a/ext/Digest/MD5/t/badfile.t b/ext/Digest/MD5/t/badfile.t index 2292341..32fc6fe 100644 --- a/ext/Digest/MD5/t/badfile.t +++ b/ext/Digest/MD5/t/badfile.t @@ -4,7 +4,6 @@ print "1..3\n"; use Digest::MD5 (); -use Config; $md5 = Digest::MD5->new; @@ -22,17 +21,11 @@ eval { print "not " unless $@ =~ /^No filehandle passed at/; print "ok 2\n"; -# Some stdio implementations don't gripe about reading from write-only -# filehandles, so if we are using stdio (which means either pre-perlio -# Perl, or perlio-Perl configured to have no perlio), we can't expect -# to get the right error. -my $stdio = !exists $Config{useperlio} || !defined $Config{useperlio}; - open(BAR, ">no-existing-file.$$") || die; eval { $md5->addfile(*BAR); }; -print "not " unless $@ =~ /^Reading from filehandle failed at/ || $stdio; +print "not " unless $@ =~ /^Reading from filehandle failed at/; print "ok 3\n"; close(BAR); diff --git a/ext/Digest/MD5/t/files.t b/ext/Digest/MD5/t/files.t index 08cd51b..f28e0df 100644 --- a/ext/Digest/MD5/t/files.t +++ b/ext/Digest/MD5/t/files.t @@ -23,7 +23,7 @@ if (ord "A" == 193) { # EBCDIC fcc48d6bb88ca8065bf9ddfcb9e7483e Changes 0565ec21b15c0f23f4c51fb327c8926d README 1965beb0e48253b694220fbb5d6230f5 MD5.pm -339e7a6915dcd67ff5bb583a7568fbb6 MD5.xs +5b3c24da3f70f3c0938cc7c205a28ab7 MD5.xs 276da0aa4e9a08b7fe09430c9c5690aa rfc1321.txt EOT } elsif ("\n" eq "\015") { # MacOS @@ -31,7 +31,7 @@ EOT f161f474603c54a0093ad2f6f93be33b Changes 6c950a0211a5a28f023bb482037698cd README 18178c90bc13d6824f6c96973b6e9433 MD5.pm -1f004206b000efac36e9890aac6f0281 MD5.xs +2c7fdb2ffa3840dc4f8dcdcf13241015 MD5.xs 754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt EOT } else { @@ -40,7 +40,7 @@ EOT 029fa5059ba0b2175cee09ab5d9b7b73 Changes 6c950a0211a5a28f023bb482037698cd README 18178c90bc13d6824f6c96973b6e9433 MD5.pm -1f004206b000efac36e9890aac6f0281 MD5.xs +2c7fdb2ffa3840dc4f8dcdcf13241015 MD5.xs 754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt EOT } diff --git a/perlio.c b/perlio.c index 178ad7c..b0649df 100644 --- a/perlio.c +++ b/perlio.c @@ -99,20 +99,6 @@ else \ SETERRNO(EBADF, SS_IVCHAN) -#define Perl_PerlIO_fail_if_hasnot(f, able, ueno, veno, ret) \ - if (PerlIOValid(f) && (PerlIOBase(f)->flags & (able)) == 0) { \ - PerlIOBase(f)->flags |= PERLIO_F_ERROR; \ - SETERRNO(ueno, veno); \ - return ret; \ - } - -#define Perl_PerlIO_fail_if_has(f, able, ueno, veno, ret) \ - if (PerlIOValid(f) && (PerlIOBase(f)->flags & (able)) == able) { \ - PerlIOBase(f)->flags |= PERLIO_F_ERROR; \ - SETERRNO(ueno, veno); \ - return ret; \ - } - int perlsio_binmode(FILE *fp, int iotype, int mode) { @@ -1570,21 +1556,18 @@ PerlIO_openn(pTHX_ const char *layers, const char *mode, int fd, SSize_t Perl_PerlIO_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) { - Perl_PerlIO_fail_if_hasnot(f, PERLIO_F_CANREAD, EBADF, SS_IVCHAN, -1); Perl_PerlIO_or_Base(f, Read, read, -1, (aTHX_ f, vbuf, count)); } SSize_t Perl_PerlIO_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count) { - Perl_PerlIO_fail_if_hasnot(f, PERLIO_F_CANREAD, EBADF, SS_IVCHAN, -1); Perl_PerlIO_or_Base(f, Unread, unread, -1, (aTHX_ f, vbuf, count)); } SSize_t Perl_PerlIO_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count) { - Perl_PerlIO_fail_if_hasnot(f, PERLIO_F_CANWRITE, EBADF, SS_IVCHAN, -1); Perl_PerlIO_or_fail(f, Write, -1, (aTHX_ f, vbuf, count)); } @@ -2050,6 +2033,11 @@ PerlIOBase_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) { STDCHAR *buf = (STDCHAR *) vbuf; if (f) { + if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD)) { + PerlIOBase(f)->flags |= PERLIO_F_ERROR; + SETERRNO(EBADF, SS_IVCHAN); + return 0; + } while (count > 0) { SSize_t avail = PerlIO_get_cnt(f); SSize_t take = 0; @@ -2459,7 +2447,7 @@ PerlIOUnix_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) int fd = PerlIOSelf(f, PerlIOUnix)->fd; if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD) || PerlIOBase(f)->flags & (PERLIO_F_EOF|PERLIO_F_ERROR)) { - return -1; + return 0; } while (1) { SSize_t len = PerlLIO_read(fd, vbuf, count); @@ -2500,15 +2488,17 @@ PerlIOUnix_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count) IV PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence) { - int fd; + int fd = PerlIOSelf(f, PerlIOUnix)->fd; Off_t new; -#ifdef ESPIPE - Perl_PerlIO_fail_if_has(f, PERLIO_F_NOTREG, ESPIPE, SS_IVCHAN, -1); + if (PerlIOBase(f)->flags & PERLIO_F_NOTREG) { +#ifdef ESPIPE + SETERRNO(ESPIPE, LIB_INVARG); #else - Perl_PerlIO_fail_if_has(f, PERLIO_F_NOTREG, EBADF, SS_IVCHAN, -1); + SETERRNO(EINVAL, LIB_INVARG); #endif - fd = PerlIOSelf(f, PerlIOUnix)->fd; - new = PerlLIO_lseek(fd, offset, whence); + return -1; + } + new = PerlLIO_lseek(fd, offset, whence); if (new == (Off_t) - 1) { return -1; @@ -3120,13 +3110,7 @@ PerlIOStdio_eof(pTHX_ PerlIO *f) IV PerlIOStdio_error(pTHX_ PerlIO *f) { - IV stdio_error = PerlSIO_ferror(PerlIOSelf(f, PerlIOStdio)->stdio); - /* Some stdio implementations do not mind e.g. trying to output - * to a write-only filehandle, or vice versa. Therefore we will - * try both the stdio way and the perlio way. */ - IV iobase_error = PerlIOValid(f) ? - ((PerlIOBase(f)->flags & PERLIO_F_ERROR) != 0) : 0; - return stdio_error || iobase_error; + return PerlSIO_ferror(PerlIOSelf(f, PerlIOStdio)->stdio); } void