8000 Merge branch 'master' into bpo_41832 · shihai1991/cpython@c267e35 · GitHub
[go: up one dir, main page]

Skip to content

Commit c267e35

Browse files
committed
Merge branch 'master' into bpo_41832
* master: bpo-42260: Add _PyInterpreterState_SetConfig() (pythonGH-23158) Disable peg generator tests when building with PGO (pythonGH-23141) bpo-1635741: _sqlite3 uses PyModule_AddObjectRef() (pythonGH-23148) bpo-1635741: Fix PyInit_pyexpat() error handling (pythonGH-22489) bpo-42260: Main init modify sys.flags in-place (pythonGH-23150) bpo-1635741: Fix ref leak in _PyWarnings_Init() error path (pythonGH-23151) bpo-1635741: _ast uses PyModule_AddObjectRef() (pythonGH-23146) bpo-1635741: _contextvars uses PyModule_AddType() (pythonGH-23147) bpo-42260: Reorganize PyConfig (pythonGH-23149) bpo-1635741: Add PyModule_AddObjectRef() function (pythonGH-23122) bpo-42236: os.device_encoding() respects UTF-8 Mode (pythonGH-23119) bpo-42251: Add gettrace and getprofile to threading (pythonGH-23125) Enable signing of nuget.org packages and update to supported timestamp server (pythonGH-23132) Fix incorrect links in ast docs (pythonGH-23017) Add _PyType_GetModuleByDef (pythonGH-22835) Post 3.10.0a2 bpo-41796: Call _PyAST_Fini() earlier to fix a leak (pythonGH-23131) bpo-42249: Fix writing binary Plist files larger than 4 GiB. (pythonGH-23121) bpo-40077: Convert mmap.mmap static type to a heap type (pythonGH-23108) Python 3.10.0a2
2 parents cca7bc7 + 048a356 commit c267e35

File tree

143 files changed

+2286
-1002
lines changed

Some content is hidden

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

143 files changed

+2286
-1002
lines changed

.azure-pipelines/windows-release/stage-pack-msix.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ jobs:
120120
artifactName: unsigned_msix
121121
downloadPath: $(Build.BinariesDirectory)
122122

