develooper Front page | perl.perl5.porters | Postings from October 2011

[perl #101382] seeking on bytes causes broken perl strings

Thread Previous
From:
Father Chrysostomos via RT
Date:
October 17, 2011 09:34
Subject:
[perl #101382] seeking on bytes causes broken perl strings
Message ID:
rt-3.6.HEAD-31297-1318869283-547.101382-15-0@perl.org
On Mon Oct 17 09:18:48 2011, tom christiansen wrote:
> "A. Pagaltzis via RT" <perlbug-followup@perl.org> wrote
>    on Mon, 17 Oct 2011 09:04:07 PDT:
> 
> > That will make the read “work” in that it won’t complain and won’t
> > produce corrupt data, but in what practical scenario is this useful?
> > 
> >  “Sometimes your read will swallow the first character in the data. We
> >   won’t tell you though. In fact we’ll make sure you can’t notice even
> >   if you wanted to.”
> > 
> > What is the sense of that?
> 
> Good point.
> 
> I agree that it seems dodgy.  Perl is pretty careful not to go silently
> destroying data, and I'd like it to remain so.  I also wouldn't want
> break {sys,}seek from working when given a legitimate tell address.
> 
> I just don't know what the devil to do with reads producing broken strings
> after seek has been given a tell address that is *not* a character
> boundary when you're working with an auto-decoded stream.  I'm a bit
> surprised that broken internal strings aren't fatals, actually. Hm?
> 
> My stomach has been somewhat unsettled of late, so I don't know that I
> should necessarily trust its instincts, but my gut feel that Perl should
> never let you be able to produce a broken Perl string.  Modulo intentional
> malice with the low-level stuff, of course, but I don't see seek and read
> as being in that bucket.  This is also what makes me feel that $/ = \INT
> producing broken Perl strings is also inherently flawed.  I think Nick
once
> observed that we mustn't let those happen.
> 
> I know how the super-duper-over-object-oriented languages would "fix"
> this: they'd create 52 levels of strictly typed I/O wrapper classes and
> only allow you to go through their APIs to get at things.  That goes
> against the Unix/C mentality of allowing low-level access to the real
> and very simple system calls when such is asked for, so I don't want to
> even start to go there.  
> 
> But what to do about these malformed characters, eh?

Either
a) croak, or
b) fudge things, as was suggested above, but with a default (formerly
known as mandatory) warning.




Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About