Skip to content

Commit 6aa2d1f

Browse files
committed
Merged revisions 65459,65472,65481,65518,65536,65581,65609,65637,65641,65644-65645 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r65459 | gregory.p.smith | 2008-08-04 00:13:29 +0000 (Mon, 04 Aug 2008) | 4 lines - Issue #1857: subprocess.Popen.poll gained an additional _deadstate keyword argument in python 2.5, this broke code that subclassed Popen to include its own poll method. Fixed my moving _deadstate to an _internal_poll method. ........ r65472 | andrew.kuchling | 2008-08-04 01:43:43 +0000 (Mon, 04 Aug 2008) | 3 lines Bug 3228: Explicitly supply the file mode to avoid creating executable files, and add corresponding tests. Possible 2.5 backport candidate ........ r65481 | gregory.p.smith | 2008-08-04 07:33:37 +0000 (Mon, 04 Aug 2008) | 22 lines Adds a sanity check to avoid a *very rare* infinite loop due to a corrupt tls key list data structure in the thread startup path. This change is a companion to r60148 which already successfully dealt with a similar issue on thread shutdown. In particular this loop has been observed happening from this call path: #0 in find_key () #1 in PyThread_set_key_value () #2 in _PyGILState_NoteThreadState () #3 in PyThreadState_New () #4 in t_bootstrap () #5 in pthread_start_thread () I don't know how this happens but it does, *very* rarely. On more than one hardware platform. I have not been able to reproduce it manually. (A flaky mutex implementation on the system in question is one hypothesis). As with r60148, the spinning we managed to observe in the wild was due to a single list element pointing back upon itself. ........ r65518 | mark.dickinson | 2008-08-04 21:30:09 +0000 (Mon, 04 Aug 2008) | 7 lines Issue #1481296: (again!) Make conversion of a float NaN to an int or long raise ValueError instead of returning 0. Also, change the error message for conversion of an infinity to an integer, replacing 'long' by 'integer', so that it's appropriate for both long(float('inf')) and int(float('inf')). ........ r65536 | andrew.kuchling | 2008-08-05 01:00:57 +0000 (Tue, 05 Aug 2008) | 1 line Bug 3228: take a test from Niels Gustaebel's patch, and based on his patch, check for having os.stat available ........ r65581 | guido.van.rossum | 2008-08-07 18:51:38 +0000 (Thu, 07 Aug 2008) | 3 lines Patch by Ian Charnas from issue 3517. Add F_FULLFSYNC if it exists (OS X only so far). ........ r65609 | antoine.pitrou | 2008-08-09 17:22:25 +0000 (Sat, 09 Aug 2008) | 3 lines #3205: bz2 iterator fails silently on MemoryError ........ r65637 | georg.brandl | 2008-08-11 09:07:59 +0000 (Mon, 11 Aug 2008) | 3 lines - Issue #3537: Fix an assertion failure when an empty but presized dict object was stored in the freelist. ........ r65641 | jesse.noller | 2008-08-11 14:28:07 +0000 (Mon, 11 Aug 2008) | 2 lines Remove the fqdn call for issue 3270 ........ r65644 | antoine.pitrou | 2008-08-11 17:21:36 +0000 (Mon, 11 Aug 2008) | 3 lines #3134: shutil referenced undefined WindowsError symbol ........ r65645 | jesse.noller | 2008-08-11 19:00:15 +0000 (Mon, 11 Aug 2008) | 2 lines Fix the connection refused error part of issue 3419, use errno module instead of a static list of possible connection refused messages. ........
1 parent 734e268 commit 6aa2d1f

File tree

13 files changed

+115
-21
lines changed

13 files changed

+115
-21
lines changed

Lib/mailbox.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ def add_folder(self, folder):
394394
result = Maildir(path, factory=self._factory)
395395
maildirfolder_path = os.path.join(path, 'maildirfolder')
396396
if not os.path.exists(maildirfolder_path):
397-
os.close(os.open(maildirfolder_path, os.O_CREAT | os.O_WRONLY))
397+
os.close(os.open(maildirfolder_path, os.O_CREAT | os.O_WRONLY,
398+
0o666))
398399
return result
399400

400401
def remove_folder(self, folder):
@@ -1900,7 +1901,7 @@ def _unlock_file(f):
19001901

19011902
def _create_carefully(path):
19021903
"""Create a file if it doesn't exist and open for reading and writing."""
1903-
fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDWR)
1904+
fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDWR, 0o666)
19041905
try:
19051906
return open(path, 'r+', newline='')
19061907
finally:

