[Python-checkins] r76005 - in sandbox/trunk/newgil: Doc/c-api/conversion.rst Doc/library/logging.rst Lib/decimal.py Lib/gzip.py Lib/test/decimaltestdata/extra.decTest Lib/test/regrtest.py Lib/test/support.py Lib/test/test_ascii_formatd.py Lib/test/test_asynchat.py Lib/test/test_decimal.py Lib/test/test_docxmlrpc.py Lib/test/test_pep263.py Lib/test/test_pydoc.py Lib/test/test_signal.py Lib/test/test_thread.py Lib/test/test_xmlrpc.py Misc/NEWS Modules/_io/_iomodule.h Modules/_io/bufferedio.c Modules/_threadmodule.c Python/ast.c Python/ceval.c

antoine.pitrou python-checkins at python.org
Sun Nov 1 12:17:38 CET 2009


Author: antoine.pitrou
Date: Sun Nov 1 12:17:37 2009
New Revision: 76005
Log:
Merged revisions 75922,75928-75929,75932,75937,75941,75947,75959,75961,75964-75966,75968,75970,75976-75977,75981,75984,75988,75992,75997,76002 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
 r75922 | r.david.murray | 2009年10月28日 15:07:51 +0100 (mer., 28 oct. 2009) | 9 lines
 
 Merged revisions 75920 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75920 | r.david.murray | 2009年10月28日 10:03:43 -0400 (2009年10月28日) | 2 lines
 
 Remove variable that is no longer used.
 ........
................
 r75928 | benjamin.peterson | 2009年10月28日 22:59:39 +0100 (mer., 28 oct. 2009) | 5 lines
 
 in wide builds, avoid storing high unicode characters from source code with surrogates
 
 This is accomplished by decoding with utf-32 instead of utf-16 on all builds.
 The patch is by Adam Olsen.
................
 r75929 | vinay.sajip | 2009年10月29日 00:28:16 +0100 (jeu., 29 oct. 2009) | 1 line
 
 Issue 7199: Documentation made slightly more consistent w.r.t. logging level enumeration.
................
 r75932 | benjamin.peterson | 2009年10月29日 02:50:06 +0100 (jeu., 29 oct. 2009) | 11 lines
 
 Blocked revisions 75931 via svnmerge
 
 ........
 r75931 | benjamin.peterson | 2009年10月28日 20:49:07 -0500 (2009年10月28日) | 5 lines
 
 do a backport of r75928
 
 The added test does not fail without the patch, but we still fix the issue of
 surrogates being used in wide builds where they should not be.
 ........
................
 r75937 | lars.gustaebel | 2009年10月29日 10:39:47 +0100 (jeu., 29 oct. 2009) | 10 lines
 
 Merged revisions 75935 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75935 | lars.gustaebel | 2009年10月29日 10:15:00 +0100 (2009年10月29日) | 3 lines
 
 Issue #4750: Store the basename of the original filename in
 the gzip FNAME header as required by RFC 1952.
 ........
................
 r75941 | mark.dickinson | 2009年10月29日 10:58:06 +0100 (jeu., 29 oct. 2009) | 11 lines
 
 Merged revisions 75939 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75939 | mark.dickinson | 2009年10月29日 09:46:04 +0000 (2009年10月29日) | 5 lines
 
 Roll back ill-considered attempts to fix printf specifier mismatch for off_t.
 The sensible solution seems to be to implement %lld for PyString_FromFormat(V)
 and PyErr_Format. See issue #7228.
 ........
................
 r75947 | mark.dickinson | 2009年10月29日 13:23:02 +0100 (jeu., 29 oct. 2009) | 20 lines
 
 Merged revisions 75943-75945 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75943 | mark.dickinson | 2009年10月29日 11:09:09 +0000 (2009年10月29日) | 1 line
 
 Fix duplicate test numbers in extra.decTest
 ........
 r75944 | mark.dickinson | 2009年10月29日 12:04:00 +0000 (2009年10月29日) | 3 lines
 
 Issue #7233: A number of two-argument Decimal methods were failing to
 accept ints and longs for the second argument.
 ........
 r75945 | mark.dickinson | 2009年10月29日 12:11:18 +0000 (2009年10月29日) | 4 lines
 
 Issue #7233: Fix Decimal.shift and Decimal.rotate methods for
 arguments with more digits than the current context precision.
 Bug reported by Stefan Krah.
 ........
................
 r75959 | antoine.pitrou | 2009年10月30日 18:25:12 +0100 (ven., 30 oct. 2009) | 13 lines
 
 Merged revisions 75958 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75958 | antoine.pitrou | 2009年10月30日 18:07:08 +0100 (ven., 30 oct. 2009) | 7 lines
 
 Issue #7222: Make thread "reaping" more reliable so that reference
 leak-chasing test runs give sensible results. The previous method of
 reaping threads could return successfully while some Thread objects were
 still referenced. This also introduces a new private function:
 :func:hread._count().
 ........
................
 r75961 | antoine.pitrou | 2009年10月30日 18:34:49 +0100 (ven., 30 oct. 2009) | 9 lines
 
 Merged revisions 75960 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75960 | antoine.pitrou | 2009年10月30日 18:33:28 +0100 (ven., 30 oct. 2009) | 3 lines
 
 Fix transient refleaks in test_docxmlrpc.
 ........
................
 r75964 | antoine.pitrou | 2009年10月30日 18:58:27 +0100 (ven., 30 oct. 2009) | 13 lines
 
 Merged revisions 75962-75963 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75962 | antoine.pitrou | 2009年10月30日 18:55:21 +0100 (ven., 30 oct. 2009) | 3 lines
 
 Try to fix transient refleaks in test_asynchat.
 ........
 r75963 | antoine.pitrou | 2009年10月30日 18:56:00 +0100 (ven., 30 oct. 2009) | 3 lines
 
 Try to fix transient refleaks in test_xmlrpc.
 ........
