Skip to content

Commit

Permalink
Merge branch 'main' into nodeaddict
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
carljm committed Mar 7, 2023
2 parents 239981c + a33ca2a commit e391218
Show file tree
Hide file tree
Showing 22 changed files with 605 additions and 325 deletions.
7 changes: 4 additions & 3 deletions Doc/tools/extensions/c_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from docutils.parsers.rst import directives
from docutils.parsers.rst import Directive
from docutils.statemachine import StringList
from sphinx.locale import _ as sphinx_gettext
import csv

from sphinx import addnodes
Expand Down Expand Up @@ -168,11 +169,11 @@ def add_annotations(self, app, doctree):
elif not entry.result_type.endswith("Object*"):
continue
if entry.result_refs is None:
rc = 'Return value: Always NULL.'
rc = sphinx_gettext('Return value: Always NULL.')
elif entry.result_refs:
rc = 'Return value: New reference.'
rc = sphinx_gettext('Return value: New reference.')
else:
rc = 'Return value: Borrowed reference.'
rc = sphinx_gettext('Return value: Borrowed reference.')
node.insert(0, nodes.emphasis(rc, rc, classes=['refcount']))


Expand Down
5 changes: 5 additions & 0 deletions Doc/tools/templates/dummy.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
{% trans %}Deprecated since version {deprecated}, will be removed in version {removed}{% endtrans %}
{% trans %}Deprecated since version {deprecated}, removed in version {removed}{% endtrans %}

In extensions/c_annotations.py:

{% trans %}Return value: Always NULL.{% endtrans %}
{% trans %}Return value: New reference.{% endtrans %}
{% trans %}Return value: Borrowed reference.{% endtrans %}

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

Expand Down
208 changes: 116 additions & 92 deletions Doc/whatsnew/3.11.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct _Py_interp_static_objects {
// hamt_empty is here instead of global because of its weakreflist.
_PyGC_Head_UNUSED _hamt_empty_gc_not_used;
PyHamtObject hamt_empty;
PyBaseExceptionObject last_resort_memory_error;
} singletons;
};

Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value);
typedef PyObject *(*instrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2);

extern instrinsic_func1 _PyIntrinsics_UnaryFunctions[];
extern instrinsic_func2 _PyIntrinsics_BinaryFunctions[];
extern const instrinsic_func1 _PyIntrinsics_UnaryFunctions[];
extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[];

6 changes: 6 additions & 0 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ extern "C" {
#include "pycore_obmalloc_init.h"


extern PyTypeObject _PyExc_MemoryError;


/* The static initializers defined here should only be used
in the runtime init code (in pystate.c and pylifecycle.c). */

Expand Down Expand Up @@ -120,6 +123,9 @@ extern "C" {
.ob_base = _PyObject_IMMORTAL_INIT(&_PyHamt_Type), \
.h_root = (PyHamtNode*)&_Py_SINGLETON(hamt_bitmap_node_empty), \
}, \
.last_resort_memory_error = { \
_PyObject_IMMORTAL_INIT(&_PyExc_MemoryError), \
}, \
}, \
}, \
._initial_thread = _PyThreadState_INIT, \
Expand Down
8 changes: 2 additions & 6 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,6 @@ def ensure_future(coro_or_future, *, loop=None):
If the argument is a Future, it is returned directly.
"""
return _ensure_future(coro_or_future, loop=loop)


def _ensure_future(coro_or_future, *, loop=None):
if futures.isfuture(coro_or_future):
if loop is not None and loop is not futures._get_loop(coro_or_future):
raise ValueError('The future belongs to a different loop than '
Expand Down Expand Up @@ -798,7 +794,7 @@ def _done_callback(fut):
outer = None # bpo-46672
for arg in coros_or_futures:
if arg not in arg_to_fut:
fut = _ensure_future(arg, loop=loop)
fut = ensure_future(arg, loop=loop)
if loop is None:
loop = futures._get_loop(fut)
if fut is not arg:
Expand Down Expand Up @@ -855,7 +851,7 @@ def shield(arg):
weak references to tasks. A task that isn't referenced elsewhere
may get garbage collected at any time, even before it's done.
"""
inner = _ensure_future(arg)
inner = ensure_future(arg)
if inner.done():
# Shortcut.
return inner
Expand Down
28 changes: 28 additions & 0 deletions Lib/test/test_capi/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,34 @@ def test_err_restore(self):
self.assertEqual(1, v.args[0])
self.assertIs(tb, v.__traceback__.tb_next)

def test_set_object(self):

# new exception as obj is not an exception
with self.assertRaises(ValueError) as e:
_testcapi.exc_set_object(ValueError, 42)
self.assertEqual(e.exception.args, (42,))

