Skip to content

Commit 17279ae

Browse files
Merge branch 'master' into pymodule-add
2 parents 76b6063 + 7a27c7e commit 17279ae

Some content is hidden

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

70 files changed

+6576
-5589
lines changed

Doc/c-api/type.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,5 @@ The following functions and structs are used to create
265265
266266
The desired value of the slot. In most cases, this is a pointer
267267
to a function.
268+
269+
Slots other than ``Py_tp_doc`` may not be ``NULL``.

Doc/library/asyncio-policy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ implementation used by the asyncio event loop:
209209
It works reliably even when the asyncio event loop is run in a non-main OS thread.
210210

211211
There is no noticeable overhead when handling a big number of children (*O(1)* each
212-
time a child terminates), but stating a thread per process requires extra memory.
212+
time a child terminates), but starting a thread per process requires extra memory.
213213

214214
This watcher is used by default.
215215

Doc/library/http.client.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ The module provides the following classes:
9999
:attr:`ssl.SSLContext.post_handshake_auth` for the default *context* or
100100
when *cert_file* is passed with a custom *context*.
101101

102+
.. versionchanged:: 3.10
103+
This class now sends an ALPN extension with protocol indicator
104+
``http/1.1`` when no *context* is given. Custom *context* should set
105+
ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocol`.
106+
102107
.. deprecated:: 3.6
103108

104109
*key_file* and *cert_file* are deprecated in favor of *context*.

Doc/library/os.rst

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,6 +3276,102 @@ features:
32763276
.. versionadded:: 3.8
32773277

32783278

3279+
.. function:: eventfd(initval[, flags=os.EFD_CLOEXEC])
3280+
3281+
Create and return an event file descriptor. The file descriptors supports
3282+
raw :func:`read` and :func:`write` with a buffer size of 8,
3283+
:func:`~select.select`, :func:`~select.poll` and similar. See man page
3284+
:manpage:`eventfd(2)` for more information. By default, the
3285+
new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
3286+
3287+
*initval* is the initial value of the event counter. The initial value
3288+
must be an 32 bit unsigned integer. Please note that the initial value is
3289+
limited to a 32 bit unsigned int although the event counter is an unsigned
3290+
64 bit integer with a maximum value of 2\ :sup:`64`\ -\ 2.
3291+
3292+
*flags* can be constructed from :const:`EFD_CLOEXEC`,
3293+
:const:`EFD_NONBLOCK`, and :const:`EFD_SEMAPHORE`.
3294+
3295+
If :const:`EFD_SEMAPHORE` is specified and the event counter is non-zero,
3296+
:func:`eventfd_read` returns 1 and decrements the counter by one.
3297+
3298+
If :const:`EFD_SEMAPHORE` is not specified and the event counter is
3299+
non-zero, :func:`eventfd_read` returns the current event counter value and
3300+
resets the counter to zero.
3301+
3302+
If the event counter is zero and :const:`EFD_NONBLOCK` is not
3303+
specified, :func:`eventfd_read` blocks.
3304+
3305+
:func:`eventfd_write` increments the event counter. Write blocks if the
3306+
write operation would increment the counter to a value larger than
3307+
2\ :sup:`64`\ -\ 2.
3308+
3309+
Example::
3310+
3311+
import os
3312+
3313+
# semaphore with start value '1'
3314+
fd = os.eventfd(1, os.EFD_SEMAPHORE | os.EFC_CLOEXEC)
3315+
try:
3316+
# acquire semaphore
3317+
v = os.eventfd_read(fd)
3318+
try:
3319+
do_work()
3320+
finally:
3321+
# release semaphore
3322+
os.eventfd_write(fd, v)
3323+
finally:
3324+
os.close(fd)
3325+
3326+
.. availability:: Linux 2.6.27 or newer with glibc 2.8 or newer.
3327+
3328+
.. versionadded:: 3.10
3329+
3330+
.. function:: eventfd_read(fd)
3331+
3332+
Read value from an :func:`eventfd` file descriptor and return a 64 bit
3333+
unsigned int. The function does not verify that *fd* is an :func:`eventfd`.
3334+
3335+
.. availability:: See :func:`eventfd`
3336+
3337+
.. versionadded:: 3.10
3338+
3339+
.. function:: eventfd_write(fd, value)
3340+
3341+
Add value to an :func:`eventfd` file descriptor. *value* must be a 64 bit
3342+
unsigned int. The function does not verify that *fd* is an :func:`eventfd`.
3343+
3344+
.. availability:: See :func:`eventfd`
3345+
3346+
.. versionadded:: 3.10
3347+
3348+
.. data:: EFD_CLOEXEC
3349+
3350+
Set close-on-exec flag for new :func:`eventfd` file descriptor.
3351+
3352+
.. availability:: See :func:`eventfd`
3353+
3354+
.. versionadded:: 3.10
3355+
3356+
.. data:: EFD_NONBLOCK
3357+
3358+
Set :const:`O_NONBLOCK` status flag for new :func:`eventfd` file
3359+
descriptor.
3360+
3361+
.. availability:: See :func:`eventfd`
3362+
3363+
.. versionadded:: 3.10
3364+
3365+
.. data:: EFD_SEMAPHORE
3366+
3367+
Provide semaphore-like semantics for reads from a :func:`eventfd` file
3368+
descriptor. On read the internal counter is decremented by one.
3369+
3370+
.. availability:: Linux 2.6.30 or newer with glibc 2.8 or newer.
3371+
3372+
.. versionadded:: 3.10
3373+
3374+
32793375
Linux extended attributes
32803376
~~~~~~~~~~~~~~~~~~~~~~~~~
32813377

Doc/library/threading.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ This module defines the following functions:
7171

7272
.. versionadded:: 3.8
7373

74+
.. data:: __excepthook__
75+
76+
Holds the original value of :func:`threading.excepthook`. It is saved so that the
77+
original value can be restored in case they happen to get replaced with
78+
broken or alternative objects.
79+
80+
.. versionadded:: 3.10
7481

7582
.. function:: get_ident()
7683

Doc/library/types.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ Additional Utility Classes and Functions
409409
return "{}({})".format(type(self).__name__, ", ".join(items))
410410

411411
def __eq__(self, other):
412-
return self.__dict__ == other.__dict__
412+
if isinstance(self, SimpleNamespace) and isinstance(other, SimpleNamespace):
413+
return self.__dict__ == other.__dict__
414+
return NotImplemented
413415

414416
``SimpleNamespace`` may be useful as a replacement for ``class NS: pass``.
415417
However, for a structured record type use :func:`~collections.namedtuple`

Doc/library/urllib.request.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ The :mod:`urllib.request` module defines the following functions:
109109
.. versionchanged:: 3.4.3
110110
*context* was added.
111111

112+
.. versionchanged:: 3.10
113+
HTTPS connection now send an ALPN extension with protocol indicator
114+
``http/1.1`` when no *context* is given. Custom *context* should set
115+
ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocol`.
116+
112117
.. deprecated:: 3.6
113118

