Skip to content

Commit e391218

Browse files
committed
Merge branch 'main' into nodeaddict
* main: pythongh-102493: fix normalization in PyErr_SetObject (python#102502) pythongh-87092: compiler's CFG construction moved to after codegen stage (python#102320) pythongh-95913: Consolidate build requirements changes in 3.11 WhatsNew (pythonGH-98781) Remove redundant `_ensure_future` in favor of `ensure_future` in `asyncio` (python#102398) pythongh-95913: Edit Faster CPython section in 3.11 WhatsNew (pythonGH-98429) pythongh-90110: Fix the c-analyzer Tool (python#102483) pythongh-101759: Update macOS installer SQLite 3.40.1 checksum (pythongh-102485) Remove unused import of `warnings` from `unittest.loader` (python#102479) Add gettext support to tools/extensions/c_annotations.py (python#101989)
2 parents 239981c + a33ca2a commit e391218

File tree

22 files changed

+605
-325
lines changed

22 files changed

+605
-325
lines changed

Doc/tools/extensions/c_annotations.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from docutils.parsers.rst import directives
2525
from docutils.parsers.rst import Directive
2626
from docutils.statemachine import StringList
27+
from sphinx.locale import _ as sphinx_gettext
2728
import csv
2829

2930
from sphinx import addnodes
@@ -168,11 +169,11 @@ def add_annotations(self, app, doctree):
168169
elif not entry.result_type.endswith("Object*"):
169170
continue
170171
if entry.result_refs is None:
171-
rc = 'Return value: Always NULL.'
172+
rc = sphinx_gettext('Return value: Always NULL.')
172173
elif entry.result_refs:
173-
rc = 'Return value: New reference.'
174+
rc = sphinx_gettext('Return value: New reference.')
174175
else:
175-
rc = 'Return value: Borrowed reference.'
176+
rc = sphinx_gettext('Return value: Borrowed reference.')
176177
node.insert(0, nodes.emphasis(rc, rc, classes=['refcount']))
177178

178179

Doc/tools/templates/dummy.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
{% trans %}Deprecated since version {deprecated}, will be removed in version {removed}{% endtrans %}
88
{% trans %}Deprecated since version {deprecated}, removed in version {removed}{% endtrans %}
99

10+
In extensions/c_annotations.py:
11+
12+
{% trans %}Return value: Always NULL.{% endtrans %}
13+
{% trans %}Return value: New reference.{% endtrans %}
14+
{% trans %}Return value: Borrowed reference.{% endtrans %}
1015

1116
In docsbuild-scripts, when rewriting indexsidebar.html with actual versions:
1217

Doc/whatsnew/3.11.rst

Lines changed: 116 additions & 92 deletions
Large diffs are not rendered by default.

Include/internal/pycore_global_objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct _Py_interp_static_objects {
8686
// hamt_empty is here instead of global because of its weakreflist.
8787
_PyGC_Head_UNUSED _hamt_empty_gc_not_used;
8888
PyHamtObject hamt_empty;
89+
PyBaseExceptionObject last_resort_memory_error;
8990
} singletons;
9091
};
9192

Include/internal/pycore_intrinsics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value);
2222
typedef PyObject *(*instrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2);
2323

24-
extern instrinsic_func1 _PyIntrinsics_UnaryFunctions[];
25-
extern instrinsic_func2 _PyIntrinsics_BinaryFunctions[];
24+
extern const instrinsic_func1 _PyIntrinsics_UnaryFunctions[];
25+
extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[];
2626

Include/internal/pycore_runtime_init.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ extern "C" {
1414
#include "pycore_obmalloc_init.h"
1515

1616

17+
extern PyTypeObject _PyExc_MemoryError;
18+
19+
1720
/* The static initializers defined here should only be used
1821
in the runtime init code (in pystate.c and pylifecycle.c). */
1922

@@ -120,6 +123,9 @@ extern "C" {
120123
.ob_base = _PyObject_IMMORTAL_INIT(&_PyHamt_Type), \
121124
.h_root = (PyHamtNode*)&_Py_SINGLETON(hamt_bitmap_node_empty), \
122125
}, \
126+
.last_resort_memory_error = { \
127+
_PyObject_IMMORTAL_INIT(&_PyExc_MemoryError), \
128+
}, \
123129
}, \
124130
}, \
125131
._initial_thread = _PyThreadState_INIT, \

Lib/asyncio/tasks.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,6 @@ def ensure_future(coro_or_future, *, loop=None):
630630
631631
If the argument is a Future, it is returned directly.
632632
"""
633-
return _ensure_future(coro_or_future, loop=loop)
634-
635-
636-
def _ensure_future(coro_or_future, *, loop=None):
637633
if futures.isfuture(coro_or_future):
638634
if loop is not None and loop is not futures._get_loop(coro_or_future):
639635
raise ValueError('The future belongs to a different loop than '
@@ -798,7 +794,7 @@ def _done_callback(fut):
798794
outer = None # bpo-46672
799795
for arg in coros_or_futures:
800796
if arg not in arg_to_fut:
801-
fut = _ensure_future(arg, loop=loop)
797+
fut = ensure_future(arg, loop=loop)
802798
if loop is None:
803799
loop = futures._get_loop(fut)
804800
if fut is not arg:
@@ -855,7 +851,7 @@ def shield(arg):
855851
weak references to tasks. A task that isn't referenced elsewhere
856852
may get garbage collected at any time, even before it's done.
857853
"""
858-
inner = _ensure_future(arg)
854+
inner = ensure_future(arg)
859855
if inner.done():
860856
# Shortcut.
861857
return inner

Lib/test/test_capi/test_exceptions.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,34 @@ def test_err_restore(self):
140140
self.assertEqual(1, v.args[0])
141141
self.assertIs(tb, v.__traceback__.tb_next)
142142