................
 r75965 | antoine.pitrou | 2009年10月30日 19:15:02 +0100 (ven., 30 oct. 2009) | 5 lines
 
 Fix a refleak in test_uuid when run with -j. 
 The "refleak" was simply the effect of internal buffering in block buffering mode
 (rather than line buffering when sys.stdout is a terminal)
................
 r75966 | antoine.pitrou | 2009年10月30日 19:30:35 +0100 (ven., 30 oct. 2009) | 4 lines
 
 Followup to r75965: replace the test_uuid-specific patch with a generic fix
 (other tests may have the same problem).
................
 r75968 | antoine.pitrou | 2009年10月30日 22:45:40 +0100 (ven., 30 oct. 2009) | 9 lines
 
 Merged revisions 75967 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75967 | antoine.pitrou | 2009年10月30日 22:41:22 +0100 (ven., 30 oct. 2009) | 3 lines
 
 Try to fix transient refleaks in test_pydoc.
 ........
................
 r75970 | antoine.pitrou | 2009年10月30日 23:23:02 +0100 (ven., 30 oct. 2009) | 10 lines
 
 Merged revisions 75969 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75969 | antoine.pitrou | 2009年10月30日 23:19:09 +0100 (ven., 30 oct. 2009) | 5 lines
 
 Remove official documentation entry for thread._count() and make the
 docstring more descriptive instead.
 ........
................
 r75976 | mark.dickinson | 2009年10月31日 10:29:47 +0100 (sam., 31 oct. 2009) | 8 lines
 
 Blocked revisions 75974 via svnmerge
 
 ........
 r75974 | mark.dickinson | 2009年10月31日 09:28:12 +0000 (2009年10月31日) | 1 line
 
 Move a Misc/NEWS entry to right section.
 ........
................
 r75977 | mark.dickinson | 2009年10月31日 10:39:52 +0100 (sam., 31 oct. 2009) | 1 line
 
 Fix ReST markup.
................
 r75981 | mark.dickinson | 2009年10月31日 10:43:46 +0100 (sam., 31 oct. 2009) | 8 lines
 
 Blocked revisions 75979 via svnmerge
 
 ........
 r75979 | mark.dickinson | 2009年10月31日 09:42:39 +0000 (2009年10月31日) | 1 line
 
 Deprecate PyOS_ascii_strtod and PyOS_ascii_atof, and document the replacement function PyOS_string_to_double.
 ........
................
 r75984 | mark.dickinson | 2009年10月31日 11:18:44 +0100 (sam., 31 oct. 2009) | 12 lines
 
 Merged revisions 75982 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75982 | mark.dickinson | 2009年10月31日 10:11:28 +0000 (2009年10月31日) | 5 lines
 
 Issue #6603: Fix --with-tsc build failures on x86-64 that resulted
 from a gcc inline assembler peculiarity. (gcc's "A" constraint
 apparently means 'rax or rdx' in 64-bit mode, not edx:eax
 or rdx:rax as one might expect.)
 ........
................
 r75988 | mark.dickinson | 2009年10月31日 11:38:43 +0100 (sam., 31 oct. 2009) | 9 lines
 
 Merged revisions 75986 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75986 | mark.dickinson | 2009年10月31日 10:36:06 +0000 (2009年10月31日) | 2 lines
 
 Issue #7042: Use a better mechanism for testing timers in test_signal.
 ........
................
 r75992 | mark.dickinson | 2009年10月31日 13:48:28 +0100 (sam., 31 oct. 2009) | 8 lines
 
 Blocked revisions 75991 via svnmerge
 
 ........
 r75991 | mark.dickinson | 2009年10月31日 12:47:47 +0000 (2009年10月31日) | 1 line
 
 Set retval on PyOS_string_to_double failure.
 ........
................
 r75997 | eric.smith | 2009年10月31日 18:08:48 +0100 (sam., 31 oct. 2009) | 9 lines
 
 Merged revisions 75995 via svnmerge from 
 svn+ssh://pythondev@svn.python.org/python/trunk
 
 ........
 r75995 | eric.smith | 2009年10月31日 13:07:17 -0400 (2009年10月31日) | 1 line
 
 Improved test for a deprecation warning.
 ........
................
 r76002 | antoine.pitrou | 2009年11月01日 00:26:47 +0100 (dim., 01 nov. 2009) | 9 lines
 
 Blocked revisions 76001 via svnmerge
 Apparently someone already did the job in py3k.
 
 ........
 r76001 | antoine.pitrou | 2009年11月01日 00:19:52 +0100 (dim., 01 nov. 2009) | 3 lines
 
 Use richer assertions in test_mailbox (for better failure messages).
 ........
................
Modified:
 sandbox/trunk/newgil/ (props changed)
 sandbox/trunk/newgil/Doc/c-api/conversion.rst
 sandbox/trunk/newgil/Doc/library/logging.rst
 sandbox/trunk/newgil/Lib/decimal.py
 sandbox/trunk/newgil/Lib/gzip.py
 sandbox/trunk/newgil/Lib/test/decimaltestdata/extra.decTest
 sandbox/trunk/newgil/Lib/test/regrtest.py
 sandbox/trunk/newgil/Lib/test/support.py
 sandbox/trunk/newgil/Lib/test/test_ascii_formatd.py
 sandbox/trunk/newgil/Lib/test/test_asynchat.py
 sandbox/trunk/newgil/Lib/test/test_decimal.py
 sandbox/trunk/newgil/Lib/test/test_docxmlrpc.py
 sandbox/trunk/newgil/Lib/test/test_pep263.py
 sandbox/trunk/newgil/Lib/test/test_pydoc.py
 sandbox/trunk/newgil/Lib/test/test_signal.py
 sandbox/trunk/newgil/Lib/test/test_thread.py
 sandbox/trunk/newgil/Lib/test/test_xmlrpc.py
 sandbox/trunk/newgil/Misc/NEWS
 sandbox/trunk/newgil/Modules/_io/_iomodule.h
 sandbox/trunk/newgil/Modules/_io/bufferedio.c
 sandbox/trunk/newgil/Modules/_threadmodule.c
 sandbox/trunk/newgil/Python/ast.c
 sandbox/trunk/newgil/Python/ceval.c