123+
# MSIX must be signed and timestamped simultaneously
123124
- powershell: |
124125
$failed = $true
125126
foreach ($retry in 1..3) {
126-
signtool sign /a /n "$(SigningCertificate)" /fd sha256 /t http://timestamp.verisign.com/scripts/timestamp.dll /d "$(SigningDescription)" (gi *.msix)
127+
signtool sign /a /n "$(SigningCertificate)" /fd sha256 /tr http://timestamp.digicert.com/ /td sha256 /d "$(SigningDescription)" (gi *.msix)
127128
if ($?) {
128129
$failed = $false
129130
break

.azure-pipelines/windows-release/stage-pack-nuget.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jobs:
44
condition: and(succeeded(), eq(variables['DoNuget'], 'true'))
55

66
pool:
7-
vmImage: windows-2019
7+
name: 'Windows Release'
88

99
workspace:
1010
clean: all
@@ -36,6 +36,14 @@ jobs:
3636
nuget pack "$(Build.BinariesDirectory)\layout\python.nuspec" -OutputDirectory $(Build.ArtifactStagingDirectory) -NoPackageAnalysis -NonInteractive
3737
displayName: 'Create nuget package'
3838
39+
- powershell: |
40+
gci *.nupkg | %{
41+
nuget sign "$_" -CertificateSubjectName "$(SigningCertificate)" -Timestamper http://timestamp.digicert.com/ -Overwrite
42+
}
43+
displayName: 'Sign nuget package'
44+
workingDirectory: $(Build.ArtifactStagingDirectory)
45+
condition: and(succeeded(), variables['SigningCertificate'])
46+
3947
- task: PublishBuildArtifacts@1
4048
displayName: 'Publish Artifact: nuget'
4149
inputs:

.azure-pipelines/windows-release/stage-sign.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
$files = (gi ${{ parameters.Include }} -Exclude ${{ parameters.Exclude }})
5858
$failed = $true
5959
foreach ($retry in 1..10) {
60-
signtool timestamp /t http://timestamp.verisign.com/scripts/timestamp.dll $files
60+
signtool timestamp /tr http://timestamp.digicert.com/ /td sha256 $files
6161
if ($?) {
6262
$failed = $false
6363
break

Doc/c-api/init_config.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ PyStatus
128128
129129
Initialization error with a message.
130130
131+
*err_msg* must not be ``NULL``.
132+
131133
.. c:function:: PyStatus PyStatus_NoMemory(void)
132134
133135
Memory allocation failure (out of memory).

Doc/c-api/module.rst

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ of the following two module creation functions:
264264
instead; only use this if you are sure you need it.
265265
266266
Before it is returned from in the initialization function, the resulting module
267-
object is typically populated using functions like :c:func:`PyModule_AddObject`.
267+
object is typically populated using functions like :c:func:`PyModule_AddObjectRef`.
268268
269269
.. _multi-phase-initialization:
270270
@@ -437,26 +437,102 @@ a function called from a module execution slot (if using multi-phase
437437
initialization), can use the following functions to help initialize the module
438438
state:
439439
440+
.. c:function:: int PyModule_AddObjectRef(PyObject *module, const char *name, PyObject *value)
441+
442+
Add an object to *module* as *name*. This is a convenience function which
443+
can be used from the module's initialization function.
444+
445+
On success, return ``0``. On error, raise an exception and return ``-1``.
446+
447+
Return ``NULL`` if *value* is ``NULL``. It must be called with an exception
448+
raised in this case.
449+
450+
Example usage::
451+
452+
static int
453+
add_spam(PyObject *module, int value)
454+
{
455+
PyObject *obj = PyLong_FromLong(value);
456+
if (obj == NULL) {
457+
return -1;
458+
}
459+
int res = PyModule_AddObjectRef(module, "spam", obj);
460+
Py_DECREF(obj);
461+
return res;
462+
}
463+
464+
The example can also be written without checking explicitly if *obj* is
465+
``NULL``::
466+
467+
static int
468+
add_spam(PyObject *module, int value)
469+
{
470+
PyObject *obj = PyLong_FromLong(value);
471+
int res = PyModule_AddObjectRef(module, "spam", obj);
472+
Py_XDECREF(obj);
473+
return res;
474+
}
475+
476+
Note that ``Py_XDECREF()`` should be used instead of ``Py_DECREF()`` in
477+
this case, since *obj* can be ``NULL``.
478+
479+
.. versionadded:: 3.10
480+
481+
440482
.. c:function:: int PyModule_AddObject(PyObject *module, const char *name, PyObject *value)
441483
442-
Add an object to *module* as *name*. This is a convenience function which can
443-
be used from the module's initialization function. This steals a reference to
444-
*value* on success. Return ``-1`` on error, ``0`` on success.
484+
Similar to :c:func:`PyModule_AddObjectRef`, but steals a reference to
485+
*value* on success (if it returns ``0``).
486+
487+
The new :c:func:`PyModule_AddObjectRef` function is recommended, since it is
488+
easy to introduce reference leaks by misusing the
489+
:c:func:`PyModule_AddObject` function.
445490
446491
.. note::
447492
448-
Unlike other functions that steal references, ``PyModule_AddObject()`` only
449-
decrements the reference count of *value* **on success**.
493+
Unlike other functions that steal references, ``PyModule_AddObject()``
494+
only decrements the reference count of *value* **on success**.
450495
451496
This means that its return value must be checked, and calling code must
452-
:c:func:`Py_DECREF` *value* manually on error. Example usage::
453-
454-
Py_INCREF(spam);
455-
if (PyModule_AddObject(module, "spam", spam) < 0) {
456-
Py_DECREF(module);
457-
Py_DECREF(spam);
458-
return NULL;
459-
}
497+
:c:func:`Py_DECREF` *value* manually on error.
498+
499+
Example usage::
500+
501+
static int
502+
add_spam(PyObject *module, int value)
503+
{
504+
PyObject *obj = PyLong_FromLong(value);
505+
if (obj == NULL) {
506+
return -1;
507+
}
508+
if (PyModule_AddObject(module, "spam", obj) < 0) {
509+
Py_DECREF(obj);
510+
return -1;
511+
}
512+
// PyModule_AddObject() stole a reference to obj:
513+
// Py_DECREF(obj) is not needed here
514+
return 0;
515+
}
516+
517+
The example can also be written without checking explicitly if *obj* is
518+
``NULL``::
519+
520+
static int
521+
add_spam(PyObject *module, int value)
522+
{
523+
PyObject *obj = PyLong_FromLong(value);
524+
if (PyModule_AddObject(module, "spam", obj) < 0) {
525+
Py_XDECREF(obj);
526+
return -1;
527+
}
528+
// PyModule_AddObject() stole a reference to obj:
529+
// Py_DECREF(obj) is not needed here
530+
return 0;
531+
}
532+
533+
Note that ``Py_XDECREF()`` should be used instead of ``Py_DECREF()`` in
534+
this case, since *obj* can be ``NULL``.
535+
460536
461537
.. c:function:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value)
462 F438 538

Doc/library/ast.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ Node classes
8080
end_col_offset
8181

8282
Instances of :class:`ast.expr` and :class:`ast.stmt` subclasses have
83-
:attr:`lineno`, :attr:`col_offset`, :attr:`lineno`, and :attr:`col_offset`
84-
attributes. The :attr:`lineno` and :attr:`end_lineno` are the first and
85-
last line numbers of source text span (1-indexed so the first line is line 1)
86-
and the :attr:`col_offset` and :attr:`end_col_offset` are the corresponding
87-
UTF-8 byte offsets of the first and last tokens that generated the node.
88-
The UTF-8 offset is recorded because the parser uses UTF-8 internally.
83+
:attr:`lineno`, :attr:`col_offset`, :attr:`end_lineno`, and
84+
:attr:`end_col_offset` attributes. The :attr:`lineno` and :attr:`end_lineno`
85+
are the first and last line numbers of source text span (1-indexed so the
86+
first line is line 1) and the :attr:`col_offset` and :attr:`end_col_offset`
87+
are the corresponding UTF-8 byte offsets of the first and last tokens that
88+
generated the node. The UTF-8 offset is recorded because the parser uses
89+
UTF-8 internally.
8990

9091
Note that the end positions are not required by the compiler and are
9192
therefore optional. The end offset is *after* the last symbol, for example

Doc/library/os.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ of the UTF-8 encoding:
113113
:ref:`error handler <error-handlers>` being enabled for :data:`sys.stdin`
114114
and :data:`sys.stdout` (:data:`sys.stderr` continues to use
115115
``backslashreplace`` as it does in the default locale-aware mode)
116+
* On Unix, :func:`os.device_encoding` returns ``'UTF-8'``. rather than the
117+
device encoding.
116118

117119
Note that the standard stream settings in UTF-8 mode can be overridden by
118120
:envvar:`PYTHONIOENCODING` (just as they can be in the default locale-aware
@@ -808,6 +810,12 @@ as internal buffering of data.
808810
Return a string describing the encoding of the device associated with *fd*
809811
if it is connected to a terminal; else return :const:`None`.
810812

813+
On Unix, if the :ref:`Python UTF-8 Mode <utf8-mode>` is enabled, return
814+
``'UTF-8'`` rather than the device encoding.
815+
816+
.. versionchanged:: 3.10
817+
On Unix, the function now implements the Python UTF-8 Mode.
818+
811819

812820
.. function:: dup(fd)
813821

Doc/library/threading.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ This module defines the following functions:
121121
:meth:`~Thread.run` method is called.
122122

123123

124+
.. function:: gettrace()
125+
126+
.. index::
127+
single: trace function
128+
single: debugger
129+
130+
Get the trace function as set by :func:`settrace`.
131+
132+
.. versionadded:: 3.10
133+
134+
124135
.. function:: setprofile(func)
125136

126137
.. index:: single: profile function
@@ -130,6 +141,15 @@ This module defines the following functions:
130141
:meth:`~Thread.run` method is called.
131142

132143

144+
.. function:: getprofile()
145+
146+
.. index:: single: profile function
147+
148+
Get the profiler function as set by :func:`setprofile`.
149+
150+
.. versionadded:: 3.10
151+
152+
133153
.. function:: stack_size([size])
134154

135155
Return the thread stack size used when creating new threads. The optional

Doc/whatsnew/3.10.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ Add :data:`sys.orig_argv` attribute: the list of the original command line
224224
arguments passed to the Python executable.
225225
(Contributed by Victor Stinner in :issue:`23427`.)
226226

227+
threading
228+
---------
229+
230+
Added :func:`threading.gettrace` and :func:`threading.getprofile` to
231+
retrieve the functions set by :func:`threading.settrace` and
232+
:func:`threading.setprofile` respectively.
233+
(Contributed by Mario Corchero in :issue:`42251`.)
234+
227235
types
228236
-----
229237

@@ -366,6 +374,11 @@ New Features
366374
* Added :c:func:`PyUnicode_AsUTF8AndSize` to the limited C API.
367375
(Contributed by Alex Gaynor in :issue:`41784`.)
368376

377+
* Added :c:func:`PyModule_AddObjectRef` function: similar to
378+
:c:func:`PyModule_AddObjectRef` but don't steal a reference to the value on
379+
success.
380+
(Contributed by Victor Stinner in :issue:`1635741`.)
381+
369382
* The :c:func:`PyType_FromModuleAndSpec` function now accepts NULL ``tp_doc``
370383
slot.
371384
(Contributed by Hai Shi in :issue:`41832`.)

Include/cpython/initconfig.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ PyAPI_FUNC(PyStatus) PyWideStringList_Insert(PyWideStringList *list,
4141

4242
/* --- PyPreConfig ----------------------------------------------- */
4343

44-
typedef struct {
44+
typedef struct PyPreConfig {
4545
int _config_init; /* _PyConfigInitEnum value */
4646

4747
/* Parse Py_PreInitializeFromBytesArgs() arguments?
@@ -128,7 +128,7 @@ PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
128128
/* --- PyConfig ---------------------------------------------- */
129129

130130
/* This structure is best documented in the Doc/c-api/init_config.rst file. */
131-
typedef struct {
131+
typedef struct PyConfig {
132132
int _config_init; /* _PyConfigInitEnum value */
133133

134134
int isolated;
@@ -147,8 +147,8 @@ typedef struct {
147147
wchar_t *filesystem_errors;
148148
wchar_t *pycache_prefix;
149149
int parse_argv;
150+
PyWideStringList orig_argv;
150151
PyWideStringList argv;
151-
wchar_t *program_name;
152152
PyWideStringList xoptions;
153153
PyWideStringList warnoptions;
154154
int site_import;
@@ -169,12 +169,13 @@ typedef struct {
169169
int legacy_windows_stdio;
170170
#endif
171171
wchar_t *check_hash_pycs_mode;
172-
PyWideStringList orig_argv;
173172

174173
/* --- Path configuration inputs ------------ */
175174
int pathconfig_warnings;
175+
wchar_t *program_name;
176176
wchar_t *pythonpath_env;
177177
wchar_t *home;
178+
wchar_t *platlibdir;
178179

179180
/* --- Path configuration outputs ----------- */
180181
int module_search_paths_set;
@@ -185,7 +186,6 @@ typedef struct {
185186
wchar_t *base_prefix;
186187
wchar_t *exec_prefix;
187188
wchar_t *base_exec_prefix;
188-
wchar_t *platlibdir;
189189

190190
/* --- Parameter only used by Py_Main() ---------- */
191191
int skip_source_first_line;

0 commit comments

Comments
 (0)
0