Lib/multiprocessing/connection.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import sys
1313
import socket
14+
import errno
1415
import time
1516
import tempfile
1617
import itertools
@@ -215,10 +216,7 @@ def __init__(self, address, family, backlog=1):
215216
self._socket = socket.socket(getattr(socket, family))
216217
self._socket.bind(address)
217218
self._socket.listen(backlog)
218-
address = self._socket.getsockname()
219-
if type(address) is tuple:
220-
address = (socket.getfqdn(address[0]),) + address[1:]
221-
self._address = address
219+
self._address = self._socket.getsockname()
222220
self._family = family
223221
self._last_accepted = None
224222

@@ -253,7 +251,7 @@ def SocketClient(address):
253251
try:
254252
s.connect(address)
255253
except socket.error as e:
256-
if e.args[0] != 10061: # 10061 => connection refused
254+
if e.args[0] != errno.ECONNREFUSED: # connection refused
257255
debug('failed to connect to address %s', address)
258256
raise
259257
time.sleep(0.01)

Lib/shutil.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
class Error(EnvironmentError):
1717
pass
1818

19+
try:
20+
WindowsError
21+
except NameError:
22+
WindowsError = None
23+
1924
def copyfileobj(fsrc, fdst, length=16*1024):
2025
"""copy data from file-like object fsrc to file-like object fdst"""
2126
while 1:
@@ -162,11 +167,12 @@ def copytree(src, dst, symlinks=False, ignore=None):
162167
errors.extend(err.args[0])
163168
try:
164169
copystat(src, dst)
165-
except WindowsError:
166-
# can't copy file access times on Windows
167-
pass
168170
except OSError as why:
169-
errors.extend((src, dst, str(why)))
171+
if WindowsError is not None and isinstance(why, WindowsError):
172+
# Copying file access times may fail on Windows
173+
pass
174+
else:
175+
errors.extend((src, dst, str(why)))
170176
if errors:
171177
raise Error(errors)
172178

Lib/subprocess.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class pywintypes:
375375

376376
def _cleanup():
377377
for inst in _active[:]:
378-
res = inst.poll(_deadstate=sys.maxsize)
378+
res = inst._internal_poll(_deadstate=sys.maxsize)
379379
if res is not None and res >= 0:
380380
try:
381381
_active.remove(inst)
@@ -635,7 +635,7 @@ def __del__(self, sys=sys):
635635
# We didn't get to successfully create a child process.
636636
return
637637
# In case the child hasn't been waited on, check if it's done.
638-
self.poll(_deadstate=sys.maxsize)
638+
self._internal_poll(_deadstate=sys.maxsize)
639639
if self.returncode is None and _active is not None:
640640
# Child is still running, keep us alive until we can wait on it.
641641
_active.append(self)
@@ -671,6 +671,10 @@ def communicate(self, input=None):
671671
return self._communicate(input)
672672

673673

674+
def poll(self):
675+
return self._internal_poll()
676+
677+
674678
if mswindows:
675679
#
676680
# Windows methods
@@ -842,7 +846,7 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
842846
errwrite.Close()
843847

844848

845-
def poll(self, _deadstate=None):
849+
def _internal_poll(self, _deadstate=None):
846850
"""Check if child process has terminated. Returns returncode
847851
attribute."""
848852
if self.returncode is None:
@@ -1103,7 +1107,7 @@ def _handle_exitstatus(self, sts):
11031107
raise RuntimeError("Unknown child exit status!")
11041108

11051109

1106-
def poll(self, _deadstate=None):
1110+
def _internal_poll(self, _deadstate=None):
11071111
"""Check if child process has terminated. Returns returncode
11081112
attribute."""
11091113
if self.returncode is None:

Lib/test/test_dict.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,17 @@ def __eq__(self, other):
638638
resizing = True
639639
d[9] = 6
640640

641+
def test_empty_presized_dict_in_freelist(self):
642+
# Bug #3537: if an empty but presized dict with a size larger
643+
# than 7 was in the freelist, it triggered an assertion failure
644+
try:
645+
d = {'a': 1/0, 'b': None, 'c': None, 'd': None, 'e': None,
646+
'f': None, 'g': None, 'h': None}
647+
except ZeroDivisionError:
648+
pass
649+
d = {}
650+
651+
641652

642653
from test import mapping_tests
643654

Lib/test/test_long.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,8 @@ def test__format__(self):
768768