Modified: sandbox/trunk/newgil/Doc/c-api/conversion.rst
==============================================================================
--- sandbox/trunk/newgil/Doc/c-api/conversion.rst	(original)
+++ sandbox/trunk/newgil/Doc/c-api/conversion.rst	Sun Nov 1 12:17:37 2009
@@ -155,7 +155,7 @@
 See the Unix man page :manpage:`atof(2)` for details.
 
 .. deprecated:: 3.1
- Use PyOS_string_to_double instead.
+ Use :cfunc:`PyOS_string_to_double` instead.
 
 
 .. cfunction:: char* PyOS_stricmp(char *s1, char *s2)
Modified: sandbox/trunk/newgil/Doc/library/logging.rst
==============================================================================
--- sandbox/trunk/newgil/Doc/library/logging.rst	(original)
+++ sandbox/trunk/newgil/Doc/library/logging.rst	Sun Nov 1 12:17:37 2009
@@ -119,7 +119,7 @@
 messages at different log levels. This allows you to instrument your code with
 debug messages, for example, but turning the log level down so that those debug
 messages are not written for your production system. The default levels are
-``CRITICAL``, ``ERROR``, ``WARNING``, ``INFO``, ``DEBUG`` and ``NOTSET``.
+``NOTSET``, ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR`` and ``CRITICAL``.
 
 The logger, handler, and log message call each specify a level. The log message
 is only emitted if the handler and logger are configured to emit messages of
Modified: sandbox/trunk/newgil/Lib/decimal.py
==============================================================================
--- sandbox/trunk/newgil/Lib/decimal.py	(original)
+++ sandbox/trunk/newgil/Lib/decimal.py	Sun Nov 1 12:17:37 2009
@@ -2806,6 +2806,8 @@
 value. Note that a total ordering is defined for all possible abstract
 representations.
 """
+ other = _convert_other(other, raiseit=True)
+
 # if one is negative and the other is positive, it's easy
 if self._sign and not other._sign:
 return _NegativeOne
@@ -2875,6 +2877,8 @@
 
 Like compare_total, but with operand's sign ignored and assumed to be 0.
 """
+ other = _convert_other(other, raiseit=True)
+
 s = self.copy_abs()
 o = other.copy_abs()
 return s.compare_total(o)
@@ -3243,6 +3247,9 @@
 """Applies an 'and' operation between self and other's digits."""
 if context is None:
 context = getcontext()
+
+ other = _convert_other(other, raiseit=True)
+
 if not self._islogical() or not other._islogical():
 return context._raise_error(InvalidOperation)
 
@@ -3264,6 +3271,9 @@
 """Applies an 'or' operation between self and other's digits."""
 if context is None:
 context = getcontext()
+
+ other = _convert_other(other, raiseit=True)
+
 if not self._islogical() or not other._islogical():
 return context._raise_error(InvalidOperation)
 
@@ -3278,6 +3288,9 @@
 """Applies an 'xor' operation between self and other's digits."""
 if context is None:
 context = getcontext()
+
+ other = _convert_other(other, raiseit=True)
+
 if not self._islogical() or not other._islogical():
 return context._raise_error(InvalidOperation)
 
@@ -3491,6 +3504,8 @@
 if context is None:
 context = getcontext()
 
+ other = _convert_other(other, raiseit=True)
+
 ans = self._check_nans(other, context)
 if ans:
 return ans
@@ -3507,19 +3522,23 @@
 torot = int(other)
 rotdig = self._int
 topad = context.prec - len(rotdig)
- if topad:
+ if topad > 0:
 rotdig = '0'*topad + rotdig
+ elif topad < 0:
+ rotdig = rotdig[-topad:]
 
 # let's rotate!
 rotated = rotdig[torot:] + rotdig[:torot]
 return _dec_from_triple(self._sign,
 rotated.lstrip('0') or '0', self._exp)
 
- def scaleb (self, other, context=None):
+ def scaleb(self, other, context=None):
 """Returns self operand after adding the second value to its exp."""
 if context is None:
 context = getcontext()
 
+ other = _convert_other(other, raiseit=True)
+
 ans = self._check_nans(other, context)
 if ans:
 return ans
@@ -3543,6 +3562,8 @@
 if context is None:
 context = getcontext()
 
+ other = _convert_other(other, raiseit=True)
+
 ans = self._check_nans(other, context)
 if ans:
 return ans
@@ -3557,22 +3578,22 @@
 
 # get values, pad if necessary
 torot = int(other)
- if not torot:
- return Decimal(self)
 rotdig = self._int
 topad = context.prec - len(rotdig)
- if topad:
+ if topad > 0:
 rotdig = '0'*topad + rotdig
+ elif topad < 0:
+ rotdig = rotdig[-topad:]
 
 # let's shift!
 if torot < 0:
- rotated = rotdig[:torot]
+ shifted = rotdig[:torot]
 else:
- rotated = rotdig + '0'*torot
- rotated = rotated[-context.prec:]
+ shifted = rotdig + '0'*torot
+ shifted = shifted[-context.prec:]
 
 return _dec_from_triple(self._sign,
- rotated.lstrip('0') or '0', self._exp)
+ shifted.lstrip('0') or '0', self._exp)
 
 # Support for pickling, copy, and deepcopy
 def __reduce__(self):
Modified: sandbox/trunk/newgil/Lib/gzip.py
==============================================================================
--- sandbox/trunk/newgil/Lib/gzip.py	(original)
+++ sandbox/trunk/newgil/Lib/gzip.py	Sun Nov 1 12:17:37 2009
@@ -5,7 +5,7 @@
 
 # based on Andrew Kuchling's minigzip.py distributed with the zlib module
 
-import struct, sys, time
+import struct, sys, time, os
 import zlib
 import builtins
 