# wraps the exception because unrelated types
with self.assertRaises(ValueError) as e:
_testcapi.exc_set_object(ValueError, TypeError(1,2,3))
wrapped = e.exception.args[0]
self.assertIsInstance(wrapped, TypeError)
self.assertEqual(wrapped.args, (1, 2, 3))

# is superclass, so does not wrap
with self.assertRaises(PermissionError) as e:
_testcapi.exc_set_object(OSError, PermissionError(24))
self.assertEqual(e.exception.args, (24,))

class Meta(type):
def __subclasscheck__(cls, sub):
1/0

class Broken(Exception, metaclass=Meta):
pass

with self.assertRaises(ZeroDivisionError) as e:
_testcapi.exc_set_object(Broken, Broken())

if __name__ == "__main__":
unittest.main()
1 change: 0 additions & 1 deletion Lib/unittest/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import traceback
import types
import functools
import warnings

from fnmatch import fnmatch, fnmatchcase

Expand Down
2 changes: 1 addition & 1 deletion Mac/BuildScript/build-installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def library_recipes():
dict(
name="SQLite 3.40.1",
url="https://sqlite.org/2022/sqlite-autoconf-3400100.tar.gz",
checksum="5498af3a357753d473ee713e363fa5b7",
checksum="42175b1a1d23529cb133bbd2b5900afd",
extra_cflags=('-Os '
'-DSQLITE_ENABLE_FTS5 '
'-DSQLITE_ENABLE_FTS4 '
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regression in semantics of normalisation in ``PyErr_SetObject``.
15 changes: 15 additions & 0 deletions Modules/_testcapi/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ make_exception_with_doc(PyObject *self, PyObject *args, PyObject *kwargs)
return PyErr_NewExceptionWithDoc(name, doc, base, dict);
}

static PyObject *
exc_set_object(PyObject *self, PyObject *args)
{
PyObject *exc;
PyObject *obj;

if (!PyArg_ParseTuple(args, "OO:exc_set_object", &exc, &obj)) {
return NULL;
}

PyErr_SetObject(exc, obj);
return NULL;
}

static PyObject *
raise_exception(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -247,6 +261,7 @@ static PyMethodDef test_methods[] = {
PyDoc_STR("fatal_error(message, release_gil=False): call Py_FatalError(message)")},
{"make_exception_with_doc", _PyCFunction_CAST(make_exception_with_doc),
METH_VARARGS | METH_KEYWORDS},
{"exc_set_object", exc_set_object, METH_VARARGS},
{"raise_exception", raise_exception, METH_VARARGS},
{"raise_memoryerror", raise_memoryerror, METH_NOARGS},
{"set_exc_info", test_set_exc_info, METH_VARARGS},
Expand Down
13 changes: 4 additions & 9 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3207,16 +3207,16 @@ SimpleExtendsException(PyExc_Exception, ReferenceError,

#define MEMERRORS_SAVE 16

static PyBaseExceptionObject last_resort_memory_error;

static PyObject *
get_memory_error(int allow_allocation, PyObject *args, PyObject *kwds)
{
PyBaseExceptionObject *self;
struct _Py_exc_state *state = get_exc_state();
if (state->memerrors_freelist == NULL) {
if (!allow_allocation) {
return Py_NewRef(&last_resort_memory_error);
PyInterpreterState *interp = _PyInterpreterState_GET();
return Py_NewRef(
&_Py_INTERP_SINGLETON(interp, last_resort_memory_error));
}
PyObject *result = BaseException_new((PyTypeObject *)PyExc_MemoryError, args, kwds);
return result;
Expand All @@ -3239,8 +3239,6 @@ get_memory_error(int allow_allocation, PyObject *args, PyObject *kwds)
return (PyObject *)self;
}

static PyBaseExceptionObject last_resort_memory_error;

static PyObject *
MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
Expand Down Expand Up @@ -3325,7 +3323,7 @@ free_preallocated_memerrors(struct _Py_exc_state *state)
}


static PyTypeObject _PyExc_MemoryError = {
PyTypeObject _PyExc_MemoryError = {
PyVarObject_HEAD_INIT(NULL, 0)
"MemoryError",
sizeof(PyBaseExceptionObject),
Expand All @@ -3339,9 +3337,6 @@ static PyTypeObject _PyExc_MemoryError = {
};
PyObject *PyExc_MemoryError = (PyObject *) &_PyExc_MemoryError;

static PyBaseExceptionObject last_resort_memory_error = {
_PyObject_IMMORTAL_INIT(&_PyExc_MemoryError)
};

/*
* BufferError extends Exception
Expand Down
Loading

0 comments on commit e391218

Please sign in to comment.