114119
*cafile*, *capath* and *cadefault* are deprecated in favor of *context*.

Doc/library/zipimport.rst

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ doesn't contain :file:`.pyc` files, importing may be rather slow.
4444
follows the specification in :pep:`273`, but uses an implementation written by Just
4545
van Rossum that uses the import hooks described in :pep:`302`.
4646

47-
:pep:`302` - New Import Hooks
48-
The PEP to add the import hooks that help this module work.
47+
:mod:`importlib` - The implementation of the import machinery
48+
Package providing the relevant protocols for all importers to
49+
implement.
4950

5051

5152
This module defines an exception:
@@ -73,14 +74,49 @@ zipimporter Objects
7374
:exc:`ZipImportError` is raised if *archivepath* doesn't point to a valid ZIP
7475
archive.
7576

76-
.. method:: find_module(fullname[, path])
77+
.. method:: create_module(spec)
78+
79+
Implementation of :meth:`importlib.abc.Loader.create_module` that returns
80+
:const:`None` to explicitly request the default semantics.
81+
82+
.. versionadded:: 3.10
83+
84+
85+
.. method:: exec_module(module)
86+
87+
Implementation of :meth:`importlib.abc.Loader.exec_module`.
88+
89+
.. versionadded:: 3.10
90+
91+
92+
.. method:: find_loader(fullname, path=None)
93+
94+
An implementation of :meth:`importlib.abc.PathEntryFinder.find_loader`.
95+
96+
.. deprecated:: 3.10
97+
98+
Use :meth:`find_spec` instead.
99+
100+
101+
.. method:: find_module(fullname, path=None)
77102