@@ -158,7 +158,8 @@
 try:
 # RFC 1952 requires the FNAME field to be Latin-1. Do not
 # include filenames that cannot be represented that way.
- fname = self.name.encode('latin-1')
+ fname = os.path.basename(self.name)
+ fname = fname.encode('latin-1')
 if fname.endswith(b'.gz'):
 fname = fname[:-3]
 except UnicodeEncodeError:
Modified: sandbox/trunk/newgil/Lib/test/decimaltestdata/extra.decTest
==============================================================================
--- sandbox/trunk/newgil/Lib/test/decimaltestdata/extra.decTest	(original)
+++ sandbox/trunk/newgil/Lib/test/decimaltestdata/extra.decTest	Sun Nov 1 12:17:37 2009
@@ -154,22 +154,6 @@
 extr1302 fma 0E123 -Inf sNaN789 -> NaN Invalid_operation
 extr1302 fma -Inf 0E-456 sNaN148 -> NaN Invalid_operation
 
--- Issue #6794: when comparing NaNs using compare_total, payloads
--- should be compared as though positive integers; not
--- lexicographically as strings.
-extr1400 comparetotal NaN123 NaN45 -> 1
-extr1401 comparetotal sNaN123 sNaN45 -> 1
-extr1402 comparetotal -NaN123 -NaN45 -> -1
-extr1403 comparetotal -sNaN123 -sNaN45 -> -1
-extr1404 comparetotal NaN45 NaN123 -> -1
-extr1405 comparetotal sNaN45 sNaN123 -> -1
-extr1406 comparetotal -NaN45 -NaN123 -> 1
-extr1407 comparetotal -sNaN45 -sNaN123 -> 1
-
-extr1410 comparetotal -sNaN63450748854172416 -sNaN911993 -> -1
-extr1411 comparetotmag NaN1222222222222 -NaN999999 -> 1
-
-
 -- max/min/max_mag/min_mag bug in 2.5.2/2.6/3.0: max(NaN, finite) gave
 -- incorrect answers when the finite number required rounding; similarly
 -- for the other thre functions
@@ -187,6 +171,50 @@
 extr1430 min_mag 9181716151 -NaN -> 9.18172E+9 Inexact Rounded
 extr1431 min_mag NaN4 1.818180E100 -> 1.81818E+100 Rounded
 
+-- Issue #6794: when comparing NaNs using compare_total, payloads
+-- should be compared as though positive integers; not
+-- lexicographically as strings.
+extr1500 comparetotal NaN123 NaN45 -> 1
+extr1501 comparetotal sNaN123 sNaN45 -> 1
+extr1502 comparetotal -NaN123 -NaN45 -> -1
+extr1503 comparetotal -sNaN123 -sNaN45 -> -1
+extr1504 comparetotal NaN45 NaN123 -> -1
+extr1505 comparetotal sNaN45 sNaN123 -> -1
+extr1506 comparetotal -NaN45 -NaN123 -> 1
+extr1507 comparetotal -sNaN45 -sNaN123 -> 1
+
+extr1510 comparetotal -sNaN63450748854172416 -sNaN911993 -> -1
+extr1511 comparetotmag NaN1222222222222 -NaN999999 -> 1
+
+-- Issue #7233: rotate and scale should truncate an argument
+-- of length greater than the current precision.
+precision: 4
+extr1600 rotate 1234567 -5 -> NaN Invalid_operation
+extr1601 rotate 1234567 -4 -> 4567
+extr1602 rotate 1234567 -3 -> 5674
+extr1603 rotate 1234567 -2 -> 6745
+extr1604 rotate 1234567 -1 -> 7456
+extr1605 rotate 1234567 0 -> 4567
+extr1606 rotate 1234567 1 -> 5674
+extr1607 rotate 1234567 2 -> 6745
+extr1608 rotate 1234567 3 -> 7456
+extr1609 rotate 1234567 4 -> 4567
+extr1610 rotate 1234567 5 -> NaN Invalid_operation
+
+extr1650 shift 1234567 -5 -> NaN Invalid_operation
+extr1651 shift 1234567 -4 -> 0
+extr1652 shift 1234567 -3 -> 4
+extr1653 shift 1234567 -2 -> 45
+extr1654 shift 1234567 -1 -> 456
+extr1655 shift 1234567 0 -> 4567
+extr1656 shift 1234567 1 -> 5670
+extr1657 shift 1234567 2 -> 6700
+extr1658 shift 1234567 3 -> 7000
+extr1659 shift 1234567 4 -> 0
+extr1660 shift 1234567 5 -> NaN Invalid_operation
+
+
+
 -- Tests for the is_* boolean operations
 precision: 9
 maxExponent: 999
Modified: sandbox/trunk/newgil/Lib/test/regrtest.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/regrtest.py	(original)
+++ sandbox/trunk/newgil/Lib/test/regrtest.py	Sun Nov 1 12:17:37 2009
@@ -996,6 +996,12 @@
 obj._abc_cache.clear()
 obj._abc_negative_cache.clear()
 
+ # Flush standard output, so that buffered data is sent to the OS and
+ # associated Python objects are reclaimed.
+ for stream in (sys.stdout, sys.stderr, sys.__stdout__, sys.__stderr__):
+ if stream is not None:
+ stream.flush()
+
 # Clear assorted module caches.
 _path_created.clear()
 re.purge()
@@ -1368,7 +1374,7 @@
 # much of the testing framework relies on the globals in the
 # test.support module.
 mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
- i = pathlen = len(sys.path)
+ i = len(sys.path)
 while i >= 0:
 i -= 1
 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
Modified: sandbox/trunk/newgil/Lib/test/support.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/support.py	(original)
+++ sandbox/trunk/newgil/Lib/test/support.py	Sun Nov 1 12:17:37 2009
@@ -947,24 +947,29 @@
 #=======================================================================
 # Threading support to prevent reporting refleaks when running regrtest.py -R
 
