Skip to content

Commit 112cee6

Browse files
committed
Merge branch 'main' into load-fast-borrow-absinterp
2 parents c30e1e9 + ef06508 commit 112cee6

File tree

99 files changed

+1766
-743
lines changed

Some content is hidden

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

99 files changed

+1766
-743
lines changed

Doc/library/importlib.metadata.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ While the module level API described above is the most common and convenient usa
422422
you can get all of that information from the :class:`!Distribution` class.
423423
:class:`!Distribution` is an abstract object that represents the metadata for
424424
a Python `Distribution Package <https://packaging.python.org/en/latest/glossary/#term-Distribution-Package>`_.
425-
You can get the concreate :class:`!Distribution` subclass instance for an installed
425+
You can get the concrete :class:`!Distribution` subclass instance for an installed
426426
distribution package by calling the :func:`distribution` function::
427427

428428
>>> from importlib.metadata import distribution # doctest: +SKIP

Doc/library/mailbox.rst

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,27 @@ Supported mailbox formats are Maildir, mbox, MH, Babyl, and MMDF.
587587
remarks:
588588

589589

590-
.. method:: get_file(key)
590+
.. method:: get_bytes(key, from_=False)
591+
592+
Note: This method has an extra parameter (*from_*) compared with other classes.
593+
The first line of an mbox file entry is the Unix "From " line.
594+
If *from_* is False, the first line of the file is dropped.
595+
596+
.. method:: get_file(key, from_=False)
591597

592598
Using the file after calling :meth:`~Mailbox.flush` or
593599
:meth:`~Mailbox.close` on the :class:`!mbox` instance may yield
594600
unpredictable results or raise an exception.
595601

602+
Note: This method has an extra parameter (*from_*) compared with other classes.
603+
The first line of an mbox file entry is the Unix "From " line.
604+
If *from_* is False, the first line of the file is dropped.
605+
606+
.. method:: get_string(key, from_=False)
607+
608+
Note: This method has an extra parameter (*from_*) compared with other classes.
609+
The first line of an mbox file entry is the Unix "From " line.
610+
If *from_* is False, the first line of the file is dropped.
596611

597612
.. method:: lock()
598613
unlock()
@@ -851,12 +866,22 @@ Supported mailbox formats are Maildir, mbox, MH, Babyl, and MMDF.
851866
remarks:
852867

853868

854-
.. method:: get_file(key)
869+
.. method:: get_bytes(key, from_=False)
870+
871+
Note: This method has an extra parameter (*from_*) compared with other classes.
872+
The first line of an mbox file entry is the Unix "From " line.
873+
If *from_* is False, the first line of the file is dropped.
874+
875+
.. method:: get_file(key, from_=False)
855876

856877
Using the file after calling :meth:`~Mailbox.flush` or
857878
:meth:`~Mailbox.close` on the :class:`!MMDF` instance may yield
858879
unpredictable results or raise an exception.
859880

881+
Note: This method has an extra parameter (*from_*) compared with other classes.
882+
The first line of an mbox file entry is the Unix "From " line.
883+
If *from_* is False, the first line of the file is dropped.
884+
860885

861886
.. method:: lock()
862887
unlock()

Doc/library/urllib.request.rst

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,48 +1215,49 @@ In addition to the examples below, more examples are given in
12151215
:ref:`urllib-howto`.
12161216

12171217
This example gets the python.org main page and displays the first 300 bytes of
1218-
it. ::
1218+
it::
12191219

12201220
>>> import urllib.request
12211221
>>> with urllib.request.urlopen('http://www.python.org/') as f:
12221222
... print(f.read(300))
12231223
...
1224-
b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1225-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\n\n<html
1226-
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\n<head>\n
1227-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />\n
1228-
<title>Python Programming '
1224+
b'<!doctype html>\n<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]-->\n<!--[if IE 7]> <html class="no-js ie7 lt-ie8 lt-ie9"> <![endif]-->\n<!--[if IE 8]> <html class="no-js ie8 lt-ie9">
12291225

12301226
Note that urlopen returns a bytes object. This is because there is no way
12311227
for urlopen to automatically determine the encoding of the byte stream
12321228
it receives from the HTTP server. In general, a program will decode
12331229
the returned bytes object to string once it determines or guesses
12341230
the appropriate encoding.
12351231

