Skip to content

Commit a156e09

Browse files
committed
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60790 | raymond.hettinger | 2008-02-14 10:32:45 +0100 (Thu, 14 Feb 2008) | 4 lines Add diagnostic message to help figure-out why SocketServer tests occasionally crash when trying to remove a pid that in not in the activechildren list. ........ r60791 | raymond.hettinger | 2008-02-14 11:46:57 +0100 (Thu, 14 Feb 2008) | 1 line Add fixed-point examples to the decimal FAQ ........ r60792 | raymond.hettinger | 2008-02-14 12:01:10 +0100 (Thu, 14 Feb 2008) | 1 line Improve rst markup ........ r60794 | raymond.hettinger | 2008-02-14 12:57:25 +0100 (Thu, 14 Feb 2008) | 1 line Show how to remove exponents. ........ r60795 | raymond.hettinger | 2008-02-14 13:05:42 +0100 (Thu, 14 Feb 2008) | 1 line Fix markup. ........ r60797 | christian.heimes | 2008-02-14 13:47:33 +0100 (Thu, 14 Feb 2008) | 1 line Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation. ........ r60798 | raymond.hettinger | 2008-02-14 13:49:37 +0100 (Thu, 14 Feb 2008) | 1 line Simplify moneyfmt() recipe. ........ r60810 | raymond.hettinger | 2008-02-14 20:02:39 +0100 (Thu, 14 Feb 2008) | 1 line Fix markup ........ r60811 | raymond.hettinger | 2008-02-14 20:30:30 +0100 (Thu, 14 Feb 2008) | 1 line No need to register subclass of ABCs. ........ r60814 | thomas.heller | 2008-02-14 22:00:28 +0100 (Thu, 14 Feb 2008) | 1 line Try to correct a markup error that does hide the following paragraph. ........ r60822 | christian.heimes | 2008-02-14 23:40:11 +0100 (Thu, 14 Feb 2008) | 1 line Use a static and interned string for __subclasscheck__ and __instancecheck__ as suggested by Thomas Heller in python#2115 ........ r60827 | christian.heimes | 2008-02-15 07:57:08 +0100 (Fri, 15 Feb 2008) | 1 line Fixed repr() and str() of complex numbers. Complex suffered from the same problem as floats but I forgot to test and fix them. ........ r60830 | christian.heimes | 2008-02-15 09:20:11 +0100 (Fri, 15 Feb 2008) | 2 lines Bug python#2111: mmap segfaults when trying to write a block opened with PROT_READ Thanks to Thomas Herve for the fix. ........ r60835 | eric.smith | 2008-02-15 13:14:32 +0100 (Fri, 15 Feb 2008) | 1 line In PyNumber_ToBase, changed from an assert to returning an error when PyObject_Index() returns something other than an int or long. It should never be possible to trigger this, as PyObject_Index checks to make sure it returns an int or long. ........ r60837 | skip.montanaro | 2008-02-15 20:03:59 +0100 (Fri, 15 Feb 2008) | 8 lines Two new functions: * place_summary_first copies the regrtest summary to the front of the file making it easier to scan quickly for problems. * count_failures gets the actual count of the number of failing tests, not just a 1 (some failures) or 0 (no failures). ........ r60840 | raymond.hettinger | 2008-02-15 22:21:25 +0100 (Fri, 15 Feb 2008) | 1 line Update example to match the current syntax. ........ r60841 | amaury.forgeotdarc | 2008-02-15 22:22:45 +0100 (Fri, 15 Feb 2008) | 8 lines Issue python#2115: __slot__ attributes setting was 10x slower. Also correct a possible crash using ABCs. This change is exactly the same as an optimisation done 5 years ago, but on slot *access*: http://svn.python.org/view?view=rev&rev=28297 ........ r60842 | amaury.forgeotdarc | 2008-02-15 22:27:44 +0100 (Fri, 15 Feb 2008) | 2 lines Temporarily let these tests pass ........ r60843 | kurt.kaiser | 2008-02-15 22:56:36 +0100 (Fri, 15 Feb 2008) | 2 lines ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat. ........ r60844 | kurt.kaiser | 2008-02-15 23:25:09 +0100 (Fri, 15 Feb 2008) | 4 lines Configured selection highlighting colors were ignored; updating highlighting in the config dialog would cause non-Python files to be colored as if they were Python source; improve use of ColorDelagator. Patch 1334. Tal Einat. ........ r60845 | amaury.forgeotdarc | 2008-02-15 23:44:20 +0100 (Fri, 15 Feb 2008) | 9 lines Re-enable tests, they were failing since gc.collect() clears the various freelists. They still remain fragile. For example, a call to assertEqual currently does not make any allocation (which surprised me at first). But this can change when gc.collect also deletes the numerous "zombie frames" attached to each function. ........
1 parent 71316b0 commit a156e09

