Skip Menu |

This queue is for tickets about the File-Map CPAN distribution.

Report information
The Basics
Id: 52012
Status: resolved
Priority: 0/
Queue: File-Map

People
Owner: LEONT [...] cpan.org
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in:
  • 0.13
  • 0.14
  • 0.15
  • 0.16
  • 0.17
  • 0.18
  • 0.19
Fixed in: 0.20



Subject: mmap of zero length
Date: Tue, 24 Nov 2009 08:14:44 +1100
To: bug-File-Map [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
When doing an mmap of length==0 there's some unhappy different behaviour on different systems. On past linux kernel it worked, but now fails, which may be in accordance with POSIX. On freebsd there's a bizarre thing where the mmap succeeds, but the munmap then fails (which might be due to change soon). It'd be good if File::Map brought some uniformity to that. When mmapping a zero length file or a zero length segment I'd like to see an empty perl string, without having to worry what the system does or doesn't normally think of size zero. The pin() and advise() operations could be noops (which might means keeping the magic on the variable, but recognising zero length as do-nothing). I struck this when mmapping files which could potentially be empty. Although it's not hard to test for an empty file it's a bit tedious and to avoid a race condition you have to do it after opening the file, and then have to pass the detected size to map_handle() in case the size changes just at that moment ...
Hi Kevin, I've resolved this issue in version 0.20, but there's one caveat: mapping empty files writably is currently an error because there's not really sensible behavior for that. I consider loosening it to a warning and only throw an exception when writing is attempted in a later version. Regards, Leon Timmermans
Subject: Re: [rt.cpan.org #52012] mmap of zero length
Date: Sun, 20 Dec 2009 08:54:20 +1100
To: bug-File-Map [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Leon Timmermans via RT" <bug-File-Map@rt.cpan.org> writes: Show quoted text
> > mapping empty files writably is currently an error because there's not > really sensible behavior for that. I consider loosening it to a warning > and only throw an exception when writing is attempted in a later version.
I think it should not be an error nor a warning. If the mapped length can't be changed later then I think a writable zero-length mmap is fine. You can't do anything with it -- but if you just mmap some file you don't know it's zero length until getting the map, and at that point you can notice there's nothing you should overwrite etc. Certainly for a read+write mode, ie. "+<" or whatever it is, a zero length should be allowed.
Hi Kevin, After some thinking I've changed the semantics in version 0.21 to be like you proposed. It seems to be the most pragmatic option. Regards, Leon