979
982
largeString = 'z' * (100 * 1024)
980
983
myPickle = cPickle.dumps(largeString, protocol=1)
984
diff -r 70274d53c1dd Doc/faq/programming.rst
985
--- a/Doc/faq/programming.rst
986
+++ b/Doc/faq/programming.rst
988
apply(g, (x,)+args, kwargs)
991
+.. _faq-argument-vs-parameter:
993
+What is the difference between arguments and parameters?
994
+--------------------------------------------------------
996
+:term:`Parameters <parameter>` are defined by the names that appear in a
997
+function definition, whereas :term:`arguments <argument>` are the values
998
+actually passed to a function when calling it. Parameters define what types of
999
+arguments a function can accept. For example, given the function definition::
1001
+ def func(foo, bar=None, **kwargs):
1004
+*foo*, *bar* and *kwargs* are parameters of ``func``. However, when calling
1005
+``func``, for example::
1007
+ func(42, bar=314, extra=somevar)
1009
+the values ``42``, ``314``, and ``somevar`` are arguments.
1012
How do I write a function with output parameters (call by reference)?
1013
---------------------------------------------------------------------
981
1015
diff -r 70274d53c1dd Doc/faq/windows.rst
982
1016
--- a/Doc/faq/windows.rst
983
1017
+++ b/Doc/faq/windows.rst
1011
1045
diff -r 70274d53c1dd Doc/glossary.rst
1012
1046
--- a/Doc/glossary.rst
1013
1047
+++ b/Doc/glossary.rst
1049
create your own ABCs with the :mod:`abc` module.
1052
- A value passed to a function or method, assigned to a named local
1053
- variable in the function body. A function or method may have both
1054
- positional arguments and keyword arguments in its definition.
1055
- Positional and keyword arguments may be variable-length: ``*`` accepts
1056
- or passes (if in the function definition or call) several positional
1057
- arguments in a list, while ``**`` does the same for keyword arguments
1059
+ A value passed to a :term:`function` (or :term:`method`) when calling the
1060
+ function. There are two types of arguments:
1062
- Any expression may be used within the argument list, and the evaluated
1063
- value is passed to the local variable.
1064
+ * :dfn:`keyword argument`: an argument preceded by an identifier (e.g.
1065
+ ``name=``) in a function call or passed as a value in a dictionary
1066
+ preceded by ``**``. For example, ``3`` and ``5`` are both keyword
1067
+ arguments in the following calls to :func:`complex`::
1069
+ complex(real=3, imag=5)
1070
+ complex(**{'real': 3, 'imag': 5})
1072
+ * :dfn:`positional argument`: an argument that is not a keyword argument.
1073
+ Positional arguments can appear at the beginning of an argument list
1074
+ and/or be passed as elements of an :term:`iterable` preceded by ``*``.
1075
+ For example, ``3`` and ``5`` are both positional arguments in the
1081
+ Arguments are assigned to the named local variables in a function body.
1082
+ See the :ref:`calls` section for the rules governing this assignment.
1083
+ Syntactically, any expression can be used to represent an argument; the
1084
+ evaluated value is assigned to the local variable.
1086
+ See also the :term:`parameter` glossary entry and the FAQ question on
1087
+ :ref:`the difference between arguments and parameters
1088
+ <faq-argument-vs-parameter>`.
1091
A value associated with an object which is referenced by name using
1017
1095
Any class which does not inherit from :class:`object`. See
1042
1120
(for example standard input/output, in-memory buffers, sockets, pipes,
1043
1121
etc.). File objects are also called :dfn:`file-like objects` or
1044
1122
:dfn:`streams`.
1123
@@ -406,16 +424,13 @@
1046
1124
:meth:`str.lower` method can serve as a key function for case insensitive
1047
1125
sorts. Alternatively, an ad-hoc key function can be built from a
1048
1126
:keyword:`lambda` expression such as ``lambda r: (r[0], r[2])``. Also,
1051
1129
:func:`~operator.attrgetter`, :func:`~operator.itemgetter`, and
1052
1130
:func:`~operator.methodcaller`. See the :ref:`Sorting HOW TO
1053
1131
<sortinghowto>` for examples of how to create and use key functions.
1054
@@ -630,6 +630,13 @@
1134
- Arguments which are preceded with a ``variable_name=`` in the call.
1135
- The variable name designates the local name in the function to which the
1136
- value is assigned. ``**`` is used to accept or pass a dictionary of
1137
- keyword arguments. See :term:`argument`.
1138
+ See :term:`argument`.
1141
An anonymous inline function consisting of a single :term:`expression`
1142
@@ -537,12 +552,46 @@
1143
(methods). Also the ultimate base class of any :term:`new-style
1147
+ A named entity in a :term:`function` (or method) definition that
1148
+ specifies an :term:`argument` (or in some cases, arguments) that the
1149
+ function can accept. There are four types of parameters:
1151
+ * :dfn:`positional-or-keyword`: specifies an argument that can be passed
1152
+ either :term:`positionally <argument>` or as a :term:`keyword argument
1153
+ <argument>`. This is the default kind of parameter, for example *foo*
1154
+ and *bar* in the following::
1156
+ def func(foo, bar=None): ...
1158
+ * :dfn:`positional-only`: specifies an argument that can be supplied only
1159
+ by position. Python has no syntax for defining positional-only
1160
+ parameters. However, some built-in functions have positional-only
1161
+ parameters (e.g. :func:`abs`).
1163
+ * :dfn:`var-positional`: specifies that an arbitrary sequence of
1164
+ positional arguments can be provided (in addition to any positional
1165
+ arguments already accepted by other parameters). Such a parameter can
1166
+ be defined by prepending the parameter name with ``*``, for example
1167
+ *args* in the following::
1169
+ def func(*args, **kwargs): ...
1171
+ * :dfn:`var-keyword`: specifies that arbitrarily many keyword arguments
1172
+ can be provided (in addition to any keyword arguments already accepted
1173
+ by other parameters). Such a parameter can be defined by prepending
1174
+ the parameter name with ``**``, for example *kwargs* in the example
1177
+ Parameters can specify both optional and required arguments, as well as
1178
+ default values for some optional arguments.
1180
+ See also the :term:`argument` glossary entry, the FAQ question on
1181
+ :ref:`the difference between arguments and parameters
1182
+ <faq-argument-vs-parameter>`, and the :ref:`function` section.
1185
- The arguments assigned to local names inside a function or method,
1186
- determined by the order in which they were given in the call. ``*`` is
1187
- used to either accept multiple positional arguments (when in the
1188
- definition), or pass several arguments as a list to a function. See
1190
+ See :term:`argument`.
1193
Nickname for the Python 3.x release line (coined long ago when the release
1194
@@ -630,6 +679,13 @@
1055
1195
object has a type. An object's type is accessible as its
1056
1196
:attr:`__class__` attribute or can be retrieved with ``type(obj)``.
3791
3931
... return timedelta(0)
3792
3932
... def tzname(self,dt):
3933
@@ -1145,7 +1154,7 @@
3934
A time object represents a (local) time of day, independent of any particular
3935
day, and subject to adjustment via a :class:`tzinfo` object.
3937
-.. class:: time(hour[, minute[, second[, microsecond[, tzinfo]]]])
3938
+.. class:: time([hour[, minute[, second[, microsecond[, tzinfo]]]]])
3940
All arguments are optional. *tzinfo* may be ``None``, or an instance of a
3941
:class:`tzinfo` subclass. The remaining arguments may be ints or longs, in the
3793
3942
@@ -1521,6 +1530,21 @@
3794
3943
other fixed-offset :class:`tzinfo` subclass (such as a class representing only
3795
3944
EST (fixed offset -5 hours), or only EDT (fixed offset -4 hours)).
4361
4510
.. module:: email.utils
4362
4511
:synopsis: Miscellaneous email package utilities.
4512
diff -r 70274d53c1dd Doc/library/exceptions.rst
4513
--- a/Doc/library/exceptions.rst
4514
+++ b/Doc/library/exceptions.rst
4515
@@ -387,6 +387,30 @@
4516
Raised when a Unicode-related encoding or decoding error occurs. It is a
4517
subclass of :exc:`ValueError`.
4519
+ :exc:`UnicodeError` has attributes that describe the encoding or decoding
4520
+ error. For example, ``err.object[err.start:err.end]`` gives the particular
4521
+ invalid input that the codec failed on.
4523
+ .. attribute:: encoding
4525
+ The name of the encoding that raised the error.
4527
+ .. attribute:: reason
4529
+ A string describing the specific codec error.
4531
+ .. attribute:: object
4533
+ The object the codec was attempting to encode or decode.
4535
+ .. attribute:: start
4537
+ The first index of invalid data in :attr:`object`.
4539
+ .. attribute:: end
4541
+ The index after the last invalid data in :attr:`object`.
4543
.. versionadded:: 2.0
4363
4546
diff -r 70274d53c1dd Doc/library/filecmp.rst
4364
4547
--- a/Doc/library/filecmp.rst
4365
4548
+++ b/Doc/library/filecmp.rst
5276
5470
:func:`find_module` and :func:`load_module` to find and load package *P*, and
5277
5471
then use :func:`find_module` with the *path* argument set to ``P.__path__``.
5278
5472
When *P* itself has a dotted name, apply this recipe recursively.
5473
@@ -237,6 +237,17 @@
5474
using shared libraries is highly system dependent, and not all systems support
5479
+ The import internals identify extension modules by filename, so doing
5480
+ ``foo = load_dynamic("foo", "mod.so")`` and
5481
+ ``bar = load_dynamic("bar", "mod.so")`` will result in both foo and bar
5482
+ referring to the same module, regardless of whether or not
5483
+ ``mod.so`` exports an ``initbar`` function. On systems which
5484
+ support them, symlinks can be used to import multiple modules from
5485
+ the same shared library, as each reference to the module will use
5486
+ a different file name.
5489
.. function:: load_source(name, pathname[, file])
5279
5491
diff -r 70274d53c1dd Doc/library/imputil.rst
5280
5492
--- a/Doc/library/imputil.rst
5281
5493
+++ b/Doc/library/imputil.rst
5452
5664
:mod:`json` exposes an API familiar to users of the standard library
5453
5665
:mod:`marshal` and :mod:`pickle` modules.
5454
@@ -99,35 +101,43 @@
5670
- >>> print json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
5671
+ >>> print json.dumps({'4': 5, '6': 7}, sort_keys=True,
5672
+ ... indent=4, separators=(',', ': '))
5676
@@ -99,35 +102,43 @@
5507
5729
If *check_circular* is ``False`` (default: ``True``), then the circular
5508
5730
reference check for container types will be skipped and a circular reference
5731
@@ -143,6 +154,12 @@
5732
or negative, will only insert newlines. ``None`` (the default) selects the
5733
most compact representation.
5737
+ Since the default item separator is ``', '``, the output might include
5738
+ trailing whitespace when *indent* is specified. You can use
5739
+ ``separators=(',', ': ')`` to avoid this.
5741
If *separators* is an ``(item_separator, dict_separator)`` tuple, then it
5742
will be used instead of the default ``(', ', ': ')`` separators. ``(',',
5743
':')`` is the most compact JSON representation.
5510
5745
*default(obj)* is a function that should return a serializable version of
5511
5746
*obj* or raise :exc:`TypeError`. The default simply raises :exc:`TypeError`.
5606
5841
If *check_circular* is ``True`` (the default), then lists, dicts, and custom
5607
5842
encoded objects will be checked for circular references during encoding to
5608
@@ -427,3 +458,108 @@
5843
@@ -379,6 +417,12 @@
5844
level. An indent level of 0 will only insert newlines. ``None`` is the most
5845
compact representation.
5849
+ Since the default item separator is ``', '``, the output might include
5850
+ trailing whitespace when *indent* is specified. You can use
5851
+ ``separators=(',', ': ')`` to avoid this.
5853
If specified, *separators* should be an ``(item_separator, key_separator)``
5854
tuple. The default is ``(', ', ': ')``. To get the most compact JSON
5855
representation, you should specify ``(',', ':')`` to eliminate whitespace.
5856
@@ -427,3 +471,108 @@
5610
5858
for chunk in JSONEncoder().iterencode(bigobject):
5611
5859
mysocket.write(chunk)
6539
6787
.. class:: POP3(host[, port[, timeout]])
6788
diff -r 70274d53c1dd Doc/library/pprint.rst
6789
--- a/Doc/library/pprint.rst
6790
+++ b/Doc/library/pprint.rst
6792
.. First the implementation class:
6795
-.. class:: PrettyPrinter(...)
6796
+.. class:: PrettyPrinter(indent=1, width=80, depth=None, stream=None)
6798
Construct a :class:`PrettyPrinter` instance. This constructor understands
6799
several keyword parameters. An output stream may be set using the *stream*
6802
The :class:`PrettyPrinter` class supports several derivative functions:
6804
-.. Now the derivative functions:
6806
-.. function:: pformat(object[, indent[, width[, depth]]])
6807
+.. function:: pformat(object, indent=1, width=80, depth=None)
6809
Return the formatted representation of *object* as a string. *indent*, *width*
6810
and *depth* will be passed to the :class:`PrettyPrinter` constructor as
6812
The parameters *indent*, *width* and *depth* were added.
6815
-.. function:: pprint(object[, stream[, indent[, width[, depth]]]])
6816
+.. function:: pprint(object, stream=None, indent=1, width=80, depth=None)
6818
Prints the formatted representation of *object* on *stream*, followed by a
6819
- newline. If *stream* is omitted, ``sys.stdout`` is used. This may be used in
6820
+ newline. If *stream* is ``None``, ``sys.stdout`` is used. This may be used in
6821
the interactive interpreter instead of a :keyword:`print` statement for
6822
inspecting values. *indent*, *width* and *depth* will be passed to the
6823
:class:`PrettyPrinter` constructor as formatting parameters.
6828
-This example demonstrates several uses of the :func:`pprint` function and its parameters.
6829
+This example demonstrates several uses of the :func:`pprint` function and its
6833
>>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead',
6540
6834
diff -r 70274d53c1dd Doc/library/profile.rst
6541
6835
--- a/Doc/library/profile.rst
6542
6836
+++ b/Doc/library/profile.rst
8556
8850
.. versionadded:: 2.2
8558
@@ -2378,7 +2399,7 @@
8852
@@ -2309,7 +2330,7 @@
8854
with open("hello.txt") as f:
8859
In older versions of Python, you would have needed to do this to get the same
8861
@@ -2317,7 +2338,7 @@
8862
f = open("hello.txt")
8870
@@ -2371,14 +2392,14 @@
8872
A file object is its own iterator, for example ``iter(f)`` returns *f* (unless
8873
*f* is closed). When a file is used as an iterator, typically in a
8874
- :keyword:`for` loop (for example, ``for line in f: print line``), the
8875
+ :keyword:`for` loop (for example, ``for line in f: print line.strip()``), the
8876
:meth:`~file.next` method is called repeatedly. This method returns the next input
8877
line, or raises :exc:`StopIteration` when EOF is hit when the file is open for
8878
reading (behavior is undefined when the file is open for writing). In order to
8559
8879
make a :keyword:`for` loop the most efficient way of looping over the lines of a
8560
8880
file (a very common operation), the :meth:`~file.next` method uses a hidden read-ahead
8561
8881
buffer. As a consequence of using a read-ahead buffer, combining :meth:`~file.next`
11519
11850
"Private" instance variables that cannot be accessed except from inside an
11520
11851
object don't exist in Python. However, there is a convention that is followed
11852
@@ -688,7 +688,7 @@
11855
for line in open("myfile.txt"):
11859
This style of access is clear, concise, and convenient. The use of iterators
11860
pervades and unifies Python. Behind the scenes, the :keyword:`for` statement
11521
11861
diff -r 70274d53c1dd Doc/tutorial/controlflow.rst
11522
11862
--- a/Doc/tutorial/controlflow.rst
11523
11863
+++ b/Doc/tutorial/controlflow.rst
11795
12135
... print 'x =', x
11796
12136
... print 'y =', y
12138
@@ -389,7 +397,7 @@
12139
and print its contents to the screen. ::
12141
for line in open("myfile.txt"):
12145
The problem with this code is that it leaves the file open for an indeterminate
12146
amount of time after the code has finished executing. This is not an issue in
12147
@@ -399,7 +407,7 @@
12149
with open("myfile.txt") as f:
12154
After the statement is executed, the file *f* is always closed, even if a
12155
problem was encountered while processing the lines. Other objects which provide
11798
12156
diff -r 70274d53c1dd Doc/tutorial/index.rst
11799
12157
--- a/Doc/tutorial/index.rst
11800
12158
+++ b/Doc/tutorial/index.rst
12281
12639
diff -r 70274d53c1dd Include/pyport.h
12282
12640
--- a/Include/pyport.h
12283
12641
+++ b/Include/pyport.h
12284
@@ -549,6 +549,30 @@
12643
* uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.
12644
* However, it doesn't set HAVE_UINT32_T, so we do that here.
12646
-#if (defined UINT32_MAX || defined uint32_t)
12648
+#define HAVE_UINT32_T 1
12651
+#ifdef HAVE_UINT32_T
12652
#ifndef PY_UINT32_T
12653
-#define HAVE_UINT32_T 1
12654
#define PY_UINT32_T uint32_t
12657
@@ -103,23 +106,33 @@
12658
/* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the
12659
* long integer implementation, when 30-bit digits are enabled.
12661
-#if (defined UINT64_MAX || defined uint64_t)
12663
+#define HAVE_UINT64_T 1
12666
+#ifdef HAVE_UINT64_T
12667
#ifndef PY_UINT64_T
12668
-#define HAVE_UINT64_T 1
12669
#define PY_UINT64_T uint64_t
12673
/* Signed variants of the above */
12674
-#if (defined INT32_MAX || defined int32_t)
12676
+#define HAVE_INT32_T 1
12679
+#ifdef HAVE_INT32_T
12681
-#define HAVE_INT32_T 1
12682
#define PY_INT32_T int32_t
12685
-#if (defined INT64_MAX || defined int64_t)
12688
+#define HAVE_INT64_T 1
12691
+#ifdef HAVE_INT64_T
12693
-#define HAVE_INT64_T 1
12694
#define PY_INT64_T int64_t
12697
@@ -549,6 +562,30 @@
12285
12698
_Py_set_387controlword(old_387controlword)
12334
12747
/* XXX signal handlers should also be here */
12336
12749
} PyThreadState;
12750
diff -r 70274d53c1dd Include/weakrefobject.h
12751
--- a/Include/weakrefobject.h
12752
+++ b/Include/weakrefobject.h
12755
PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
12757
-#define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object)
12758
+/* Explanation for the Py_REFCNT() check: when a weakref's target is part
12759
+ of a long chain of deallocations which triggers the trashcan mechanism,
12760
+ clearing the weakrefs can be delayed long after the target's refcount
12761
+ has dropped to zero. In the meantime, code accessing the weakref will
12762
+ be able to "see" the target object even though it is supposed to be
12763
+ unreachable. See issue #16602. */
12765
+#define PyWeakref_GET_OBJECT(ref) \
12766
+ (Py_REFCNT(((PyWeakReference *)(ref))->wr_object) > 0 \
12767
+ ? ((PyWeakReference *)(ref))->wr_object \
12337
12772
diff -r 70274d53c1dd Lib/BaseHTTPServer.py
12338
12773
--- a/Lib/BaseHTTPServer.py
12339
12774
+++ b/Lib/BaseHTTPServer.py
13048
13483
diff -r 70274d53c1dd Lib/collections.py
13049
13484
--- a/Lib/collections.py
13050
13485
+++ b/Lib/collections.py
13487
__all__ += _abcoll.__all__
13489
from _collections import deque, defaultdict
13490
-from operator import itemgetter as _itemgetter
13491
+from operator import itemgetter as _itemgetter, eq as _eq
13492
from keyword import iskeyword as _iskeyword
13494
import heapq as _heapq
13495
from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
13496
+from itertools import imap as _imap
13499
from thread import get_ident as _get_ident
13500
@@ -50,49 +51,45 @@
13502
self.__update(*args, **kwds)
13504
- def __setitem__(self, key, value, PREV=0, NEXT=1, dict_setitem=dict.__setitem__):
13505
+ def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
13506
'od.__setitem__(i, y) <==> od[i]=y'
13507
# Setting a new item creates a new link at the end of the linked list,
13508
# and the inherited dictionary is updated with the new key/value pair.
13509
if key not in self:
13052
13510
root = self.__root
13054
last[NEXT] = root[PREV] = self.__map[key] = [last, root, key]
13511
- last = root[PREV]
13512
- last[NEXT] = root[PREV] = self.__map[key] = [last, root, key]
13055
13513
- dict_setitem(self, key, value)
13515
+ last[1] = root[0] = self.__map[key] = [last, root, key]
13056
13516
+ return dict_setitem(self, key, value)
13058
def __delitem__(self, key, PREV=0, NEXT=1, dict_delitem=dict.__delitem__):
13518
- def __delitem__(self, key, PREV=0, NEXT=1, dict_delitem=dict.__delitem__):
13519
+ def __delitem__(self, key, dict_delitem=dict.__delitem__):
13059
13520
'od.__delitem__(y) <==> del od[y]'
13521
# Deleting an existing item uses self.__map to find the link which gets
13522
# removed by updating the links in the predecessor and successor nodes.
13523
dict_delitem(self, key)
13524
link_prev, link_next, key = self.__map.pop(key)
13525
- link_prev[NEXT] = link_next
13526
- link_next[PREV] = link_prev
13527
+ link_prev[1] = link_next # update link_prev[NEXT]
13528
+ link_next[0] = link_prev # update link_next[PREV]
13530
def __iter__(self):
13531
'od.__iter__() <==> iter(od)'
13532
# Traverse the linked list in order.
13535
- curr = root[NEXT]
13536
+ curr = root[1] # start at the first node
13537
while curr is not root:
13539
- curr = curr[NEXT]
13540
+ yield curr[2] # yield the curr[KEY]
13541
+ curr = curr[1] # move to next node
13543
def __reversed__(self):
13544
'od.__reversed__() <==> reversed(od)'
13545
# Traverse the linked list in reverse order.
13548
- curr = root[PREV]
13549
+ curr = root[0] # start at the last node
13550
while curr is not root:
13552
- curr = curr[PREV]
13553
+ yield curr[2] # yield the curr[KEY]
13554
+ curr = curr[0] # move to previous node
13062
13556
def clear(self):
13063
13557
'od.clear() -> None. Remove all items from od.'
13066
13560
root = self.__root
13067
13561
root[:] = [root, root, None]
13068
13562
self.__map.clear()
13069
@@ -234,10 +232,60 @@
13563
@@ -208,7 +205,7 @@
13566
if isinstance(other, OrderedDict):
13567
- return len(self)==len(other) and self.items() == other.items()
13568
+ return dict.__eq__(self, other) and all(_imap(_eq, self, other))
13569
return dict.__eq__(self, other)
13571
def __ne__(self, other):
13572
@@ -234,10 +231,60 @@
13070
13573
### namedtuple
13071
13574
################################################################################
13416
13919
def _dist_path(self, path):
13920
diff -r 70274d53c1dd Lib/distutils/command/check.py
13921
--- a/Lib/distutils/command/check.py
13922
+++ b/Lib/distutils/command/check.py
13925
def system_message(self, level, message, *children, **kwargs):
13926
self.messages.append((level, message, children, kwargs))
13927
+ return nodes.system_message(message, level=level,
13928
+ type=self.levels[level],
13929
+ *children, **kwargs)
13931
HAS_DOCUTILS = True
13932
except ImportError:
13417
13933
diff -r 70274d53c1dd Lib/distutils/config.py
13418
13934
--- a/Lib/distutils/config.py
13419
13935
+++ b/Lib/distutils/config.py
13936
@@ -42,16 +42,11 @@
13421
13937
def _store_pypirc(self, username, password):
13422
13938
"""Creates a default .pypirc file."""
13423
13939
rc = self._get_rc_file()
13690
14215
def test_suite():
13691
14216
return unittest.makeSuite(InstallTestCase)
14218
diff -r 70274d53c1dd Lib/distutils/tests/test_register.py
14219
--- a/Lib/distutils/tests/test_register.py
14220
+++ b/Lib/distutils/tests/test_register.py
14222
# -*- encoding: utf8 -*-
14223
"""Tests for distutils.command.register."""
14228
@@ -11,11 +10,14 @@
14230
from distutils.command import register as register_module
14231
from distutils.command.register import register
14232
-from distutils.core import Distribution
14233
from distutils.errors import DistutilsSetupError
14235
-from distutils.tests import support
14236
-from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
14237
+from distutils.tests.test_config import PyPIRCCommandTestCase
14241
+except ImportError:
14244
PYPIRC_NOPASSWORD = """\
14246
@@ -192,6 +194,7 @@
14247
self.assertEqual(headers['Content-length'], '290')
14248
self.assertTrue('tarek' in req.data)
14250
+ @unittest.skipUnless(docutils is not None, 'needs docutils')
14251
def test_strict(self):
14252
# testing the script option
14253
# when on, the register command stops if
14254
@@ -204,13 +207,6 @@
14256
self.assertRaises(DistutilsSetupError, cmd.run)
14258
- # we don't test the reSt feature if docutils
14259
- # is not installed
14262
- except ImportError:
14265
# metadata are OK but long_description is broken
14266
metadata = {'url': 'xxx', 'author': 'xxx',
14267
'author_email': u'éxéxé',
14268
@@ -264,6 +260,21 @@
14270
del register_module.raw_input
14272
+ @unittest.skipUnless(docutils is not None, 'needs docutils')
14273
+ def test_register_invalid_long_description(self):
14274
+ description = ':funkie:`str`' # mimic Sphinx-specific markup
14275
+ metadata = {'url': 'xxx', 'author': 'xxx',
14276
+ 'author_email': 'xxx',
14277
+ 'name': 'xxx', 'version': 'xxx',
14278
+ 'long_description': description}
14279
+ cmd = self._get_cmd(metadata)
14280
+ cmd.ensure_finalized()
14281
+ cmd.strict = True
14282
+ inputs = RawInputs('2', 'tarek', 'tarek@ziade.org')
14283
+ register_module.raw_input = inputs
14284
+ self.addCleanup(delattr, register_module, 'raw_input')
14285
+ self.assertRaises(DistutilsSetupError, cmd.run)
14287
def test_check_metadata_deprecated(self):
14288
# makes sure make_metadata is deprecated
14289
cmd = self._get_cmd()
13693
14290
diff -r 70274d53c1dd Lib/distutils/tests/test_sdist.py
13694
14291
--- a/Lib/distutils/tests/test_sdist.py
13695
14292
+++ b/Lib/distutils/tests/test_sdist.py
14803
15400
diff -r 70274d53c1dd Lib/json/__init__.py
14804
15401
--- a/Lib/json/__init__.py
14805
15402
+++ b/Lib/json/__init__.py
15407
- >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
15408
- >>> print '\n'.join([l.rstrip() for l in s.splitlines()])
15409
+ >>> print json.dumps({'4': 5, '6': 7}, sort_keys=True,
15410
+ ... indent=4, separators=(',', ': '))
14806
15414
@@ -95,7 +95,7 @@
14807
15415
"json": "obj"
14842
15450
If ``check_circular`` is false, then the circular reference check
14843
15451
for container types will be skipped and a circular reference will
14844
@@ -158,6 +161,9 @@
15452
@@ -147,7 +150,9 @@
15453
If ``indent`` is a non-negative integer, then JSON array elements and
15454
object members will be pretty-printed with that indent level. An indent
15455
level of 0 will only insert newlines. ``None`` is the most compact
15457
+ representation. Since the default item separator is ``', '``, the
15458
+ output might include trailing whitespace when ``indent`` is specified.
15459
+ You can use ``separators=(',', ': ')`` to avoid this.
15461
If ``separators`` is an ``(item_separator, dict_separator)`` tuple
15462
then it will be used instead of the default ``(', ', ': ')`` separators.
15463
@@ -158,6 +163,9 @@
14845
15464
``default(obj)`` is a function that should return a serializable version
14846
15465
of obj or raise TypeError. The default simply raises TypeError.
14890
15509
If ``check_circular`` is false, then the circular reference check
14891
15510
for container types will be skipped and a circular reference will
14892
@@ -218,6 +223,9 @@
15511
@@ -207,7 +214,9 @@
15512
If ``indent`` is a non-negative integer, then JSON array elements and
15513
object members will be pretty-printed with that indent level. An indent
15514
level of 0 will only insert newlines. ``None`` is the most compact
15516
+ representation. Since the default item separator is ``', '``, the
15517
+ output might include trailing whitespace when ``indent`` is specified.
15518
+ You can use ``separators=(',', ': ')`` to avoid this.
15520
If ``separators`` is an ``(item_separator, dict_separator)`` tuple
15521
then it will be used instead of the default ``(', ', ': ')`` separators.
15522
@@ -218,6 +227,9 @@
14893
15523
``default(obj)`` is a function that should return a serializable version
14894
15524
of obj or raise TypeError. The default simply raises TypeError.
15000
15630
If check_circular is true, then lists, dicts, and custom encoded
15001
15631
objects will be checked for circular references during encoding to
15632
@@ -129,7 +131,10 @@
15633
If indent is a non-negative integer, then JSON array
15634
elements and object members will be pretty-printed with that
15635
indent level. An indent level of 0 will only insert newlines.
15636
- None is the most compact representation.
15637
+ None is the most compact representation. Since the default
15638
+ item separator is ', ', the output might include trailing
15639
+ whitespace when indent is specified. You can use
15640
+ separators=(',', ': ') to avoid this.
15642
If specified, separators should be a (item_separator, key_separator)
15643
tuple. The default is (', ', ': '). To get the most compact JSON
15002
15644
diff -r 70274d53c1dd Lib/json/tests/test_decode.py
15003
15645
--- a/Lib/json/tests/test_decode.py
15004
15646
+++ b/Lib/json/tests/test_decode.py
15174
15816
class TestPyPass1(TestPass1, PyTest): pass
15817
diff -r 70274d53c1dd Lib/json/tests/test_tool.py
15819
+++ b/Lib/json/tests/test_tool.py
15826
+from test import test_support
15827
+from test.script_helper import assert_python_ok
15829
+class TestTool(unittest.TestCase):
15832
+ [["blorpie"],[ "whoops" ] , [
15833
+ ],\t"d-shtaeou",\r"d-nthiouh",
15834
+ "i-vhbjkhnth", {"nifty":87}, {"morefield" :\tfalse,"field"
15838
+ expect = textwrap.dedent("""\
15855
+ "morefield": false
15860
+ def test_stdin_stdout(self):
15861
+ proc = subprocess.Popen(
15862
+ (sys.executable, '-m', 'json.tool'),
15863
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
15864
+ out, err = proc.communicate(self.data.encode())
15865
+ self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
15866
+ self.assertEqual(err, None)
15868
+ def _create_infile(self):
15869
+ infile = test_support.TESTFN
15870
+ with open(infile, "w") as fp:
15871
+ self.addCleanup(os.remove, infile)
15872
+ fp.write(self.data)
15875
+ def test_infile_stdout(self):
15876
+ infile = self._create_infile()
15877
+ rc, out, err = assert_python_ok('-m', 'json.tool', infile)
15878
+ self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
15879
+ self.assertEqual(err, b'')
15881
+ def test_infile_outfile(self):
15882
+ infile = self._create_infile()
15883
+ outfile = test_support.TESTFN + '.out'
15884
+ rc, out, err = assert_python_ok('-m', 'json.tool', infile, outfile)
15885
+ self.addCleanup(os.remove, outfile)
15886
+ with open(outfile, "r") as fp:
15887
+ self.assertEqual(fp.read(), self.expect)
15888
+ self.assertEqual(out, b'')
15889
+ self.assertEqual(err, b'')
15175
15890
diff -r 70274d53c1dd Lib/json/tool.py
15176
15891
--- a/Lib/json/tool.py
15177
15892
+++ b/Lib/json/tool.py
15902
@@ -25,12 +25,15 @@
15903
outfile = open(sys.argv[2], 'wb')
15905
raise SystemExit(sys.argv[0] + " [infile [outfile]]")
15907
- obj = json.load(infile)
15908
- except ValueError, e:
15909
- raise SystemExit(e)
15910
- json.dump(obj, outfile, sort_keys=True, indent=4)
15911
- outfile.write('\n')
15914
+ obj = json.load(infile)
15915
+ except ValueError, e:
15916
+ raise SystemExit(e)
15918
+ json.dump(obj, outfile, sort_keys=True,
15919
+ indent=4, separators=(',', ': '))
15920
+ outfile.write('\n')
15923
if __name__ == '__main__':
15187
15924
diff -r 70274d53c1dd Lib/keyword.py
15188
15925
--- a/Lib/keyword.py
15189
15926
+++ b/Lib/keyword.py
15254
16005
def _options(self, cnf, kw = None):
15255
16006
"""Internal function."""
16008
@@ -1685,7 +1713,9 @@
16009
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
16012
- self.readprofile(baseName, className)
16013
+ if not sys.flags.ignore_environment:
16014
+ # Issue #16248: Honor the -E flag to avoid code injection.
16015
+ self.readprofile(baseName, className)
16017
if not self._tkloaded:
15257
16019
diff -r 70274d53c1dd Lib/lib-tk/tkSimpleDialog.py
15258
16020
--- a/Lib/lib-tk/tkSimpleDialog.py
15259
16021
+++ b/Lib/lib-tk/tkSimpleDialog.py
15281
16043
diff -r 70274d53c1dd Lib/lib2to3/fixer_util.py
15282
16044
--- a/Lib/lib2to3/fixer_util.py
15283
16045
+++ b/Lib/lib2to3/fixer_util.py
16046
@@ -165,7 +165,7 @@
16049
consuming_calls = set(["sorted", "list", "set", "any", "all", "tuple", "sum",
16051
+ "min", "max", "enumerate"])
16053
def attr_chain(obj, attr):
16054
"""Follow an attribute chain.
16055
@@ -192,14 +192,14 @@
16058
( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
16059
- 'any' | 'all' | (any* trailer< '.' 'join' >) )
16060
+ 'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) )
16061
trailer< '(' node=any ')' >
16068
+ ( 'sorted' | 'enumerate' )
16069
trailer< '(' arglist<node=any any*> ')' >
16072
@@ -207,14 +207,14 @@
16074
def in_special_context(node):
16075
""" Returns true if node is in an environment where all that is required
16076
- of it is being itterable (ie, it doesn't matter if it returns a list
16077
- or an itterator).
16078
+ of it is being iterable (ie, it doesn't matter if it returns a list
16080
See test_map_nochange in test_fixers.py for some examples and tests.
16082
global p0, p1, p2, pats_built
16084
+ p0 = patcomp.compile_pattern(p0)
16085
p1 = patcomp.compile_pattern(p1)
16086
- p0 = patcomp.compile_pattern(p0)
16087
p2 = patcomp.compile_pattern(p2)
16089
patterns = [p0, p1, p2]
15284
16090
@@ -274,9 +274,9 @@
15285
16091
"""Find the top level namespace."""
15286
16092
# Scamper up to the top level namespace
15329
16135
# this node has been cut off from a
15330
16136
# previous transformation ; skip
16138
diff -r 70274d53c1dd Lib/lib2to3/tests/test_fixers.py
16139
--- a/Lib/lib2to3/tests/test_fixers.py
16140
+++ b/Lib/lib2to3/tests/test_fixers.py
16141
@@ -2981,6 +2981,10 @@
16143
a = """sorted(filter(f, 'abc'), key=blah)[0]"""
16145
+ a = """enumerate(filter(f, 'abc'))"""
16146
+ self.unchanged(a)
16147
+ a = """enumerate(filter(f, 'abc'), start=1)"""
16148
+ self.unchanged(a)
16149
a = """for i in filter(f, 'abc'): pass"""
16151
a = """[x for x in filter(f, 'abc')]"""
16152
@@ -3089,6 +3093,10 @@
16154
a = """sorted(map(f, 'abc'), key=blah)[0]"""
16156
+ a = """enumerate(map(f, 'abc'))"""
16157
+ self.unchanged(a)
16158
+ a = """enumerate(map(f, 'abc'), start=1)"""
16159
+ self.unchanged(a)
16160
a = """for i in map(f, 'abc'): pass"""
16162
a = """[x for x in map(f, 'abc')]"""
16163
@@ -3152,6 +3160,10 @@
16165
a = """sorted(zip(a, b), key=blah)[0]"""
16167
+ a = """enumerate(zip(a, b))"""
16168
+ self.unchanged(a)
16169
+ a = """enumerate(zip(a, b), start=1)"""
16170
+ self.unchanged(a)
16171
a = """for i in zip(a, b): pass"""
16173
a = """[x for x in zip(a, b)]"""
15332
16174
diff -r 70274d53c1dd Lib/locale.py
15333
16175
--- a/Lib/locale.py
15334
16176
+++ b/Lib/locale.py
16620
17462
diff -r 70274d53c1dd Lib/tarfile.py
16621
17463
--- a/Lib/tarfile.py
16622
17464
+++ b/Lib/tarfile.py
17465
@@ -1987,9 +1987,8 @@
17467
# Append the tar header and data to the archive.
17468
if tarinfo.isreg():
17469
- f = bltn_open(name, "rb")
17470
- self.addfile(tarinfo, f)
17472
+ with bltn_open(name, "rb") as f:
17473
+ self.addfile(tarinfo, f)
17475
elif tarinfo.isdir():
17476
self.addfile(tarinfo)
17477
@@ -2197,10 +2196,11 @@
17478
"""Make a file called targetpath.
17480
source = self.extractfile(tarinfo)
17481
- target = bltn_open(targetpath, "wb")
17482
- copyfileobj(source, target)
17486
+ with bltn_open(targetpath, "wb") as target:
17487
+ copyfileobj(source, target)
17491
def makeunknown(self, tarinfo, targetpath):
17492
"""Make a file from a TarInfo object with an unknown type
16623
17493
@@ -2397,7 +2397,7 @@
16625
17495
if tarinfo.issym():
21194
22064
@unittest.skipUnless(hasattr(posix, 'chown'), "test needs os.chown()")
21195
22065
def test_chown(self):
21196
22066
# raise an OSError if the file does not exist
21197
@@ -395,8 +405,16 @@
22067
@@ -324,7 +334,16 @@
22068
def _test_chflags_regular_file(self, chflags_func, target_file):
22069
st = os.stat(target_file)
22070
self.assertTrue(hasattr(st, 'st_flags'))
22071
- chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE)
22073
+ # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE.
22075
+ chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE)
22076
+ except OSError as err:
22077
+ if err.errno != errno.EOPNOTSUPP:
22079
+ msg = 'chflag UF_IMMUTABLE not supported by underlying fs'
22080
+ self.skipTest(msg)
22083
new_st = os.stat(target_file)
22084
self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags)
22085
@@ -353,8 +372,16 @@
22086
self.teardown_files.append(_DUMMY_SYMLINK)
22087
dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
22089
- posix.lchflags(_DUMMY_SYMLINK,
22090
- dummy_symlink_st.st_flags | stat.UF_IMMUTABLE)
22091
+ # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE.
22093
+ posix.lchflags(_DUMMY_SYMLINK,
22094
+ dummy_symlink_st.st_flags | stat.UF_IMMUTABLE)
22095
+ except OSError as err:
22096
+ if err.errno != errno.EOPNOTSUPP:
22098
+ msg = 'chflag UF_IMMUTABLE not supported by underlying fs'
22099
+ self.skipTest(msg)
22102
new_testfn_st = os.stat(test_support.TESTFN)
22103
new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
22104
@@ -395,8 +422,16 @@
21198
22105
_create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1)
21199
22106
except OSError as e:
21200
22107
expected_errno = errno.ENAMETOOLONG
21227
22134
diff -r 70274d53c1dd Lib/test/test_posixpath.py
21228
22135
--- a/Lib/test/test_posixpath.py
21229
22136
+++ b/Lib/test/test_posixpath.py
21230
@@ -201,6 +201,7 @@
22137
@@ -110,8 +110,10 @@
22141
- # If we don't have links, assume that os.stat doesn't return resonable
22142
- # inode information and thus, that samefile() doesn't work
22144
+ # If we don't have links, assume that os.stat doesn't return
22145
+ # reasonable inode information and thus, that samefile() doesn't
22147
if hasattr(os, "symlink"):
22149
test_support.TESTFN + "1",
22150
@@ -151,19 +153,19 @@
22154
- # If we don't have links, assume that os.stat() doesn't return resonable
22155
- # inode information and thus, that samefile() doesn't work
22156
+ # If we don't have links, assume that os.stat() doesn't return
22157
+ # reasonable inode information and thus, that samestat() doesn't
22159
if hasattr(os, "symlink"):
22160
- if hasattr(os, "symlink"):
22161
- os.symlink(test_support.TESTFN + "1", test_support.TESTFN + "2")
22163
- posixpath.samestat(
22164
- os.stat(test_support.TESTFN + "1"),
22165
- os.stat(test_support.TESTFN + "2")
22169
- os.remove(test_support.TESTFN + "2")
22170
+ os.symlink(test_support.TESTFN + "1", test_support.TESTFN + "2")
22172
+ posixpath.samestat(
22173
+ os.stat(test_support.TESTFN + "1"),
22174
+ os.stat(test_support.TESTFN + "2")
22178
+ os.remove(test_support.TESTFN + "2")
22179
f = open(test_support.TESTFN + "2", "wb")
22182
@@ -201,6 +203,7 @@
21231
22183
with test_support.EnvironmentVarGuard() as env:
21232
22184
env['HOME'] = '/'
21233
22185
self.assertEqual(posixpath.expanduser("~"), "/")
21393
22345
diff -r 70274d53c1dd Lib/test/test_re.py
21394
22346
--- a/Lib/test/test_re.py
21395
22347
+++ b/Lib/test/test_re.py
21396
@@ -174,11 +174,31 @@
22349
from test.test_support import verbose, run_unittest, import_module
22350
+from test.test_support import precisionbigmemtest, _2G
22352
from re import Scanner
22356
from weakref import proxy
22359
# Misc tests from Tim Peters' re.doc
22361
# WARNING: Don't change details in these tests if you don't know
22362
@@ -174,11 +176,31 @@
21397
22363
self.assertEqual(re.sub('x*', '-', 'abxd'), '-a-b-d-')
21398
22364
self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d')
21425
22391
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<1a1>', 'xx')
21426
22392
self.assertRaises(IndexError, re.sub, '(?P<a>x)', '\g<ab>', 'xx')
21427
22393
self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')
21428
@@ -373,12 +393,44 @@
22394
@@ -373,12 +395,44 @@
21429
22395
self.assertEqual(re.search(r"\d\D\w\W\s\S",
21430
22396
"1aa! a", re.UNICODE).group(0), "1aa! a")
21484
22450
+ # Test behaviour when not given a string or pattern as parameter
21485
22451
+ self.assertRaises(TypeError, re.compile, 0)
22453
+ @precisionbigmemtest(size=_2G, memuse=1)
22454
+ def test_large_search(self, size):
22455
+ # Issue #10182: indices were 32-bit-truncated.
22457
+ m = re.search('$', s)
22458
+ self.assertIsNotNone(m)
22459
+ self.assertEqual(m.start(), size)
22460
+ self.assertEqual(m.end(), size)
22462
+ # The huge memuse is because of re.sub() using a list and a join()
22463
+ # to create the replacement result.
22464
+ @precisionbigmemtest(size=_2G, memuse=16 + 2)
22465
+ def test_large_subn(self, size):
22466
+ # Issue #10182: indices were 32-bit-truncated.
22468
+ r, n = re.subn('', '', s)
22469
+ self.assertEqual(r, s)
22470
+ self.assertEqual(n, size + 1)
21487
22473
def run_re_tests():
21488
22474
from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
23275
24261
+ self.assertEqual(hash(a), hash(42))
23276
24262
+ self.assertRaises(TypeError, hash, b)
24264
+ def test_trashcan_16602(self):
24265
+ # Issue #16602: when a weakref's target was part of a long
24266
+ # deallocation chain, the trashcan mechanism could delay clearing
24267
+ # of the weakref and make the target object visible from outside
24268
+ # code even though its refcount had dropped to 0. A crash ensued.
24270
+ def __init__(self, parent):
24273
+ wself = weakref.ref(self)
24276
+ self.wparent = weakref.ref(parent, cb)
24278
+ d = weakref.WeakKeyDictionary()
24279
+ root = c = C(None)
24280
+ for n in range(100):
23279
24286
class SubclassableWeakrefTestCase(TestBase):
23281
@@ -809,17 +878,66 @@
24288
@@ -809,17 +899,66 @@
23282
24289
self.assertEqual(self.cbcalled, 0)
25195
26202
AST_C= $(AST_C_DIR)/Python-ast.c
25196
26203
AST_ASDL= $(srcdir)/Parser/Python.asdl
25198
@@ -406,11 +410,15 @@
26205
@@ -406,11 +410,16 @@
25201
26208
# Build the shared modules
25202
+# MAKEFLAGS are sorted and normalized. Under GNU make the 's' for
26209
+# Under GNU make, MAKEFLAGS are sorted and normalized; the 's' for
25203
26210
+# -s, --silent or --quiet is always the first char.
26211
+# Under BSD make, MAKEFLAGS might be " -s -v x=y".
25204
26212
sharedmods: $(BUILDPYTHON)
25205
26213
- @case $$MAKEFLAGS in \
25206
26214
- *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
25207
26215
- *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
25209
26217
+ @case "$$MAKEFLAGS" in \
25210
+ s*) quiet="-q";; \
26218
+ *\ -s*|s*) quiet="-q";; \
25211
26219
+ *) quiet="";; \
25213
26221
+ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
27279
+- Issue #16248: Disable code execution from the user's home directory by
27280
+ tkinter when the -E flag is passed to Python. Patch by Zachary Ware.
27282
+- Issue #16628: Fix a memory leak in ctypes.resize().
27284
+- Issue #13614: Fix setup.py register failure with invalid rst in description.
27285
+ Patch by Julien Courteau and Pierre Paul Lefebvre.
27287
+- Issue #10182: The re module doesn't truncate indices to 32 bits anymore.
27288
+ Patch by Serhiy Storchaka.
27290
+- Issue #16573: In 2to3, treat enumerate() like a consuming call, so superfluous
27291
+ list() calls aren't added to filter(), map(), and zip() which are directly
27292
+ passed enumerate().
27294
+- Issue #16476: Fix json.tool to avoid including trailing whitespace.
26243
27296
+- Issue #1160: Fix compiling large regular expressions on UCS2 builds.
26244
27297
+ Patch by Serhiy Storchaka.
26956
28018
++self->line_num;
28019
diff -r 70274d53c1dd Modules/_ctypes/_ctypes.c
28020
--- a/Modules/_ctypes/_ctypes.c
28021
+++ b/Modules/_ctypes/_ctypes.c
28022
@@ -2530,7 +2530,7 @@
28023
assert(dict); /* Cannot be NULL for CDataObject instances */
28024
Py_CLEAR(self->b_objects);
28025
if ((self->b_needsfree)
28026
- && ((size_t)dict->size > sizeof(self->b_value)))
28027
+ && _CDataObject_HasExternalBuffer(self))
28028
PyMem_Free(self->b_ptr);
28029
self->b_ptr = NULL;
28030
Py_CLEAR(self->b_base);
28031
diff -r 70274d53c1dd Modules/_ctypes/callproc.c
28032
--- a/Modules/_ctypes/callproc.c
28033
+++ b/Modules/_ctypes/callproc.c
28034
@@ -1740,7 +1740,7 @@
28035
obj->b_size = size;
28038
- if (obj->b_size <= sizeof(obj->b_value)) {
28039
+ if (!_CDataObject_HasExternalBuffer(obj)) {
28040
/* We are currently using the objects default buffer, but it
28041
isn't large enough any more. */
28042
void *ptr = PyMem_Malloc(size);
26957
28043
diff -r 70274d53c1dd Modules/_ctypes/cfield.c
26958
28044
--- a/Modules/_ctypes/cfield.c
26959
28045
+++ b/Modules/_ctypes/cfield.c
27219
28305
#ifdef WORDS_BIGENDIAN
27220
28306
if (_PyFloat_Pack4(x, (unsigned char *)ptr, 1))
28308
diff -r 70274d53c1dd Modules/_ctypes/ctypes.h
28309
--- a/Modules/_ctypes/ctypes.h
28310
+++ b/Modules/_ctypes/ctypes.h
28311
@@ -153,6 +153,7 @@
28312
extern PyTypeObject PyCData_Type;
28313
#define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type)
28314
#define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type)
28315
+#define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value)
28317
extern PyTypeObject PyCSimpleType_Type;
28318
#define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_Type)
27222
28319
diff -r 70274d53c1dd Modules/_ctypes/libffi_osx/x86/darwin64.S
27223
28320
--- a/Modules/_ctypes/libffi_osx/x86/darwin64.S
27224
28321
+++ b/Modules/_ctypes/libffi_osx/x86/darwin64.S
28211
29308
diff -r 70274d53c1dd Modules/_sre.c
28212
29309
--- a/Modules/_sre.c
28213
29310
+++ b/Modules/_sre.c
29311
@@ -1636,7 +1636,7 @@
29313
sre_codesize(PyObject* self, PyObject *unused)
29315
- return Py_BuildValue("l", sizeof(SRE_CODE));
29316
+ return PyLong_FromSize_t(sizeof(SRE_CODE));
29320
@@ -2448,7 +2448,7 @@
29324
- return Py_BuildValue("Ni", item, n);
29325
+ return Py_BuildValue("Nn", item, n);
28214
29329
@@ -2675,6 +2675,13 @@
28215
29330
PyObject *o = PyList_GET_ITEM(code, i);
28216
29331
unsigned long value = PyInt_Check(o) ? (unsigned long)PyInt_AsLong(o)
28247
29362
if (!_validate_inner(code, code+skip-3, groups))
28249
29364
code += skip-3;
29365
@@ -3386,7 +3389,7 @@
29368
/* mark is -1 if group is undefined */
29369
- return Py_BuildValue("i", self->mark[index*2]);
29370
+ return PyLong_FromSsize_t(self->mark[index*2]);
29374
@@ -3409,7 +3412,7 @@
29377
/* mark is -1 if group is undefined */
29378
- return Py_BuildValue("i", self->mark[index*2+1]);
29379
+ return PyLong_FromSsize_t(self->mark[index*2+1]);
29383
@@ -3559,7 +3562,7 @@
29384
match_lastindex_get(MatchObject *self)
29386
if (self->lastindex >= 0)
29387
- return Py_BuildValue("i", self->lastindex);
29388
+ return PyLong_FromSsize_t(self->lastindex);
29389
Py_INCREF(Py_None);
28250
29392
diff -r 70274d53c1dd Modules/_ssl.c
28251
29393
--- a/Modules/_ssl.c
28252
29394
+++ b/Modules/_ssl.c
31339
32481
diff -r 70274d53c1dd Objects/weakrefobject.c
31340
32482
--- a/Objects/weakrefobject.c
31341
32483
+++ b/Objects/weakrefobject.c
31342
@@ -187,15 +187,19 @@
32486
PyObject *callback = self->wr_callback;
32488
- if (PyWeakref_GET_OBJECT(self) != Py_None) {
32489
- PyWeakReference **list = GET_WEAKREFS_LISTPTR(
32490
- PyWeakref_GET_OBJECT(self));
32491
+ if (self->wr_object != Py_None) {
32492
+ PyWeakReference **list = GET_WEAKREFS_LISTPTR(self->wr_object);
32495
/* If 'self' is the end of the list (and thus self->wr_next == NULL)
32496
@@ -187,15 +186,19 @@
31343
32497
static PyObject *
31344
32498
weakref_richcompare(PyWeakReference* self, PyWeakReference* other, int op)
33130
34284
#undef _POSIX_THREADS
34287
diff -r 70274d53c1dd Python/thread_pthread.h
34288
--- a/Python/thread_pthread.h
34289
+++ b/Python/thread_pthread.h
34290
@@ -284,6 +284,7 @@
34291
sem_t *thelock = (sem_t *)lock;
34292
int status, error = 0;
34294
+ (void) error; /* silence unused-but-set-variable warning */
34295
dprintf(("PyThread_free_lock(%p) called\n", lock));
34298
@@ -314,6 +315,7 @@
34299
sem_t *thelock = (sem_t *)lock;
34300
int status, error = 0;
34302
+ (void) error; /* silence unused-but-set-variable warning */
34303
dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
34306
@@ -341,6 +343,7 @@
34307
sem_t *thelock = (sem_t *)lock;
34308
int status, error = 0;
34310
+ (void) error; /* silence unused-but-set-variable warning */
34311
dprintf(("PyThread_release_lock(%p) called\n", lock));
34313
status = sem_post(thelock);
33133
34314
diff -r 70274d53c1dd README
34781
35969
+AC_DEFINE_UNQUOTED([RETSIGTYPE],[void],[assume C89 semantics that RETSIGTYPE is always void])
34782
35970
+AC_TYPE_SIZE_T
34783
35971
+AC_TYPE_UID_T
35973
+# There are two separate checks for each of the exact-width integer types we
35974
+# need. First we check whether the type is available using the usual
35975
+# AC_CHECK_TYPE macro with the default includes (which includes <inttypes.h>
35976
+# and <stdint.h> where available). We then also use the special type checks of
35977
+# the form AC_TYPE_UINT32_T, which in the case that uint32_t is not available
35978
+# directly, #define's uint32_t to be a suitable type.
35980
+AC_CHECK_TYPE(uint32_t,
35981
+ AC_DEFINE(HAVE_UINT32_T, 1, [Define if your compiler provides uint32_t.]),,)
34784
35982
+AC_TYPE_UINT32_T
35984
+AC_CHECK_TYPE(uint64_t,
35985
+ AC_DEFINE(HAVE_UINT64_T, 1, [Define if your compiler provides uint64_t.]),,)
34785
35986
+AC_TYPE_UINT64_T
35988
+AC_CHECK_TYPE(int32_t,
35989
+ AC_DEFINE(HAVE_INT32_T, 1, [Define if your compiler provides int32_t.]),,)
34786
35990
+AC_TYPE_INT32_T
35992
+AC_CHECK_TYPE(int64_t,
35993
+ AC_DEFINE(HAVE_INT64_T, 1, [Define if your compiler provides int64_t.]),,)
34787
35994
+AC_TYPE_INT64_T
34788
35996
+AC_CHECK_TYPE(ssize_t,
34789
35997
+ AC_DEFINE(HAVE_SSIZE_T, 1, [Define if your compiler provides ssize_t]),,)
42024
43232
#ifndef Py_PYCONFIG_H
43233
@@ -370,6 +370,12 @@
43234
/* Define to 1 if you have the `initgroups' function. */
43235
#undef HAVE_INITGROUPS
43237
+/* Define if your compiler provides int32_t. */
43238
+#undef HAVE_INT32_T
43240
+/* Define if your compiler provides int64_t. */
43241
+#undef HAVE_INT64_T
43243
/* Define to 1 if you have the <inttypes.h> header file. */
43244
#undef HAVE_INTTYPES_H
43246
@@ -847,6 +853,12 @@
43247
/* Define this if you have tcl and TCL_UTF_MAX==6 */
43248
#undef HAVE_UCS4_TCL
43250
+/* Define if your compiler provides uint32_t. */
43251
+#undef HAVE_UINT32_T
43253
+/* Define if your compiler provides uint64_t. */
43254
+#undef HAVE_UINT64_T
43256
/* Define to 1 if the system has the type `uintptr_t'. */
43257
#undef HAVE_UINTPTR_T
42025
43259
diff -r 70274d53c1dd setup.py
42026
43260
--- a/setup.py
42027
43261
+++ b/setup.py