+# NOTE: we use thread._count() rather than threading.enumerate() (or the
+# moral equivalent thereof) because a threading.Thread object is still alive
+# until its __bootstrap() method has returned, even after it has been
+# unregistered from the threading module.
+# thread._count(), on the other hand, only gets decremented *after* the
+# __bootstrap() method has returned, which gives us reliable reference counts
+# at the end of a test run.
+
 def threading_setup():
- import threading
- return len(threading._active), len(threading._limbo)
+ import _thread
+ return _thread._count(),
 
-def threading_cleanup(num_active, num_limbo):
- import threading
+def threading_cleanup(nb_threads):
+ import _thread
 import time
 
 _MAX_COUNT = 10
- count = 0
- while len(threading._active) != num_active and count < _MAX_COUNT:
- count += 1
- time.sleep(0.1)
-
- count = 0
- while len(threading._limbo) != num_limbo and count < _MAX_COUNT:
- count += 1
+ for count in range(_MAX_COUNT):
+ n = _thread._count()
+ if n == nb_threads:
+ break
 time.sleep(0.1)
+ # XXX print a warning in case of failure?
 
 def reap_threads(func):
 @functools.wraps(func)
Modified: sandbox/trunk/newgil/Lib/test/test_ascii_formatd.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/test_ascii_formatd.py	(original)
+++ sandbox/trunk/newgil/Lib/test/test_ascii_formatd.py	Sun Nov 1 12:17:37 2009
@@ -20,8 +20,7 @@
 c_double(10.0))
 self.assertEqual(buf.value, b'+10.0000000000')
 
- self.assertEqual(str(w.message), 'PyOS_ascii_formatd is deprecated, '
- 'use PyOS_double_to_string instead')
+ self.assertEqual(w.category, DeprecationWarning)
 
 class FormatTests(unittest.TestCase):
 # ensure that, for the restricted set of format codes,
Modified: sandbox/trunk/newgil/Lib/test/test_asynchat.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/test_asynchat.py	(original)
+++ sandbox/trunk/newgil/Lib/test/test_asynchat.py	Sun Nov 1 12:17:37 2009
@@ -93,10 +93,10 @@
 usepoll = False
 
 def setUp (self):
- pass
+ self._threads = support.threading_setup()
 
 def tearDown (self):
- pass
+ support.threading_cleanup(*self._threads)
 
 def line_terminator_check(self, term, server_chunk):
 event = threading.Event()
Modified: sandbox/trunk/newgil/Lib/test/test_decimal.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/test_decimal.py	(original)
+++ sandbox/trunk/newgil/Lib/test/test_decimal.py	Sun Nov 1 12:17:37 2009
@@ -1530,6 +1530,53 @@
 self.assertEqual(str(Decimal(0).sqrt()),
 str(c.sqrt(Decimal(0))))
 
+ def test_conversions_from_int(self):
+ # Check that methods taking a second Decimal argument will
+ # always accept an integer in place of a Decimal.
+ self.assertEqual(Decimal(4).compare(3),
+ Decimal(4).compare(Decimal(3)))
+ self.assertEqual(Decimal(4).compare_signal(3),
+ Decimal(4).compare_signal(Decimal(3)))
+ self.assertEqual(Decimal(4).compare_total(3),
+ Decimal(4).compare_total(Decimal(3)))
+ self.assertEqual(Decimal(4).compare_total_mag(3),
+ Decimal(4).compare_total_mag(Decimal(3)))
+ self.assertEqual(Decimal(10101).logical_and(1001),
+ Decimal(10101).logical_and(Decimal(1001)))
+ self.assertEqual(Decimal(10101).logical_or(1001),
+ Decimal(10101).logical_or(Decimal(1001)))
+ self.assertEqual(Decimal(10101).logical_xor(1001),
+ Decimal(10101).logical_xor(Decimal(1001)))
+ self.assertEqual(Decimal(567).max(123),
+ Decimal(567).max(Decimal(123)))
+ self.assertEqual(Decimal(567).max_mag(123),
+ Decimal(567).max_mag(Decimal(123)))
+ self.assertEqual(Decimal(567).min(123),
+ Decimal(567).min(Decimal(123)))
+ self.assertEqual(Decimal(567).min_mag(123),
+ Decimal(567).min_mag(Decimal(123)))
+ self.assertEqual(Decimal(567).next_toward(123),
+ Decimal(567).next_toward(Decimal(123)))
+ self.assertEqual(Decimal(1234).quantize(100),
+ Decimal(1234).quantize(Decimal(100)))
+ self.assertEqual(Decimal(768).remainder_near(1234),
+ Decimal(768).remainder_near(Decimal(1234)))
+ self.assertEqual(Decimal(123).rotate(1),
+ Decimal(123).rotate(Decimal(1)))
+ self.assertEqual(Decimal(1234).same_quantum(1000),
+ Decimal(1234).same_quantum(Decimal(1000)))
+ self.assertEqual(Decimal('9.123').scaleb(-100),
+ Decimal('9.123').scaleb(Decimal(-100)))
+ self.assertEqual(Decimal(456).shift(-1),
+ Decimal(456).shift(Decimal(-1)))
+
+ self.assertEqual(Decimal(-12).fma(Decimal(45), 67),
+ Decimal(-12).fma(Decimal(45), Decimal(67)))
+ self.assertEqual(Decimal(-12).fma(45, 67),
+ Decimal(-12).fma(Decimal(45), Decimal(67)))
+ self.assertEqual(Decimal(-12).fma(45, Decimal(67)),
+ Decimal(-12).fma(Decimal(45), Decimal(67)))
+
 
 class DecimalPythonAPItests(unittest.TestCase):
 
Modified: sandbox/trunk/newgil/Lib/test/test_docxmlrpc.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/test_docxmlrpc.py	(original)
+++ sandbox/trunk/newgil/Lib/test/test_docxmlrpc.py	Sun Nov 1 12:17:37 2009
@@ -53,6 +53,7 @@
 
 class DocXMLRPCHTTPGETServer(unittest.TestCase):
 def setUp(self):
