Subject: | check handle layers before mapping |
Date: | Wed, 31 Mar 2010 11:04:07 +1100 |
To: | bug-File-Map [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
In my locate iterator, when given a file handle I look at the perlio
layers as part of choosing mmap or plain reads. Any layers that might
transform the data would be bypassed by an mmap so plain reads must be
used.
As an idea for a feature, File::Map could have something to say whether
map_handle() will give the same bytes as plain reads.
Maybe map_handle() could go so far as to refuse to operate on a handle
with transforms and/or utf-8 flag. Refusing would avoid surprises
seeing data different than read(), but might be inconvenient for anyone
who thinks they know what they're doing.
In my code I list some known-safe layers like :unix and :stdio and rate
anything unknown as possibly transforming the data and therefore unsafe.
A more general mechanism might be to look for a class method like
PerlIO::foo->File_Map_clean
which could say if bypassing the :foo layer by an mmap is ok. (Keeping
the linkage loose, so File::Map doesn't have to hard code a list, and
layers don't have to care if File::Map is ever loaded or used.)
On ms-dos I think the C library unix emulations add an O_TEXT or some
such flag on file descriptors. Dunno if an mmap() in that case obeys
that flag or skips it. If skipped then the same consideration would
apply there as for :crlf pushed on a perl-level handle.