78103
Search for a module specified by *fullname*. *fullname* must be the fully
79104
qualified (dotted) module name. It returns the zipimporter instance itself
80105
if the module was found, or :const:`None` if it wasn't. The optional
81106
*path* argument is ignored---it's there for compatibility with the
82107
importer protocol.
83108

109+
.. deprecated:: 3.10
110+
111+
Use :meth:`find_spec` instead.
112+
113+
114+
.. method:: find_spec(fullname, target=None)
115+
116+
An implementation of :meth:`importlib.abc.PathEntryFinder.find_spec`.
117+
118+
.. versionadded:: 3.10
119+
84120

85121
.. method:: get_code(fullname)
86122

@@ -126,6 +162,10 @@ zipimporter Objects
126162
qualified (dotted) module name. It returns the imported module, or raises
127163
:exc:`ZipImportError` if it wasn't found.
128164

165+
.. deprecated:: 3.10
166+
167+
Use :meth:`exec_module` instead.
168+
129169

130170
.. attribute:: archive
131171

Doc/tools/extensions/c_annotations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ def add_annotations(self, app, doctree):
7979
classes=['stableabi']))
8080
if par['objtype'] != 'function':
8181
continue
82-
if not par[0].has_key('names') or not par[0]['names']:
82+
if not par[0].has_key('ids') or not par[0]['ids']:
8383
continue
84-
name = par[0]['names'][0]
84+
name = par[0]['ids'][0]
8585
if name.startswith("c."):
8686
name = name[2:]
8787
entry = self.get(name)

Doc/whatsnew/3.10.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ os
229229
Added :func:`os.cpu_count()` support for VxWorks RTOS.
230230
(Contributed by Peixing Xin in :issue:`41440`.)
231231

232+
Added a new function :func:`os.eventfd` and related helpers to wrap the
233+
``eventfd2`` syscall on Linux.
234+
(Contributed by Christian Heimes in :issue:`41001`.)
235+
232236
py_compile
233237
----------
234238

@@ -263,6 +267,11 @@ retrieve the functions set by :func:`threading.settrace` and
263267
:func:`threading.setprofile` respectively.
264268
(Contributed by Mario Corchero in :issue:`42251`.)
265269

270+
Add :data:`threading.__excepthook__` to allow retrieving the original value
271+
of :func:`threading.excepthook` in case it is set to a broken or a different
272+
value.
273+
(Contributed by Mario Corchero in :issue:`42308`.)
274+
266275
traceback
267276
---------
268277

@@ -294,6 +303,13 @@ Add a :class:`~xml.sax.handler.LexicalHandler` class to the
294303
:mod:`xml.sax.handler` module.
295304
(Contributed by Jonathan Gossage and Zackery Spytz in :issue:`35018`.)
296305

