Issue 1424041: The mmap module does unnecessary dup() (original) (raw)

Created on 2006-02-04 13:39 by kdart, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mmapmodule.c.patch kdart,2006-02-05 11:16 make mmapmodule.c not dup fd
Messages (4)
msg27422 - (view) Author: Keith Dart (kdart) Date: 2006-02-04 13:39
The following no longer works in Python 2.4: _buf = mmap.mmap(-1, 8192, flags=mmap.MAP_PRIVATE|mmap.MAP_ANONYMOUS, prot=mmap.PROT_READ mmap.PROT_WRITE ) This is because the fd value of -1 raises an exception because it is being dup-ed inside the mmap module. But the fd is ignored in anonymous mmaps and does not need to be dup-ed. This worked in older Python (2.3). Is the dup() call really necessary? My current workaround is to open /dev/null. But this causes "invisible" consumption of file descriptors for the process.
msg27423 - (view) Author: Keith Dart (kdart) Date: 2006-02-04 14:33
Logged In: YES user_id=16527 Here is a patch that fixes the problem for anonymous maps. It simply makes the fd to be ignored if it is less than zero. This works, but I still don't think having a duped fd is needed. Whatever it accomplishes could be done in Python. As a general rule, I prefer these kinds os system call wrappers to do as little as possible (just wrap the call).
msg27424 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-02-05 06:01
Logged In: YES user_id=33168 I think the dup() was added for resizing and some other feature. I'm not really sure about it, but it's safer to leave in at this point. There's no file attached. This problem was fixed by patch 1407135. Committed revision 42244. Committed revision 42245. (2.4)
msg27425 - (view) Author: Keith Dart (kdart) Date: 2006-02-05 11:16
Logged In: YES user_id=16527 Bah, stupid little box... Here is the patch again. Just for the record (no /dev/zero is needed here).
History
Date User Action Args
2022-04-11 14:56:15 admin set github: 42867
2006-02-04 13:39:46 kdart create