1236-
The following W3C document, https://www.w3.org/International/O-charset\ , lists
1237-
the various ways in which an (X)HTML or an XML document could have specified its
1232+
The following HTML spec document, https://html.spec.whatwg.org/#charset, lists
1233+
the various ways in which an HTML or an XML document could have specified its
12381234
encoding information.
12391235

1236+
For additional information, see the W3C document: https://www.w3.org/International/questions/qa-html-encoding-declarations.
1237+
12401238
As the python.org website uses *utf-8* encoding as specified in its meta tag, we
1241-
will use the same for decoding the bytes object. ::
1239+
will use the same for decoding the bytes object::
12421240

12431241
>>> with urllib.request.urlopen('http://www.python.org/') as f:
12441242
... print(f.read(100).decode('utf-8'))
12451243
...
1246-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1247-
"http://www.w3.org/TR/xhtml1/DTD/xhtm
1244+
<!doctype html>
1245+
<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]-->
1246+
<!-
12481247

12491248
It is also possible to achieve the same result without using the
1250-
:term:`context manager` approach. ::
1249+
:term:`context manager` approach::
12511250

12521251
>>> import urllib.request
12531252
>>> f = urllib.request.urlopen('http://www.python.org/')
12541253
>>> try:
12551254
... print(f.read(100).decode('utf-8'))
12561255
... finally:
12571256
... f.close()
1258-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1259-
"http://www.w3.org/TR/xhtml1/DTD/xhtm
1257+
...
1258+
<!doctype html>
1259+
<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]-->
1260+
<!--
12601261

12611262
In the following example, we are sending a data-stream to the stdin of a CGI
12621263
and reading the data it returns to us. Note that this example will only work