143+
def test_set_object(self):
144+
145+
# new exception as obj is not an exception
146+
with self.assertRaises(ValueError) as e:
147+
_testcapi.exc_set_object(ValueError, 42)
148+
self.assertEqual(e.exception.args, (42,))
149+
150+
# wraps the exception because unrelated types
151+
with self.assertRaises(ValueError) as e:
152+
_testcapi.exc_set_object(ValueError, TypeError(1,2,3))
153+
wrapped = e.exception.args[0]
154+
self.assertIsInstance(wrapped, TypeError)
155+
self.assertEqual(wrapped.args, (1, 2, 3))
156+
157+
# is superclass, so does not wrap
158+
with self.assertRaises(PermissionError) as e:
159+
_testcapi.exc_set_object(OSError, PermissionError(24))
160+
self.assertEqual(e.exception.args, (24,))
161+
162+
class Meta(type):
163+
def __subclasscheck__(cls, sub):
164+
1/0
165+
166+
class Broken(Exception, metaclass=Meta):
167+
pass
168+
169+
with self.assertRaises(ZeroDivisionError) as e:
170+
_testcapi.exc_set_object(Broken, Broken())
143171

144172
if __name__ == "__main__":
145173
unittest.main()

Lib/unittest/loader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import traceback
77
import types
88
import functools
9-
import warnings
109

1110
from fnmatch import fnmatch, fnmatchcase
1211

Mac/BuildScript/build-installer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def library_recipes():
361361
dict(
362362
name="SQLite 3.40.1",
363363
url="https://sqlite.org/2022/sqlite-autoconf-3400100.tar.gz",
364-
checksum="5498af3a357753d473ee713e363fa5b7",
364+
checksum="42175b1a1d23529cb133bbd2b5900afd",
365365
extra_cflags=('-Os '
366366
'-DSQLITE_ENABLE_FTS5 '
367367
'-DSQLITE_ENABLE_FTS4 '
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix regression in semantics of normalisation in ``PyErr_SetObject``.

Modules/_testcapi/exceptions.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ make_exception_with_doc(PyObject *self, PyObject *args, PyObject *kwargs)
7878
return PyErr_NewExceptionWithDoc(name, doc, base, dict);
7979
}
8080

81+
static PyObject *
82+
exc_set_object(PyObject *self, PyObject *args)
83+
{
84+
PyObject *exc;
85+
PyObject *obj;
86+
87+
if (!PyArg_ParseTuple(args, "OO:exc_set_object", &exc, &obj)) {
88+
return NULL;
89+
}
90+
91+
PyErr_SetObject(exc, obj);
92+
return NULL;
93+
}
94+
8195
static PyObject *
8296
raise_exception(PyObject *self, PyObject *args)
8397
{
@@ -247,6 +261,7 @@ static PyMethodDef test_methods[] = {
247261
PyDoc_STR("fatal_error(message, release_gil=False): call Py_FatalError(message)")},
248262
{"make_exception_with_doc", _PyCFunction_CAST(make_exception_with_doc),
249263
METH_VARARGS | METH_KEYWORDS},
264+
{"exc_set_object", exc_set_object, METH_VARARGS},
250265
{"raise_exception", raise_exception, METH_VARARGS},
251266
{"raise_memoryerror", raise_memoryerror, METH_NOARGS},
252267
{"set_exc_info", test_set_exc_info, METH_VARARGS},

Objects/exceptions.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,16 +3207,16 @@ SimpleExtendsException(PyExc_Exception, ReferenceError,
32073207

32083208
#define MEMERRORS_SAVE 16
32093209

3210-
static PyBaseExceptionObject last_resort_memory_error;
3211-
32123210
static PyObject *
32133211
get_memory_error(int allow_allocation, PyObject *args, PyObject *kwds)
32143212
{
32153213
PyBaseExceptionObject *self;
32163214
struct _Py_exc_state *state = get_exc_state();
32173215
if (state->memerrors_freelist == NULL) {
32183216
if (!allow_allocation) {
3219-
return Py_NewRef(&last_resort_memory_error);
3217+
PyInterpreterState *interp = _PyInterpreterState_GET();
3218+
return Py_NewRef(
3219+
&_Py_INTERP_SINGLETON(interp, last_resort_memory_error));
32203220
}
32213221
PyObject *result = BaseException_new((PyTypeObject *)PyExc_MemoryError, args, kwds);
32223222
return result;
@@ -3239,8 +3239,6 @@ get_memory_error(int allow_allocation, PyObject *args, PyObject *kwds)
32393239
return (PyObject *)self;
32403240
}
32413241

3242-
static PyBaseExceptionObject last_resort_memory_error;
3243-
32443242
static PyObject *
32453243
MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
32463244
{
@@ -3325,7 +3323,7 @@ free_preallocated_memerrors(struct _Py_exc_state *state)
33253323
}
33263324

33273325

3328-
static PyTypeObject _PyExc_MemoryError = {
3326+
PyTypeObject _PyExc_MemoryError = {
33293327
PyVarObject_HEAD_INIT(NULL, 0)
33303328
"MemoryError",
33313329
sizeof(PyBaseExceptionObject),
@@ -3339,9 +3337,6 @@ static PyTypeObject _PyExc_MemoryError = {
33393337
};
33403338
PyObject *PyExc_MemoryError = (PyObject *) &_PyExc_MemoryError;
33413339

3342-
static PyBaseExceptionObject last_resort_memory_error = {
3343-
_PyObject_IMMORTAL_INIT(&_PyExc_MemoryError)
3344-
};
33453340

33463341
/*
33473342
* BufferError extends Exception

0 commit comments

Comments
 (0)