Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 4e01272

Browse files
author
Anselm Kruis
committed
merge branch 3.5
2 parents 6d41bfa + a33e9f7 commit 4e01272

File tree

411 files changed

+7223
-2896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

411 files changed

+7223
-2896
lines changed

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Two-trick pony for OSX and other case insensitive file systems:
22
# Ignore ./python binary on Unix but still look into ./Python/ directory.
33
/python
4-
!/Python/**
4+
!/Python/
55
*.cover
66
*.o
77
*.orig
@@ -69,8 +69,8 @@ config.status
6969
config.status.lineno
7070
core
7171
db_home
72-
config.log
73-
config.status
72+
.hg/
73+
ipch/
7474
libpython*.a
7575
libpython*.so*
7676
platform
@@ -93,3 +93,5 @@ htmlcov/
9393
Tools/msi/obj
9494
Tools/ssl/amd64
9595
Tools/ssl/win32
96+
.vs/
97+
.vscode/

.hgignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ htmlcov/
9494
*.gcda
9595
*.gcno
9696
*.gcov
97+
ipch/
9798
coverage.info
9899
Tools/msi/obj
99100
Tools/ssl/amd64
100101
Tools/ssl/win32
102+
.vs/
103+
.vscode/

Doc/c-api/arg.rst

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ Strings and buffers
3232

3333
These formats allow accessing an object as a contiguous chunk of memory.
3434
You don't have to provide raw storage for the returned unicode or bytes
35-
area. Also, you won't have to release any memory yourself, except with the
36-
``es``, ``es#``, ``et`` and ``et#`` formats.
35+
area.
36+
37+
In general, when a format sets a pointer to a buffer, the buffer is
38+
managed by the corresponding Python object, and the buffer shares
39+
the lifetime of this object. You won't have to release any memory yourself.
40+
The only exceptions are ``es``, ``es#``, ``et`` and ``et#``.
3741

3842
However, when a :c:type:`Py_buffer` structure gets filled, the underlying
3943
buffer is locked so that the caller can subsequently use the buffer even
@@ -44,6 +48,11 @@ in any early abort case).
4448

4549
Unless otherwise stated, buffers are not NUL-terminated.
4650

51+
Some formats require a read-only :term:`bytes-like object`, and set a
52+
pointer instead of a buffer structure. They work by checking that
53+
the object's :c:member:`PyBufferProcs.bf_releasebuffer` field is *NULL*,
54+
which disallows mutable objects such as :class:`bytearray`.
55+
4756
.. note::
4857

4958
For all ``#`` variants of formats (``s#``, ``y#``, etc.), the type of
@@ -59,7 +68,7 @@ Unless otherwise stated, buffers are not NUL-terminated.
5968
Convert a Unicode object to a C pointer to a character string.
6069
A pointer to an existing string is stored in the character pointer
6170
variable whose address you pass. The C string is NUL-terminated.
62-
The Python string must not contain embedded null characters; if it does,
71+
The Python string must not contain embedded null code points; if it does,
6372
a :exc:`ValueError` exception is raised. Unicode objects are converted
6473
to C strings using ``'utf-8'`` encoding. If this conversion fails, a
6574
:exc:`UnicodeError` is raised.
@@ -72,7 +81,7 @@ Unless otherwise stated, buffers are not NUL-terminated.
7281
as *converter*.
7382

7483
.. versionchanged:: 3.5
75-
Previously, :exc:`TypeError` was raised when embedded null characters
84+
Previously, :exc:`TypeError` was raised when embedded null code points
7685
were encountered in the Python string.
7786

7887
``s*`` (:class:`str` or :term:`bytes-like object`) [Py_buffer]
@@ -82,8 +91,8 @@ Unless otherwise stated, buffers are not NUL-terminated.
8291
Unicode objects are converted to C strings using ``'utf-8'`` encoding.
8392

8493
``s#`` (:class:`str`, read-only :term:`bytes-like object`) [const char \*, int or :c:type:`Py_ssize_t`]
85-
Like ``s*``, except that it doesn't accept mutable bytes-like objects
86-
such as :class:`bytearray`. The result is stored into two C variables,
94+
Like ``s*``, except that it doesn't accept mutable objects.
95+
The result is stored into two C variables,
8796
the first one a pointer to a C string, the second one its length.
8897
The string may contain embedded null bytes. Unicode objects are converted
8998
to C strings using ``'utf-8'`` encoding.
@@ -135,21 +144,17 @@ Unless otherwise stated, buffers are not NUL-terminated.
135144
pointer variable, which will be filled with the pointer to an existing
136145
Unicode buffer. Please note that the width of a :c:type:`Py_UNICODE`
137146
character depends on compilation options (it is either 16 or 32 bits).
138-
The Python string must not contain embedded null characters; if it does,
147+
The Python string must not contain embedded null code points; if it does,
139148
a :exc:`ValueError` exception is raised.
140149

141-
.. note::
142-
Since ``u`` doesn't give you back the length of the string, and it
143-
may contain embedded NUL characters, it is recommended to use ``u#``
144-
or ``U`` instead.
145-
146150
.. versionchanged:: 3.5
147-
Previously, :exc:`TypeError` was raised when embedded null characters
151+
Previously, :exc:`TypeError` was raised when embedded null code points
148152
were encountered in the Python string.
149153

150154
``u#`` (:class:`str`) [Py_UNICODE \*, int]
151155
This variant on ``u`` stores into two C variables, the first one a pointer to a
152-
Unicode data buffer, the second one its length.
156+
Unicode data buffer, the second one its length. This variant allows
157+
null code points.
153158

154159
``Z`` (:class:`str` or ``None``) [Py_UNICODE \*]
155160
Like ``u``, but the Python object may also be ``None``, in which case the

Doc/c-api/import.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ Importing Modules
207207
208208
.. c:function:: PyObject* PyImport_GetImporter(PyObject *path)
209209
210-
Return an importer object for a :data:`sys.path`/:attr:`pkg.__path__` item
210+
Return a finder object for a :data:`sys.path`/:attr:`pkg.__path__` item
211211
*path*, possibly by fetching it from the :data:`sys.path_importer_cache`
212212
dict. If it wasn't yet cached, traverse :data:`sys.path_hooks` until a hook
213213
is found that can handle the path item. Return ``None`` if no hook could;
214-
this tells our caller it should fall back to the built-in import mechanism.
215-
Cache the result in :data:`sys.path_importer_cache`. Return a new reference
216-
to the importer object.
214+
this tells our caller that the :term:`path based finder` could not find a
215+
finder for this path item. Cache the result in :data:`sys.path_importer_cache`.
216+
Return a new reference to the finder object.
217217
218218
219219
.. c:function:: void _PyImport_Init()

Doc/c-api/init.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Initializing and finalizing the interpreter
3737
(without calling :c:func:`Py_Finalize` first). There is no return value; it is a
3838
fatal error if the initialization fails.
3939

40+
.. note::
41+
On Windows, changes the console mode from ``O_TEXT`` to ``O_BINARY``, which will
42+
also affect non-Python uses of the console using the C Runtime.
43+
4044

4145
.. c:function:: void Py_InitializeEx(int initsigs)
4246

Doc/c-api/module.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ Module Objects
5959
.. index:: single: __dict__ (module attribute)
6060
6161
Return the dictionary object that implements *module*'s namespace; this object
62-
is the same as the :attr:`~object.__dict__` attribute of the module object. This
63-
function never fails. It is recommended extensions use other
64-
:c:func:`PyModule_\*` and :c:func:`PyObject_\*` functions rather than directly
65-
manipulate a module's :attr:`~object.__dict__`.
62+
is the same as the :attr:`~object.__dict__` attribute of the module object.
63+
If *module* is not a module object (or a subtype of a module object),
64+
:exc:`SystemError` is raised and *NULL* is returned.
65+
66+
It is recommended extensions use other :c:func:`PyModule_\*` and
67+
:c:func:`PyObject_\*` functions rather than directly manipulate a module's
68+
:attr:`~object.__dict__`.
6669
6770
6871
.. c:function:: PyObject* PyModule_GetNameObject(PyObject *module)
@@ -321,7 +324,7 @@ The available slot types are:
321324
:c:type:`PyModule_Type`. Any type can be used, as long as it supports
322325
setting and getting import-related attributes.
323326
However, only ``PyModule_Type`` instances may be returned if the
324-
``PyModuleDef`` has non-*NULL* ``m_methods``, ``m_traverse``, ``m_clear``,
327+
``PyModuleDef`` has non-*NULL* ``m_traverse``, ``m_clear``,
325328
``m_free``; non-zero ``m_size``; or slots other than ``Py_mod_create``.
326329
327330
.. c:var:: Py_mod_exec

Doc/c-api/veryhigh.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,10 @@ the same library that the Python runtime is using.
219219
.. c:function:: PyObject* PyRun_StringFlags(const char *str, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags)
220220
221221
Execute Python source code from *str* in the context specified by the
222-
dictionaries *globals* and *locals* with the compiler flags specified by
223-
*flags*. The parameter *start* specifies the start token that should be used to
224-
parse the source code.
222+
objects *globals* and *locals* with the compiler flags specified by
223+
*flags*. *globals* must be a dictionary; *locals* can be any object
224+
that implements the mapping protocol. The parameter *start* specifies
225+
the start token that should be used to parse the source code.
225226
226227
Returns the result of executing the code as a Python object, or *NULL* if an
227228
exception was raised.
@@ -295,16 +296,16 @@ the same library that the Python runtime is using.
295296
.. c:function:: PyObject* PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals)
296297
297298
This is a simplified interface to :c:func:`PyEval_EvalCodeEx`, with just
298-
the code object, and the dictionaries of global and local variables.
299-
The other arguments are set to *NULL*.
299+
the code object, and global and local variables. The other arguments are
300+
set to *NULL*.
300301
301302
302303
.. c:function:: PyObject* PyEval_EvalCodeEx(PyObject *co, PyObject *globals, PyObject *locals, PyObject **args, int argcount, PyObject **kws, int kwcount, PyObject **defs, int defcount, PyObject *closure)
303304
304305
Evaluate a precompiled code object, given a particular environment for its
305-
evaluation. This environment consists of dictionaries of global and local
306-
variables, arrays of arguments, keywords and defaults, and a closure tuple of
307-
cells.
306+
evaluation. This environment consists of a dictionary of global variables,
307+
a mapping object of local variables, arrays of arguments, keywords and
308+
defaults, and a closure tuple of cells.
308309
309310
310311
.. c:type:: PyFrameObject

Doc/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@
7676

7777
# Custom sidebar templates, filenames relative to this file.
7878
html_sidebars = {
79-
'index': 'indexsidebar.html',
79+
# Defaults taken from http://www.sphinx-doc.org/en/stable/config.html#confval-html_sidebars
80+
# Removes the quick search block
81+
'**': ['localtoc.html', 'relations.html', 'customsourcelink.html'],
82+
'index': ['indexsidebar.html'],
8083
}
8184

8285
# Additional templates that should be rendered to pages.

Doc/distutils/examples.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ Let's take an example with a simple script::
245245

246246
setup(name='foobar')
247247

248-
Running the ``check`` command will display some warnings::
248+
Running the ``check`` command will display some warnings:
249+
250+
.. code-block:: shell-session
249251
250252
$ python setup.py check
251253
running check
@@ -274,7 +276,9 @@ For example, if the :file:`setup.py` script is changed like this::
274276
url='http://example.com', long_description=desc)
275277

276278
Where the long description is broken, ``check`` will be able to detect it
277-
by using the :mod:`docutils` parser::
279+
by using the :mod:`docutils` parser:
280+
281+
.. code-block:: shell-session
278282
279283
$ python setup.py check --restructuredtext
280284
running check
@@ -286,7 +290,9 @@ Reading the metadata
286290

287291
The :func:`distutils.core.setup` function provides a command-line interface
288292
that allows you to query the metadata fields of a project through the
289-
``setup.py`` script of a given project::
293+
``setup.py`` script of a given project:
294+
295+
.. code-block:: shell-session
290296
291297
$ python setup.py --name
292298
distribute

Doc/distutils/packageindex.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ in the root of the package besides :file:`setup.py`.
233233

234234
To prevent registering broken reStructuredText content, you can use the
235235
:program:`rst2html` program that is provided by the :mod:`docutils` package and
236-
check the ``long_description`` from the command line::
236+
check the ``long_description`` from the command line:
237+
238+
.. code-block:: shell-session
237239
238240
$ python setup.py --long-description | rst2html.py > output.html
239241

Doc/distutils/sourcedist.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ described above does not apply in this case.
133133

134134
The manifest template has one command per line, where each command specifies a
135135
set of files to include or exclude from the source distribution. For an
136-
example, again we turn to the Distutils' own manifest template::
136+
example, again we turn to the Distutils' own manifest template:
137+
138+
.. code-block:: none
137139
138140
include *.txt
139141
recursive-include examples *.txt *.py

Doc/extending/building.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ Since distutils also supports creation of binary packages, users don't
5555
necessarily need a compiler and distutils to install the extension.
5656
5757
A distutils package contains a driver script, :file:`setup.py`. This is a plain
58-
Python file, which, in the most simple case, could look like this::
58+
Python file, which, in the most simple case, could look like this:
59+
60+
.. code-block:: python3
5961
6062
from distutils.core import setup, Extension
6163
@@ -96,7 +98,9 @@ file, :file:`demo.c`.
9698

9799
In many cases, building an extension is more complex, since additional
98100
preprocessor defines and libraries may be needed. This is demonstrated in the
99-
example below. ::
101+
example below.
102+
103+
.. code-block:: python3
100104
101105
from distutils.core import setup, Extension
102106
@@ -161,4 +165,3 @@ commands can be used to do so. ::
161165
python setup.py bdist_wininst
162166
python setup.py bdist_rpm
163167
python setup.py bdist_dumb
164-

Doc/extending/embedding.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ script, such as:
155155
c = c + b
156156
return c
157157
158-
then the result should be::
158+
then the result should be:
159+
160+
.. code-block:: shell-session
159161
160162
$ call multiply multiply 3 2
161163
Will compute 3 times 2
@@ -289,16 +291,20 @@ available). This script has several options, of which the following will
289291
be directly useful to you:
290292

291293
* ``pythonX.Y-config --cflags`` will give you the recommended flags when
292-
compiling::
294+
compiling:
295+
296+
.. code-block:: shell-session
293297
294-
$ /opt/bin/python3.4-config --cflags
295-
-I/opt/include/python3.4m -I/opt/include/python3.4m -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
298+
$ /opt/bin/python3.4-config --cflags
299+
-I/opt/include/python3.4m -I/opt/include/python3.4m -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
296300
297301
* ``pythonX.Y-config --ldflags`` will give you the recommended flags when
298-
linking::
302+
linking:
303+
304+
.. code-block:: shell-session
299305
300-
$ /opt/bin/python3.4-config --ldflags
301-
-L/opt/lib/python3.4/config-3.4m -lpthread -ldl -lutil -lm -lpython3.4m -Xlinker -export-dynamic
306+
$ /opt/bin/python3.4-config --ldflags
307+
-L/opt/lib/python3.4/config-3.4m -lpthread -ldl -lutil -lm -lpython3.4m -Xlinker -export-dynamic
302308
303309
.. note::
304310
To avoid confusion between several Python installations (and especially

Doc/extending/extending.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,9 @@ the format string is empty, it returns ``None``; if it contains exactly one
792792
format unit, it returns whatever object is described by that format unit. To
793793
force it to return a tuple of size 0 or one, parenthesize the format string.
794794

795-
Examples (to the left the call, to the right the resulting Python value)::
795+
Examples (to the left the call, to the right the resulting Python value):
796+
797+
.. code-block:: none
796798
797799
Py_BuildValue("") None
798800
Py_BuildValue("i", 123) 123
@@ -1348,4 +1350,3 @@ code distribution).
13481350
13491351
.. [#] These guarantees don't hold when you use the "old" style calling convention ---
13501352
this is still found in much existing code.
1351-

Doc/extending/newtypes.rst

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ The first bit that will be new is::
5252
} noddy_NoddyObject;
5353

5454
This is what a Noddy object will contain---in this case, nothing more than what
55-
every Python object contains---a refcount and a pointer to a type object.
56-
These are the fields the ``PyObject_HEAD`` macro brings in. The reason for the
57-
macro is to standardize the layout and to enable special debugging fields in
58-
debug builds. Note that there is no semicolon after the ``PyObject_HEAD``
59-
macro; one is included in the macro definition. Be wary of adding one by
55+
every Python object contains---a field called ``ob_base`` of type
56+
:c:type:`PyObject`. :c:type:`PyObject` in turn, contains an ``ob_refcnt``
57+
field and a pointer to a type object. These can be accessed using the macros
58+
:c:macro:`Py_REFCNT` and :c:macro:`Py_TYPE` respectively. These are the fields
59+
the :c:macro:`PyObject_HEAD` macro brings in. The reason for the macro is to
60+
standardize the layout and to enable special debugging fields in debug builds.
61+
62+
Note that there is no semicolon after the :c:macro:`PyObject_HEAD` macro;
63+
one is included in the macro definition. Be wary of adding one by
6064
accident; it's easy to do from habit, and your compiler might not complain,
6165
but someone else's probably will! (On Windows, MSVC is known to call this an
6266
error and refuse to compile the code.)
@@ -209,7 +213,9 @@ That's it! All that remains is to build it; put the above code in a file called
209213
setup(name="noddy", version="1.0",
210214
ext_modules=[Extension("noddy", ["noddy.c"])])
211215

212-
in a file called :file:`setup.py`; then typing ::
216+
in a file called :file:`setup.py`; then typing
217+
218+
.. code-block:: shell-session
213219
214220
$ python setup.py build
215221
@@ -1513,4 +1519,3 @@ might be something like the following::
15131519
.. [#] Even in the third version, we aren't guaranteed to avoid cycles. Instances of
15141520
string subclasses are allowed and string subclasses could allow cycles even if
15151521
normal strings don't.
1516-

0 commit comments

Comments
 (0)