769769
def test_nan_inf(self):
770770
self.assertRaises(OverflowError, int, float('inf'))
771-
self.assertRaises(OverflowError, int, float('nan'))
771+
self.assertRaises(OverflowError, int, float('-inf'))
772+
self.assertRaises(ValueError, int, float('nan'))
772773

773774
def test_true_division(self):
774775
huge = 1 << 40000

Lib/test/test_mailbox.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,38 @@ def test_directory_in_folder (self):
709709
for msg in self._box:
710710
pass
711711

712+
def test_file_permissions(self):
713+
# Verify that message files are created without execute permissions
714+
if not hasattr(os, "stat") or not hasattr(os, "umask"):
715+
return
716+
msg = mailbox.MaildirMessage(self._template % 0)
717+
orig_umask = os.umask(0)
718+
try:
719+
key = self._box.add(msg)
720+
finally:
721+
os.umask(orig_umask)
722+
path = os.path.join(self._path, self._box._lookup(key))
723+
mode = os.stat(path).st_mode
724+
self.assert_(mode & 0o111 == 0)
725+
726+
def test_folder_file_perms(self):
727+
# From bug #3228, we want to verify that the file created inside a Maildir
728+
# subfolder isn't marked as executable.
729+
if not hasattr(os, "stat") or not hasattr(os, "umask"):
730+
return
731+
732+
orig_umask = os.umask(0)
733+
try:
734+
subfolder = self._box.add_folder('subfolder')
735+
finally:
736+
os.umask(orig_umask)
737+
738+
path = os.path.join(subfolder._path, 'maildirfolder')
739+
st = os.stat(path)
740+
perms = st.st_mode
741+
self.assertFalse((perms & 0o111)) # Execute bits should all be off.
742+
743+
712744
class _TestMboxMMDF(TestMailbox):
713745

714746
def tearDown(self):
@@ -800,11 +832,28 @@ def test_relock(self):
800832
self._box.close()
801833

802834

803-
804835
class TestMbox(_TestMboxMMDF):
805836

806837
_factory = lambda self, path, factory=None: mailbox.mbox(path, factory)
807838

839+
def test_file_perms(self):
840+
# From bug #3228, we want to verify that the mailbox file isn't executable,
841+
# even if the umask is set to something that would leave executable bits set.
842+
# We only run this test on platforms that support umask.
843+
if hasattr(os, 'umask') and hasattr(os, 'stat'):
844+
try:
845+
old_umask = os.umask(0o077)
846+
self._box.close()
847+
os.unlink(self._path)
848+
self._box = mailbox.mbox(self._path, create=True)
849+
self._box.add('')
850+
self._box.close()
851+
finally:
852+
os.umask(old_umask)
853+
854+
st = os.stat(self._path)
855+
perms = st.st_mode
856+
self.assertFalse((perms & 0o111)) # Execute bits should all be off.
808857

809858
class TestMMDF(_TestMboxMMDF):
810859

Modules/bz2module.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ Util_ReadAhead(BZ2FileObject *f, int bufsize)
317317
return 0;
318318
}
319319
if ((f->f_buf = PyMem_Malloc(bufsize)) == NULL) {
320+
PyErr_NoMemory();
320321
return -1;
321322
}
322323
Py_BEGIN_ALLOW_THREADS

Modules/fcntlmodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@ all_ins(PyObject* d)
530530
if (ins(d, "F_SHLCK", (long)F_SHLCK)) return -1;
531531
#endif
532532

533+
/* OS X (and maybe others) let you tell the storage device to flush to physical media */
534+
#ifdef F_FULLFSYNC
535+
if (ins(d, "F_FULLFSYNC", (long)F_FULLFSYNC)) return -1;
536+
#endif
537+
533538
/* For F_{GET|SET}FL */
534539
#ifdef FD_CLOEXEC
535540
if (ins(d, "FD_CLOEXEC", (long)FD_CLOEXEC)) return -1;

Objects/dictobject.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ PyDict_New(void)
242242
_Py_NewReference((PyObject *)mp);
243243
if (mp->ma_fill) {
244244
EMPTY_TO_MINSIZE(mp);
245+
} else {
246+
/* At least set ma_table and ma_mask; these are wrong
247+
if an empty but presized dict is added to freelist */
248+
INIT_NONZERO_DICT_SLOTS(mp);
245249
}
246250
assert (mp->ma_used == 0);
247251
assert (mp->ma_table == mp->ma_smalltable);

0 commit comments

Comments
 (0)