35 files changed

+401
-112
lines changed

Doc/c-api/method.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ no longer available.
9292
.. cfunction:: PyObject* PyMethod_GET_SELF(PyObject *meth)
9393

9494
Macro version of :cfunc:`PyMethod_Self` which avoids error checking.
95+
96+
97+
.. cfunction:: int PyMethod_ClearFreeList(void)
98+
99+
Clear the free list. Return the total number of freed items.
100+

Doc/c-api/set.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,11 @@ the constructor functions work with any iterable Python object.
5454

5555
Return true if *p* is a :class:`set` object or an instance of a subtype.
5656

57-
.. versionadded:: 2.6
58-
5957
.. cfunction:: int PyFrozenSet_Check(PyObject *p)
6058

6159
Return true if *p* is a :class:`frozenset` object or an instance of a
6260
subtype.
6361

64-
.. versionadded:: 2.6
65-
6662
.. cfunction:: int PyAnySet_Check(PyObject *p)
6763

6864
Return true if *p* is a :class:`set` object, a :class:`frozenset` object, or an

Doc/c-api/tuple.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ Tuple Objects
105105
this function. If the object referenced by ``*p`` is replaced, the original
106106
``*p`` is destroyed. On failure, returns ``-1`` and sets ``*p`` to *NULL*, and
107107
raises :exc:`MemoryError` or :exc:`SystemError`.
108+
109+
.. cfunction:: int PyMethod_ClearFreeList(void)
110+
111+
Clear the free list. Return the total number of freed items.

Doc/c-api/type.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ Type Objects
3737

3838
Clears the internal lookup cache. Return the current version tag.
3939

40-
.. versionadded:: 2.6
41-
4240

4341
.. cfunction:: int PyType_HasFeature(PyObject *o, int feature)
4442

Doc/c-api/unicode.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ access internal read-only data of Unicode objects:
8383
Return a pointer to the internal buffer of the object. *o* has to be a
8484
:ctype:`PyUnicodeObject` (not checked).
8585

86+
87+
.. cfunction:: int PyUnicode_ClearFreeList(void)
88+
89+
Clear the free list. Return the total number of freed items.
90+
8691
Unicode provides many different character properties. The most often needed ones
8792
are available through these macros which are mapped to C functions depending on
8893
the Python configuration.

Doc/library/ctypes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,6 @@ Fundamental data types
20102010
their methods and attributes.
20112011

20122012
.. versionchanged:: 2.6
2013-
20142013
ctypes data types that are not and do not contain pointers can
20152014
now be pickled.
20162015

Doc/library/decimal.rst

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,19 +1352,15 @@ to work with the :class:`Decimal` class::
13521352
'<.02>'
13531353

13541354
"""
1355-
q = Decimal((0, (1,), -places)) # 2 places --> '0.01'
1356-
sign, digits, exp = value.quantize(q).as_tuple()
1357-
assert exp == -places
1355+
q = Decimal(10) ** -places # 2 places --> '0.01'
1356+
sign, digits, exp = value.quantize(q).as_tuple()
13581357
result = []
13591358
digits = map(str, digits)
13601359
build, next = result.append, digits.pop
13611360
if sign:
13621361
build(trailneg)
13631362
for i in range(places):
1364-
if digits:
1365-
build(next())
1366-
else:
1367-
build('0')
1363+
build(next() if digits else '0')
13681364
build(dp)
13691365
i = 0
13701366
while digits:
@@ -1374,12 +1370,8 @@ to work with the :class:`Decimal` class::
13741370
i = 0
13751371
build(sep)
13761372
build(curr)
1377-
if sign:
1378-
build(neg)
1379-
else:
1380-
build(pos)
1381-
result.reverse()
1382-
return ''.join(result)
1373+
build(neg if sign else pos)
1374+
return ''.join(reversed(result))
13831375

13841376
def pi():
13851377
"""Compute Pi to the current precision.
@@ -1482,7 +1474,7 @@ Decimal FAQ
14821474
Q. It is cumbersome to type ``decimal.Decimal('1234.5')``. Is there a way to
14831475
minimize typing when using the interactive interpreter?
14841476