Doc/reference/compound_stmts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ A function definition defines a user-defined function object (see section
12221222
parameter_list_no_posonly: `defparameter` ("," `defparameter`)* ["," [`parameter_list_starargs`]]
12231223
: | `parameter_list_starargs`
12241224
parameter_list_starargs: "*" [`star_parameter`] ("," `defparameter`)* ["," [`parameter_star_kwargs`]]
1225-
: "*" ("," `defparameter`)+ ["," [`parameter_star_kwargs`]]
1225+
: | "*" ("," `defparameter`)+ ["," [`parameter_star_kwargs`]]
12261226
: | `parameter_star_kwargs`
12271227
parameter_star_kwargs: "**" `parameter` [","]
12281228
parameter: `identifier` [":" `expression`]

Include/internal/pycore_gc.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,6 @@ union _PyStackRef;
352352
extern int _PyGC_VisitFrameStack(_PyInterpreterFrame *frame, visitproc visit, void *arg);
353353
extern int _PyGC_VisitStackRef(union _PyStackRef *ref, visitproc visit, void *arg);
354354

355-
// Like Py_VISIT but for _PyStackRef fields
356-
#define _Py_VISIT_STACKREF(ref) \
357-
do { \
358-
if (!PyStackRef_IsNull(ref)) { \
359-
int vret = _PyGC_VisitStackRef(&(ref), visit, arg); \
360-
if (vret) \
361-
return vret; \
362-
} \
363-
} while (0)
364-
365355
#ifdef Py_GIL_DISABLED
366356
extern void _PyGC_VisitObjectsWorldStopped(PyInterpreterState *interp,
367357
gcvisitobjects_t callback, void *arg);

Include/internal/pycore_genobject.h

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,10 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#include "pycore_interpframe.h" // _PyInterpreterFrame
11+
#include "pycore_interpframe_structs.h" // _PyGenObject
1212

13+
#include <stddef.h> // offsetof()
1314

14-
/* _PyGenObject_HEAD defines the initial segment of generator
15-
and coroutine objects. */
16-
#define _PyGenObject_HEAD(prefix) \
17-
PyObject_HEAD \
18-
/* List of weak reference. */ \
19-
PyObject *prefix##_weakreflist; \
20-
/* Name of the generator. */ \
21-
PyObject *prefix##_name; \
22-
/* Qualified name of the generator. */ \
23-
PyObject *prefix##_qualname; \
24-
_PyErr_StackItem prefix##_exc_state; \
25-
PyObject *prefix##_origin_or_finalizer; \
26-
char prefix##_hooks_inited; \
27-
char prefix##_closed; \
28-
char prefix##_running_async; \
29-
/* The frame */ \
30-
int8_t prefix##_frame_state; \
31-
_PyInterpreterFrame prefix##_iframe; \
32-
33-
struct _PyGenObject {
34-
/* The gi_ prefix is intended to remind of generator-iterator. */
35-
_PyGenObject_HEAD(gi)
36-
};
37-
38-
struct _PyCoroObject {
39-
_PyGenObject_HEAD(cr)
40-
};
41-
42-
struct _PyAsyncGenObject {
43-
_PyGenObject_HEAD(ag)
44-
};
45-
46-
#undef _PyGenObject_HEAD
4715

4816
static inline
4917
PyGenObject *_PyGen_GetGeneratorFromFrame(_PyInterpreterFrame *frame)

Include/internal/pycore_interpframe.h

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/* See InternalDocs/frames.md for an explanation of the frame stack
2-
* including explanation of the PyFrameObject and _PyInterpreterFrame
3-
* structs. */
4-
51
#ifndef Py_INTERNAL_INTERP_FRAME_H
62
#define Py_INTERNAL_INTERP_FRAME_H
73

@@ -10,49 +6,14 @@
106
#endif
117

128
#include "pycore_code.h" // _PyCode_CODE()
13-
#include "pycore_structs.h" // _PyStackRef
9+
#include "pycore_interpframe_structs.h" // _PyInterpreterFrame
1410
#include "pycore_stackref.h" // PyStackRef_AsPyObjectBorrow()
15-
#include "pycore_typedefs.h" // _PyInterpreterFrame
16-
11+
#include "pycore_stats.h" // CALL_STAT_INC()
1712

1813
#ifdef __cplusplus
1914
extern "C" {
2015
#endif
2116

22-
enum _frameowner {
23-
FRAME_OWNED_BY_THREAD = 0,
24-
FRAME_OWNED_BY_GENERATOR = 1,
25-
FRAME_OWNED_BY_FRAME_OBJECT = 2,
26-
FRAME_OWNED_BY_INTERPRETER = 3,
27-
FRAME_OWNED_BY_CSTACK = 4,
28-
};
29-
30-
struct _PyInterpreterFrame {
31-
_PyStackRef f_executable; /* Deferred or strong reference (code object or None) */
32-
struct _PyInterpreterFrame *previous;
33-
_PyStackRef f_funcobj; /* Deferred or strong reference. Only valid if not on C stack */
34-
PyObject *f_globals; /* Borrowed reference. Only valid if not on C stack */
35-
PyObject *f_builtins; /* Borrowed reference. Only valid if not on C stack */
36-
PyObject *f_locals; /* Strong reference, may be NULL. Only valid if not on C stack */
37-
PyFrameObject *frame_obj; /* Strong reference, may be NULL. Only valid if not on C stack */
38-
_Py_CODEUNIT *instr_ptr; /* Instruction currently executing (or about to begin) */
39-
_PyStackRef *stackpointer;
40-
#ifdef Py_GIL_DISABLED
41-
/* Index of thread-local bytecode containing instr_ptr. */
42-
int32_t tlbc_index;
43-
#endif
44-
uint16_t return_offset; /* Only relevant during a function call */
45-
char owner;
46-
#ifdef Py_DEBUG
47-
uint8_t visited:1;
48-
uint8_t lltrace:7;
49-
#else
50-
uint8_t visited;
51-
#endif
52-
/* Locals and stack */
53-
_PyStackRef localsplus[1];
54-
};
55-
5617
#define _PyInterpreterFrame_LASTI(IF) \
5718
((int)((IF)->instr_ptr - _PyFrame_GetBytecode((IF))))
5819

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* Structures used by pycore_debug_offsets.h.
2+
*
3+
* See InternalDocs/frames.md for an explanation of the frame stack
4+
* including explanation of the PyFrameObject and _PyInterpreterFrame
5+
* structs.
6+
*/
7+
8+
#ifndef Py_INTERNAL_INTERP_FRAME_STRUCTS_H
9+
#define Py_INTERNAL_INTERP_FRAME_STRUCTS_H
10+
11+
#ifndef Py_BUILD_CORE
12+
# error "this header requires Py_BUILD_CORE define"
13+
#endif
14+
15+
#include "pycore_structs.h" // _PyStackRef
16+
#include "pycore_typedefs.h" // _PyInterpreterFrame
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
enum _frameowner {
23+
FRAME_OWNED_BY_THREAD = 0,
24+
FRAME_OWNED_BY_GENERATOR = 1,
25+
FRAME_OWNED_BY_FRAME_OBJECT = 2,
26+
FRAME_OWNED_BY_INTERPRETER = 3,
27+
FRAME_OWNED_BY_CSTACK = 4,
28+
};
29+
30+
struct _PyInterpreterFrame {
31+
_PyStackRef f_executable; /* Deferred or strong reference (code object or None) */
32+
struct _PyInterpreterFrame *previous;
33+
_PyStackRef f_funcobj; /* Deferred or strong reference. Only valid if not on C stack */
34+
PyObject *f_globals; /* Borrowed reference. Only valid if not on C stack */
35+
PyObject *f_builtins; /* Borrowed reference. Only valid if not on C stack */
36+
PyObject *f_locals; /* Strong reference, may be NULL. Only valid if not on C stack */
37+
PyFrameObject *frame_obj; /* Strong reference, may be NULL. Only valid if not on C stack */
38+
_Py_CODEUNIT *instr_ptr; /* Instruction currently executing (or about to begin) */
39+
_PyStackRef *stackpointer;
40+
#ifdef Py_GIL_DISABLED
41+
/* Index of thread-local bytecode containing instr_ptr. */
42+
int32_t tlbc_index;
43+
#endif
44+
uint16_t return_offset; /* Only relevant during a function call */
45+
char owner;
46+
#ifdef Py_DEBUG
47+
uint8_t visited:1;
48+
uint8_t lltrace:7;
49+
#else
50+
uint8_t visited;
51+
#endif
52+
/* Locals and stack */
53+
_PyStackRef localsplus[1];
54+
};
55+
56+
57+
/* _PyGenObject_HEAD defines the initial segment of generator
58+
and coroutine objects. */
59+
#define _PyGenObject_HEAD(prefix) \
60+
PyObject_HEAD \
61+
/* List of weak reference. */ \
62+
PyObject *prefix##_weakreflist; \
63+
/* Name of the generator. */ \
64+
PyObject *prefix##_name; \
65+
/* Qualified name of the generator. */ \
66+
PyObject *prefix##_qualname; \
67+
_PyErr_StackItem prefix##_exc_state; \
68+
PyObject *prefix##_origin_or_finalizer; \
69+
char prefix##_hooks_inited; \
70+
char prefix##_closed; \
71+
char prefix##_running_async; \
72+
/* The frame */ \
73+
int8_t prefix##_frame_state; \
74+
_PyInterpreterFrame prefix##_iframe; \
75+
76+
struct _PyGenObject {
77+
/* The gi_ prefix is intended to remind of generator-iterator. */
78+
_PyGenObject_HEAD(gi)
79+
};
80+
81+
struct _PyCoroObject {
82+
_PyGenObject_HEAD(cr)
83+
};
84+
85+
struct _PyAsyncGenObject {
86+
_PyGenObject_HEAD(ag)
87+
};
88+
89+
#undef _PyGenObject_HEAD
90+
91+
92+
#ifdef __cplusplus
93+
}
94+
#endif
95+
#endif // !Py_INTERNAL_INTERP_FRAME_STRUCTS_H

Include/internal/pycore_object.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#include <stdbool.h>
1211
#include "pycore_emscripten_trampoline.h" // _PyCFunction_TrampolineCall()
13-
#include "pycore_object_deferred.h" // _PyObject_HasDeferredRefcount
14-
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_STORE_PTR_RELAXED
12+
#include "pycore_gc.h" // _PyObject_GC_TRACK()
13+
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_PTR_ACQUIRE()
1514
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1615
#include "pycore_runtime.h" // _PyRuntime
1716
#include "pycore_typeobject.h" // _PyStaticType_GetState()
1817
#include "pycore_uniqueid.h" // _PyObject_ThreadIncrefSlow()
1918

19+
#include <stdbool.h> // bool
20+
21+
2022
// This value is added to `ob_ref_shared` for objects that use deferred
2123
// reference counting so that they are not immediately deallocated when the
2224
// non-deferred reference count drops to zero.

Include/internal/pycore_optimizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ typedef struct _jit_opt_tuple {
202202

203203
typedef struct {
204204
uint8_t tag;
205-
bool not;
205+
bool invert;
206206
uint16_t value;
207207
} JitOptTruthiness;
208208

0 commit comments

Comments
 (0)