+ self._threads = support.threading_setup()
 # Enable server feedback
 DocXMLRPCServer._send_traceback_header = True
 
@@ -74,6 +75,7 @@
 
 # Disable server feedback
 DocXMLRPCServer._send_traceback_header = False
+ support.threading_cleanup(*self._threads)
 
 def test_valid_get_response(self):
 self.client.request("GET", "/")
Modified: sandbox/trunk/newgil/Lib/test/test_pep263.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/test_pep263.py	(original)
+++ sandbox/trunk/newgil/Lib/test/test_pep263.py	Sun Nov 1 12:17:37 2009
@@ -36,6 +36,14 @@
 exec(c, d)
 self.assertEquals(d['\xc6'], '\xc6')
 
+ def test_issue3297(self):
+ c = compile("a, b = '\U0001010F', '\\U0001010F'", "dummy", "exec")
+ d = {}
+ exec(c, d)
+ self.assertEqual(d['a'], d['b'])
+ self.assertEqual(len(d['a']), len(d['b']))
+ self.assertEqual(ascii(d['a']), ascii(d['b']))
+
 def test_main():
 support.run_unittest(PEP263Test)
 
Modified: sandbox/trunk/newgil/Lib/test/test_pydoc.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/test_pydoc.py	(original)
+++ sandbox/trunk/newgil/Lib/test/test_pydoc.py	Sun Nov 1 12:17:37 2009
@@ -9,7 +9,8 @@
 import unittest
 import test.support
 from contextlib import contextmanager
-from test.support import TESTFN, forget, rmtree, EnvironmentVarGuard
+from test.support import (
+ TESTFN, forget, rmtree, EnvironmentVarGuard, reap_children)
 
 from test import pydoc_mod
 