306+
zipimport
307+
---------
308+
Add methods related to :pep:`451`: :meth:`~zipimport.zipimporter.find_spec`,
309+
:meth:`zipimport.zipimporter.create_module`, and
310+
:meth:`zipimport.zipimporter.exec_module`.
311+
(Contributed by Brett Cannon in :issue:`42131`.
312+
297313

298314
Optimizations
299315
=============

Include/cpython/code.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct PyCodeObject {
3838
Py_ssize_t *co_cell2arg; /* Maps cell vars which are arguments. */
3939
PyObject *co_filename; /* unicode (where it was loaded from) */
4040
PyObject *co_name; /* unicode (name, for reference) */
41-
PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See
41+
PyObject *co_linetable; /* string (encoding addr<->lineno mapping) See
4242
Objects/lnotab_notes.txt for details. */
4343
void *co_zombieframe; /* for optimization only (see frameobject.c) */
4444
PyObject *co_weakreflist; /* to support weakrefs to code objects */
@@ -135,16 +135,18 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno);
135135
PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
136136

137137
/* for internal use only */
138-
typedef struct _addr_pair {
139-
int ap_lower;
140-
int ap_upper;
141-
} PyAddrPair;
138+
typedef struct _line_offsets {
139+
int ar_start;
140+
int ar_end;
141+
int ar_line;
142+
int ar_computed_line;
143+
char *lo_next;
144+
} PyCodeAddressRange;
142145

143146
/* Update *bounds to describe the first and one-past-the-last instructions in the
144147
same line as lasti. Return the number of that line.
145148
*/
146-
PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co,
147-
int lasti, PyAddrPair *bounds);
149+
PyAPI_FUNC(int) _PyCode_CheckLineNumber(int lasti, PyCodeAddressRange *bounds);
148150

149151
/* Create a comparable key used to compare constants taking in account the
150152
* object type. It is used to make sure types are not coerced (e.g., float and
@@ -163,3 +165,15 @@ PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index,
163165
void **extra);
164166
PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
165167
void *extra);
168+
169+
/** API for initializing the line number table. */
170+
int _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
171+
172+
/** Out of process API for initializing the line number table. */
173+
void PyLineTable_InitAddressRange(char *linetable, int firstlineno, PyCodeAddressRange *range);
174+
175+
/** API for traversing the line number table. */
176+
int PyLineTable_NextAddressRange(PyCodeAddressRange *range);
177+
int PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
178+
179+

Include/internal/pycore_bitutils.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ extern "C" {
1717
# error "this header requires Py_BUILD_CORE define"
1818
#endif
1919

20-
#if ((defined(__GNUC__) \
21-
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) \
22-
|| (defined(__clang__) \
23-
&& (__clang_major__ >= 4 \
24-
|| (__clang_major__ == 3 && __clang_minor__ >= 2))))
25-
/* __builtin_bswap16() is available since GCC 4.8 and clang 3.2,
20+
#if defined(__GNUC__) \
21+
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))
22+
/* __builtin_bswap16() is available since GCC 4.8,
2623
__builtin_bswap32() is available since GCC 4.3,
2724
__builtin_bswap64() is available since GCC 4.3. */
2825
# define _PY_HAVE_BUILTIN_BSWAP
@@ -36,7 +33,7 @@ extern "C" {
3633
static inline uint16_t
3734
_Py_bswap16(uint16_t word)
3835
{
39-
#ifdef _PY_HAVE_BUILTIN_BSWAP
36+
#if defined(_PY_HAVE_BUILTIN_BSWAP) || _Py__has_builtin(__builtin_bswap16)
4037
return __builtin_bswap16(word);
4138
#elif defined(_MSC_VER)
4239
Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned short));
@@ -51,7 +48,7 @@ _Py_bswap16(uint16_t word)
5148
static inline uint32_t
5249
_Py_bswap32(uint32_t word)
5350
{
54-
#ifdef _PY_HAVE_BUILTIN_BSWAP
51+
#if defined(_PY_HAVE_BUILTIN_BSWAP) || _Py__has_builtin(__builtin_bswap32)
5552
return __builtin_bswap32(word);
5653
#elif defined(_MSC_VER)
5754
Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned long));
@@ -68,7 +65,7 @@ _Py_bswap32(uint32_t word)
6865
static inline uint64_t
6966
_Py_bswap64(uint64_t word)
7067
{
71-
#ifdef _PY_HAVE_BUILTIN_BSWAP
68+
#if defined(_PY_HAVE_BUILTIN_BSWAP) || _Py__has_builtin(__builtin_bswap64)
7269
return __builtin_bswap64(word);
7370
#elif defined(_MSC_VER)
7471
return _byteswap_uint64(word);

0 commit comments

Comments
 (0)