1485-
\A. Some users abbreviate the constructor to just a single letter::
1477+
A. Some users abbreviate the constructor to just a single letter::
14861478

14871479
>>> D = decimal.Decimal
14881480
>>> D('1.23') + D('3.45')
@@ -1513,9 +1505,36 @@ the :const:`Inexact` trap is set, it is also useful for validation::
15131505
Q. Once I have valid two place inputs, how do I maintain that invariant
15141506
throughout an application?
15151507

1516-
A. Some operations like addition and subtraction automatically preserve fixed
1517-
point. Others, like multiplication and division, change the number of decimal
1518-
places and need to be followed-up with a :meth:`quantize` step.
1508+
A. Some operations like addition, subtraction, and multiplication by an integer
1509+
will automatically preserve fixed point. Others operations, like division and
1510+
non-integer multiplication, will change the number of decimal places and need to
1511+
be followed-up with a :meth:`quantize` step::
1512+
1513+
>>> a = Decimal('102.72') # Initial fixed-point values
1514+
>>> b = Decimal('3.17')
1515+
>>> a + b # Addition preserves fixed-point
1516+
Decimal('105.89')
1517+
>>> a - b
1518+
Decimal('99.55')
1519+
>>> a * 42 # So does integer multiplication
1520+
Decimal('4314.24')
1521+
>>> (a * b).quantize(TWOPLACES) # Must quantize non-integer multiplication
1522+
Decimal('325.62')
1523+
>>> (b / a).quantize(TWOPLACES) # And quantize division
1524+
Decimal('0.03')
1525+
1526+
In developing fixed-point applications, it is convenient to define functions
1527+
to handle the :meth:`quantize` step::
1528+
1529+
>>> def mul(x, y, fp=TWOPLACES):
1530+
... return (x * y).quantize(fp)
1531+
>>> def div(x, y, fp=TWOPLACES):
1532+
... return (x / y).quantize(fp)
1533+
1534+
>>> mul(a, b) # Automatically preserve fixed-point
1535+
Decimal('325.62')
1536+
>>> div(b, a)
1537+
Decimal('0.03')
15191538

15201539
Q. There are many ways to express the same value. The numbers :const:`200`,
15211540
:const:`200.000`, :const:`2E2`, and :const:`.02E+4` all have the same value at
@@ -1537,6 +1556,16 @@ of significant places in the coefficient. For example, expressing
15371556
:const:`5.0E+3` as :const:`5000` keeps the value constant but cannot show the
15381557
original's two-place significance.
15391558

1559+
If an application does not care about tracking significance, it is easy to
1560+
remove the exponent and trailing zeroes, losing signficance, but keeping the
1561+
value unchanged::
1562+
1563+
>>> def remove_exponent(d):
1564+
... return d.quantize(Decimal(1)) if d == d.to_integral() else d.normalize()
1565+
1566+
>>> remove_exponent(Decimal('5E+3'))
1567+
Decimal('5000')
1568+
15401569
Q. Is there a way to convert a regular float to a :class:`Decimal`?
15411570

15421571
A. Yes, all binary floating point numbers can be exactly expressed as a

Doc/whatsnew/2.6.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ complete list of changes, or look through the CVS logs for all the details.
825825
int int
826826
>>> var._asdict()
827827
{'size': 4, 'type': 'int', 'id': 1, 'name': 'frequency'}
828-
>>> v2 = var._replace('name', 'amplitude')
828+
>>> v2 = var._replace(name='amplitude')
829829
>>> v2
830830
variable(id=1, name='amplitude', type='int', size=4)
831831

Include/classobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
3131
#define PyMethod_GET_SELF(meth) \
3232
(((PyMethodObject *)meth) -> im_self)
3333

34+
PyAPI_FUNC(int) PyMethod_ClearFreeList(void);
3435

3536
typedef struct {
3637
PyObject_HEAD

Include/frameobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int);
7373
PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
7474
PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
7575

76+
PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
77+
7678
#ifdef __cplusplus
7779
}
7880
#endif

0 commit comments

Comments
 (0)