@@ -195,8 +196,11 @@
 output of pydoc.
 """
 cmd = [sys.executable, pydoc.__file__, " ".join(args), module_name]
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout.read()
- return output.strip()
+ try:
+ output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
+ return output.strip()
+ finally:
+ reap_children()
 
 def get_pydoc_html(module):
 "Returns pydoc generated output as html"
Modified: sandbox/trunk/newgil/Lib/test/test_signal.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/test_signal.py	(original)
+++ sandbox/trunk/newgil/Lib/test/test_signal.py	Sun Nov 1 12:17:37 2009
@@ -360,11 +360,14 @@
 signal.signal(signal.SIGVTALRM, self.sig_vtalrm)
 signal.setitimer(self.itimer, 0.3, 0.2)
 
- for i in range(100000000):
+ start_time = time.time()
+ while time.time() - start_time < 5.0:
 # use up some virtual time by doing real work
 _ = pow(12345, 67890, 10000019)
 if signal.getitimer(self.itimer) == (0.0, 0.0):
 break # sig_vtalrm handler stopped this itimer
+ else:
+ self.fail('timeout waiting for sig_vtalrm signal')
 
 # virtual itimer should be (0.0, 0.0) now
 self.assertEquals(signal.getitimer(self.itimer), (0.0, 0.0))
@@ -376,9 +379,14 @@
 signal.signal(signal.SIGPROF, self.sig_prof)
 signal.setitimer(self.itimer, 0.2, 0.2)
 
- for i in range(100000000):
+ start_time = time.time()
+ while time.time() - start_time < 5.0:
+ # do some work
+ _ = pow(12345, 67890, 10000019)
 if signal.getitimer(self.itimer) == (0.0, 0.0):
 break # sig_prof handler stopped this itimer
+ else:
+ self.fail('timeout waiting for sig_prof signal')
 
 # profiling itimer should be (0.0, 0.0) now
 self.assertEquals(signal.getitimer(self.itimer), (0.0, 0.0))
Modified: sandbox/trunk/newgil/Lib/test/test_thread.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/test_thread.py	(original)
+++ sandbox/trunk/newgil/Lib/test/test_thread.py	Sun Nov 1 12:17:37 2009
@@ -4,6 +4,7 @@
 from test import support
 import _thread as thread
 import time
+import weakref
 
 
 NUMTASKS = 10
@@ -99,6 +100,32 @@
 
 thread.stack_size(0)
 
+ def test__count(self):
+ # Test the _count() function.
+ orig = thread._count()
+ mut = thread.allocate_lock()
+ mut.acquire()
+ started = []
+ def task():
+ started.append(None)
+ mut.acquire()
+ mut.release()
+ thread.start_new_thread(task, ())
+ while not started:
+ time.sleep(0.01)
+ self.assertEquals(thread._count(), orig + 1)
+ # Allow the task to finish.
+ mut.release()
+ # The only reliable way to be sure that the thread ended from the
+ # interpreter's point of view is to wait for the function object to be
+ # destroyed.
+ done = []
+ wr = weakref.ref(task, lambda _: done.append(None))
+ del task
+ while not done:
+ time.sleep(0.01)
+ self.assertEquals(thread._count(), orig)
+
 
 class Barrier:
 def __init__(self, num_threads):
Modified: sandbox/trunk/newgil/Lib/test/test_xmlrpc.py
==============================================================================
--- sandbox/trunk/newgil/Lib/test/test_xmlrpc.py	(original)
+++ sandbox/trunk/newgil/Lib/test/test_xmlrpc.py	Sun Nov 1 12:17:37 2009
@@ -798,6 +798,7 @@
 len(content))
 
 
+ at support.reap_threads
 def test_main():
 xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase,
 BinaryTestCase, FaultTestCase]
Modified: sandbox/trunk/newgil/Misc/NEWS
==============================================================================
--- sandbox/trunk/newgil/Misc/NEWS	(original)
+++ sandbox/trunk/newgil/Misc/NEWS	Sun Nov 1 12:17:37 2009
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- Issue #3297: On wide unicode builds, do not split unicode characters into
+ surrogates.
+
 - Remove length limitation when constructing a complex number from a string.
 
 - Issue #1087418: Boost performance of bitwise operations for longs.
@@ -117,6 +120,14 @@
 Library
 -------
 
+- Issue #7233: Fix a number of two-argument Decimal methods to make
+ sure that they accept an int or long as the second argument. Also
+ fix buggy handling of large arguments (those with coefficient longer
+ than the current precision) in shift and rotate.
+
+- Issue #4750: Store the basename of the original filename in the gzip FNAME
+ header as required by RFC 1952.
+
 - Issue #1180: Added a new global option to ignore ~/.pydistutils.cfg in
 Distutils.
 
@@ -301,6 +312,10 @@
 Build
 -----
 
+- Issue #6603: Change READ_TIMESTAMP macro in ceval.c so that it
+ compiles correctly under gcc on x86-64. This fixes a reported
+ problem with the --with-tsc build on x86-64.
+
 - Issue #6802: Fix build issues on MacOSX 10.6
 
 - Issue #6244: Allow detect_tkinter to look for Tcl/Tk 8.6.
@@ -323,6 +338,12 @@
 Tests
 -----
 
+- Issue #7222: Make thread "reaping" more reliable so that reference
+ leak-chasing test runs give sensible results. The previous method of
+ reaping threads could return successfully while some Thread objects were
+ still referenced. This also introduces a new private function:
+ :func:`_thread._count()`.
+
 - Issue #7151: fixed regrtest -j so that output to stderr from a test no
 longer runs the risk of causing the worker thread to fail.
 
Modified: sandbox/trunk/newgil/Modules/_io/_iomodule.h
==============================================================================
--- sandbox/trunk/newgil/Modules/_io/_iomodule.h	(original)
+++ sandbox/trunk/newgil/Modules/_io/_iomodule.h	Sun Nov 1 12:17:37 2009
@@ -70,14 +70,6 @@
 * Offset type for positioning.
 */
 
-/* Printing a variable of type off_t correctly and without producing
- compiler warnings is surprisingly painful. We identify an integer
- type whose size matches off_t and then: (1) cast the off_t to that
- integer type and (2) use the appropriate conversion specification
- for printf. The cast is necessary: gcc complains about formatting
- a long with "%lld" even when both long and long long have the same
- precision. */
-
 #if defined(MS_WIN64) || defined(MS_WINDOWS)
 
 /* Windows uses long long for offsets */
@@ -86,33 +78,26 @@
 # define PyLong_FromOff_t PyLong_FromLongLong
 # define PY_OFF_T_MAX PY_LLONG_MAX
 # define PY_OFF_T_MIN PY_LLONG_MIN
-# define PY_PRIdOFF "I64d" /* format to use in printf with type off_t */
-# define PY_OFF_T_COMPAT PY_LONG_LONG /* type compatible with off_t */
+
 #else
 
 /* Other platforms use off_t */
 typedef off_t Py_off_t;
-#if (HAVE_LONG_LONG && SIZEOF_OFF_T == SIZEOF_LONG_LONG)
+#if (SIZEOF_OFF_T == SIZEOF_SIZE_T)
+# define PyLong_AsOff_t PyLong_AsSsize_t
+# define PyLong_FromOff_t PyLong_FromSsize_t
+# define PY_OFF_T_MAX PY_SSIZE_T_MAX
+# define PY_OFF_T_MIN PY_SSIZE_T_MIN
+#elif (SIZEOF_OFF_T == SIZEOF_LONG_LONG)
 # define PyLong_AsOff_t PyLong_AsLongLong
 # define PyLong_FromOff_t PyLong_FromLongLong
 # define PY_OFF_T_MAX PY_LLONG_MAX
 # define PY_OFF_T_MIN PY_LLONG_MIN
-# define PY_PRIdOFF "lld"
-# define PY_OFF_T_COMPAT PY_LONG_LONG
 #elif (SIZEOF_OFF_T == SIZEOF_LONG)
 # define PyLong_AsOff_t PyLong_AsLong
 # define PyLong_FromOff_t PyLong_FromLong
 # define PY_OFF_T_MAX LONG_MAX
 # define PY_OFF_T_MIN LONG_MIN
-# define PY_PRIdOFF "ld"
-# define PY_OFF_T_COMPAT long
-#elif (SIZEOF_OFF_T == SIZEOF_SIZE_T)
-# define PyLong_AsOff_t PyLong_AsSsize_t
-# define PyLong_FromOff_t PyLong_FromSsize_t
-# define PY_OFF_T_MAX PY_SSIZE_T_MAX
-# define PY_OFF_T_MIN PY_SSIZE_T_MIN
-# define PY_PRIdOFF "zd"
-# define PY_OFF_T_COMPAT Py_ssize_t
 #else
 # error off_t does not match either size_t, long, or long long!
 #endif
Modified: sandbox/trunk/newgil/Modules/_io/bufferedio.c
==============================================================================
--- sandbox/trunk/newgil/Modules/_io/bufferedio.c	(original)
+++ sandbox/trunk/newgil/Modules/_io/bufferedio.c	Sun Nov 1 12:17:37 2009
@@ -580,8 +580,7 @@
 if (n < 0) {
 if (!PyErr_Occurred())
 PyErr_Format(PyExc_IOError,
- "Raw stream returned invalid position %" PY_PRIdOFF,
-			 (PY_OFF_T_COMPAT)n);
+ "Raw stream returned invalid position %zd", n);
 return -1;
 }
 self->abs_pos = n;
@@ -613,8 +612,7 @@
 if (n < 0) {
 if (!PyErr_Occurred())
 PyErr_Format(PyExc_IOError,
- "Raw stream returned invalid position %" PY_PRIdOFF,
-			 (PY_OFF_T_COMPAT)n);
+ "Raw stream returned invalid position %zd", n);
 return -1;
 }
 self->abs_pos = n;
Modified: sandbox/trunk/newgil/Modules/_threadmodule.c
==============================================================================
--- sandbox/trunk/newgil/Modules/_threadmodule.c	(original)
+++ sandbox/trunk/newgil/Modules/_threadmodule.c	Sun Nov 1 12:17:37 2009
@@ -14,7 +14,7 @@
 #include "pythread.h"
 
 static PyObject *ThreadError;
-
+static long nb_threads = 0;
 
 /* Lock objects */
 
@@ -439,6 +439,7 @@
 	tstate = PyThreadState_New(boot->interp);
 
 	PyEval_AcquireThread(tstate);
+	nb_threads++;
 	res = PyEval_CallObjectWithKeywords(
 		boot->func, boot->args, boot->keyw);
 	if (res == NULL) {
@@ -463,6 +464,7 @@
 	Py_DECREF(boot->args);
 	Py_XDECREF(boot->keyw);
 	PyMem_DEL(boot_raw);
+	nb_threads--;
 	PyThreadState_Clear(tstate);
 	PyThreadState_DeleteCurrent();
 	PyThread_exit_thread();
@@ -606,6 +608,24 @@
 A thread's identity may be reused for another thread after it exits.");
 
 static PyObject *
+thread__count(PyObject *self)
+{
+	return PyLong_FromLong(nb_threads);
+}
+
+PyDoc_STRVAR(_count_doc,
+"_count() -> integer\n\
+\n\
+\
+Return the number of currently running Python threads, excluding \n\
+the main thread. The returned number comprises all threads created\n\
+through `start_new_thread()` as well as `threading.Thread`, and not\n\
+yet finished.\n\
+\n\
+This function is meant for internal and specialized purposes only.\n\
+In most applications `threading.enumerate()` should be used instead.");
+
+static PyObject *
 thread_stack_size(PyObject *self, PyObject *args)
 {
 	size_t old_size;
@@ -678,6 +698,8 @@
 	 METH_NOARGS, interrupt_doc},
 	{"get_ident",		(PyCFunction)thread_get_ident, 
 	 METH_NOARGS, get_ident_doc},
+	{"_count",		(PyCFunction)thread__count, 
+	 METH_NOARGS, _count_doc},
 	{"stack_size",		(PyCFunction)thread_stack_size,
 				METH_VARARGS,
 				stack_size_doc},
@@ -748,6 +770,8 @@
 	if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0)
 		return NULL;
 
+	nb_threads = 0;
+
 	/* Initialize the C thread library */
 	PyThread_init_thread();
 	return m;
Modified: sandbox/trunk/newgil/Python/ast.c
==============================================================================
--- sandbox/trunk/newgil/Python/ast.c	(original)
+++ sandbox/trunk/newgil/Python/ast.c	Sun Nov 1 12:17:37 2009
@@ -3246,10 +3246,11 @@
 u = NULL;
 } else {
 /* check for integer overflow */
- if (len > PY_SIZE_MAX / 4)
+ if (len > PY_SIZE_MAX / 6)
 return NULL;
- /* "\XX" may become "\u005c\uHHLL" (12 bytes) */
- u = PyBytes_FromStringAndSize((char *)NULL, len * 4);
+ /* "ä" (2 bytes) may become "\U000000E4" (10 bytes), or 1:5
+ "\ä" (3 bytes) may become "\u005c\U000000E4" (16 bytes), or ~1:6 */
+ u = PyBytes_FromStringAndSize((char *)NULL, len * 6);
 if (u == NULL)
 return NULL;
 p = buf = PyBytes_AsString(u);
@@ -3266,20 +3267,24 @@
 PyObject *w;
 char *r;
 Py_ssize_t rn, i;
- w = decode_utf8(c, &s, end, "utf-16-be");
+ w = decode_utf8(c, &s, end, "utf-32-be");
 if (w == NULL) {
 Py_DECREF(u);
 return NULL;
 }
 r = PyBytes_AS_STRING(w);
 rn = Py_SIZE(w);
- assert(rn % 2 == 0);
- for (i = 0; i < rn; i += 2) {
- sprintf(p, "\\u%02x%02x",
+ assert(rn % 4 == 0);
+ for (i = 0; i < rn; i += 4) {
+ sprintf(p, "\\U%02x%02x%02x%02x",
 r[i + 0] & 0xFF,
- r[i + 1] & 0xFF);
- p += 6;
+ r[i + 1] & 0xFF,
+ r[i + 2] & 0xFF,
+ r[i + 3] & 0xFF);
+ p += 10;
 }
+ /* Should be impossible to overflow */
+ assert(p - buf <= Py_SIZE(u));
 Py_DECREF(w);
 } else {
 *p++ = *s++;
Modified: sandbox/trunk/newgil/Python/ceval.c
==============================================================================
--- sandbox/trunk/newgil/Python/ceval.c	(original)
+++ sandbox/trunk/newgil/Python/ceval.c	Sun Nov 1 12:17:37 2009
@@ -51,11 +51,29 @@
 	((long*)(v))[1] = tb;
 }
 
-#else /* this is for linux/x86 (and probably any other GCC/x86 combo) */
+#elif defined(__i386__)
+
+/* this is for linux/x86 (and probably any other GCC/x86 combo) */
 
 #define READ_TIMESTAMP(val) \
 __asm__ __volatile__("rdtsc" : "=A" (val))
 
+#elif defined(__x86_64__)
+
+/* for gcc/x86_64, the "A" constraint in DI mode means *either* rax *or* rdx;
+ not edx:eax as it does for i386. Since rdtsc puts its result in edx:eax
+ even in 64-bit mode, we need to use "a" and "d" for the lower and upper
+ 32-bit pieces of the result. */
+
+#define READ_TIMESTAMP(val) \
+ __asm__ __volatile__("rdtsc" : \
+ "=a" (((int*)&(val))[0]), "=d" (((int*)&(val))[1]));
+
+
+#else
+
+#error "Don't know how to implement timestamp counter for this architecture"
+
 #endif
 
 void dump_tsc(int opcode, int ticked, uint64 inst0, uint64 inst1,


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /