Skip to content

Commit

Permalink
Update Python 3 to 3.12.9
Browse files Browse the repository at this point in the history
commit_hash:c8651982d81e18f18e037fb247cc6ae53c4fa7f1
  • Loading branch information
shadchin committed Feb 16, 2025
1 parent fb81236 commit 0063a32
Show file tree
Hide file tree
Showing 84 changed files with 872 additions and 513 deletions.
2 changes: 1 addition & 1 deletion contrib/tools/python3/Include/cpython/pytime.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ functions and constants
extern "C" {
#endif

#ifdef __clang__
#if defined(__clang__) || defined(_MSC_VER)
struct timeval;
#endif

Expand Down
5 changes: 5 additions & 0 deletions contrib/tools/python3/Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
_Py_AddRefTotal(_PyInterpreterState_GET(), n);
#endif
op->ob_refcnt += n;

// Although the ref count was increased by `n` (which may be greater than 1)
// it is only a single increment (i.e. addition) operation, so only 1 refcnt
// increment operation is counted.
_Py_INCREF_STAT_INC();
}
#define _Py_RefcntAdd(op, n) _Py_RefcntAdd(_PyObject_CAST(op), n)

Expand Down
12 changes: 12 additions & 0 deletions contrib/tools/python3/Include/internal/pycore_pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ PyAPI_FUNC(void) _PyErr_SetString(
PyObject *exception,
const char *string);

/*
* Set an exception with the error message decoded from the current locale
* encoding (LC_CTYPE).
*
* Exceptions occurring in decoding take priority over the desired exception.
*
* Exported for '_ctypes' shared extensions.
*/
PyAPI_FUNC(void) _PyErr_SetLocaleString(
PyObject *exception,
const char *string);

PyAPI_FUNC(PyObject *) _PyErr_Format(
PyThreadState *tstate,
PyObject *exception,
Expand Down
4 changes: 2 additions & 2 deletions contrib/tools/python3/Include/patchlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
/*--start constants--*/
#define PY_MAJOR_VERSION 3
#define PY_MINOR_VERSION 12
#define PY_MICRO_VERSION 8
#define PY_MICRO_VERSION 9
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
#define PY_RELEASE_SERIAL 0

/* Version as a string */
#define PY_VERSION "3.12.8"
#define PY_VERSION "3.12.9"
/*--end constants--*/

/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
Expand Down
11 changes: 5 additions & 6 deletions contrib/tools/python3/Include/pyconfig-linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
/* Define if --enable-ipv6 is specified */
#define ENABLE_IPV6 1

/* Define to 1 if your system stores words within floats with the most
significant word first */
/* #undef FLOAT_WORDS_BIGENDIAN */

/* Define if getpgrp() must be called as getpgrp(0). */
/* #undef GETPGRP_HAVE_ARG */

Expand Down Expand Up @@ -1339,6 +1335,9 @@
/* Define to 1 if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1

/* Define to 1 if you have the <sys/pidfd.h> header file. */
/* #undef HAVE_SYS_PIDFD_H */

/* Define to 1 if you have the <sys/poll.h> header file. */
#define HAVE_SYS_POLL_H 1

Expand Down Expand Up @@ -1439,8 +1438,8 @@
/* Define to 1 if you have the `truncate' function. */
#define HAVE_TRUNCATE 1

/* Define to 1 if you have the `ttyname' function. */
#define HAVE_TTYNAME 1
/* Define to 1 if you have the `ttyname_r' function. */
#define HAVE_TTYNAME_R 1

/* Define to 1 if you don't have `tm_zone' but do have the external array
`tzname'. */
Expand Down
11 changes: 5 additions & 6 deletions contrib/tools/python3/Include/pyconfig-osx-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
/* Define if --enable-ipv6 is specified */
#define ENABLE_IPV6 1

/* Define to 1 if your system stores words within floats with the most
significant word first */
/* #undef FLOAT_WORDS_BIGENDIAN */

/* Define if getpgrp() must be called as getpgrp(0). */
/* #undef GETPGRP_HAVE_ARG */

Expand Down Expand Up @@ -1337,6 +1333,9 @@
/* Define to 1 if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1

/* Define to 1 if you have the <sys/pidfd.h> header file. */
/* #undef HAVE_SYS_PIDFD_H */

/* Define to 1 if you have the <sys/poll.h> header file. */
#define HAVE_SYS_POLL_H 1

Expand Down Expand Up @@ -1437,8 +1436,8 @@
/* Define to 1 if you have the `truncate' function. */
#define HAVE_TRUNCATE 1

/* Define to 1 if you have the `ttyname' function. */
#define HAVE_TTYNAME 1
/* Define to 1 if you have the `ttyname_r' function. */
#define HAVE_TTYNAME_R 1

/* Define to 1 if you don't have `tm_zone' but do have the external array
`tzname'. */
Expand Down
9 changes: 9 additions & 0 deletions contrib/tools/python3/Include/pymacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@
*/
#if defined(__GNUC__) || defined(__clang__)
# define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
#elif defined(_MSC_VER)
// Disable warning C4100: unreferenced formal parameter,
// declare the parameter,
// restore old compiler warnings.
# define Py_UNUSED(name) \
__pragma(warning(push)) \
__pragma(warning(suppress: 4100)) \
_unused_ ## name \
__pragma(warning(pop))
#else
# define Py_UNUSED(name) _unused_ ## name
#endif
Expand Down
11 changes: 8 additions & 3 deletions contrib/tools/python3/Include/tracemalloc.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef Py_TRACEMALLOC_H
#define Py_TRACEMALLOC_H

#ifndef Py_LIMITED_API
#ifdef __cplusplus
extern "C" {
#endif

/* Track an allocated memory block in the tracemalloc module.
Return 0 on success, return -1 on error (failed to allocate memory to store
the trace).
Expand Down Expand Up @@ -47,7 +50,7 @@ PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetTraces(void);
PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetObjectTraceback(PyObject *obj);

/* Initialize tracemalloc */
PyAPI_FUNC(int) _PyTraceMalloc_Init(void);
PyAPI_FUNC(PyStatus) _PyTraceMalloc_Init(void);

/* Start tracemalloc */
PyAPI_FUNC(int) _PyTraceMalloc_Start(int max_nframe);
Expand All @@ -67,6 +70,8 @@ PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetTracedMemory(void);
/* Set the peak size of traced memory blocks to the current size */
PyAPI_FUNC(void) _PyTraceMalloc_ResetPeak(void);

#ifdef __cplusplus
}
#endif

#endif /* !Py_LIMITED_API */
#endif /* !Py_TRACEMALLOC_H */
1 change: 0 additions & 1 deletion contrib/tools/python3/Lib/_pydatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,6 @@ def __reduce__(self):

def _isoweek1monday(year):
# Helper to calculate the day number of the Monday starting week 1
# XXX This could be done more efficiently
THURSDAY = 3
firstday = _ymd2ord(year, 1, 1)
firstweekday = (firstday + 6) % 7 # See weekday() above
Expand Down
4 changes: 2 additions & 2 deletions contrib/tools/python3/Lib/_pydecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class DecimalException(ArithmeticError):
Used exceptions derive from this.
If an exception derives from another exception besides this (such as
Underflow (Inexact, Rounded, Subnormal) that indicates that it is only
Underflow (Inexact, Rounded, Subnormal)) that indicates that it is only
called if the others are present. This isn't actually used for
anything, though.
Expand Down Expand Up @@ -145,7 +145,7 @@ class InvalidOperation(DecimalException):
x ** (+-)INF
An operand is invalid
The result of the operation after these is a quiet positive NaN,
The result of the operation after this is a quiet positive NaN,
except when the cause is a signaling NaN, in which case the result is
also a quiet NaN, but with the original sign, and an optional
diagnostic information.
Expand Down
2 changes: 0 additions & 2 deletions contrib/tools/python3/Lib/_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,6 @@ def __init__(self, locale_time=None):
'V': r"(?P<V>5[0-3]|0[1-9]|[1-4]\d|\d)",
# W is set below by using 'U'
'y': r"(?P<y>\d\d)",
#XXX: Does 'Y' need to worry about having less or more than
# 4 digits?
'Y': r"(?P<Y>\d\d\d\d)",
'z': r"(?P<z>[+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?|(?-i:Z))",
'A': self.__seqToRE(self.locale_time.f_weekday, 'A'),
Expand Down
11 changes: 8 additions & 3 deletions contrib/tools/python3/Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,9 +1246,14 @@ def visit_JoinedStr(self, node):
fallback_to_repr = True
break
quote_types = new_quote_types
elif "\n" in value:
quote_types = [q for q in quote_types if q in _MULTI_QUOTES]
assert quote_types
else:
if "\n" in value:
quote_types = [q for q in quote_types if q in _MULTI_QUOTES]
assert quote_types

new_quote_types = [q for q in quote_types if q not in value]
if new_quote_types:
quote_types = new_quote_types
new_fstring_parts.append(value)

if fallback_to_repr:
Expand Down
11 changes: 9 additions & 2 deletions contrib/tools/python3/Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,12 @@ def create_task(self, coro, *, name=None, context=None):

tasks._set_task_name(task, name)

return task
try:
return task
finally:
# gh-128552: prevent a refcycle of
# task.exception().__traceback__->BaseEventLoop.create_task->task
del task

def set_task_factory(self, factory):
"""Set a task factory that will be used by loop.create_task().
Expand Down Expand Up @@ -1550,7 +1555,9 @@ async def create_server(
if reuse_address:
sock.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
if reuse_port:
# Since Linux 6.12.9, SO_REUSEPORT is not allowed
# on other address families than AF_INET/AF_INET6.
if reuse_port and af in (socket.AF_INET, socket.AF_INET6):
_set_reuseport(sock)
# Disable IPv4/IPv6 dual stack support (enabled by
# default on Linux) which makes a single socket
Expand Down
2 changes: 1 addition & 1 deletion contrib/tools/python3/Lib/asyncio/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class Barrier(mixins._LoopBoundMixin):
def __init__(self, parties):
"""Create a barrier, initialised to 'parties' tasks."""
if parties < 1:
raise ValueError('parties must be > 0')
raise ValueError('parties must be >= 1')

self._cond = Condition() # notify all tasks when state changes

Expand Down
1 change: 1 addition & 0 deletions contrib/tools/python3/Lib/asyncio/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def run(main, *, debug=None, loop_factory=None):
running in the same thread.
If debug is True, the event loop will be run in debug mode.
If loop_factory is passed, it is used for new event loop creation.
This function always creates a new event loop and closes it at the end.
It should be used as a main entry point for asyncio programs, and should
Expand Down
13 changes: 8 additions & 5 deletions contrib/tools/python3/Lib/asyncio/selector_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,15 +1183,19 @@ def writelines(self, list_of_data):
# If the entire buffer couldn't be written, register a write handler
if self._buffer:
self._loop._add_writer(self._sock_fd, self._write_ready)
self._maybe_pause_protocol()

def can_write_eof(self):
return True

def _call_connection_lost(self, exc):
super()._call_connection_lost(exc)
if self._empty_waiter is not None:
self._empty_waiter.set_exception(
ConnectionError("Connection is closed by peer"))
try:
super()._call_connection_lost(exc)
finally:
self._write_ready = None
if self._empty_waiter is not None:
self._empty_waiter.set_exception(
ConnectionError("Connection is closed by peer"))

def _make_empty_waiter(self):
if self._empty_waiter is not None:
Expand All @@ -1206,7 +1210,6 @@ def _reset_empty_waiter(self):

def close(self):
self._read_ready_cb = None
self._write_ready = None
super().close()


Expand Down
72 changes: 48 additions & 24 deletions contrib/tools/python3/Lib/asyncio/staggered.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,27 @@ async def staggered_race(coro_fns, delay, *, loop=None):
enum_coro_fns = enumerate(coro_fns)
winner_result = None
winner_index = None
unhandled_exceptions = []
exceptions = []
running_tasks = []
running_tasks = set()
on_completed_fut = None

def task_done(task):
running_tasks.discard(task)
if (
on_completed_fut is not None
and not on_completed_fut.done()
and not running_tasks
):
on_completed_fut.set_result(None)

if task.cancelled():
return

exc = task.exception()
if exc is None:
return
unhandled_exceptions.append(exc)

async def run_one_coro(ok_to_start, previous_failed) -> None:
# in eager tasks this waits for the calling task to append this task
Expand All @@ -91,11 +110,11 @@ async def run_one_coro(ok_to_start, previous_failed) -> None:
this_failed = locks.Event()
next_ok_to_start = locks.Event()
next_task = loop.create_task(run_one_coro(next_ok_to_start, this_failed))
running_tasks.append(next_task)
running_tasks.add(next_task)
next_task.add_done_callback(task_done)
# next_task has been appended to running_tasks so next_task is ok to
# start.
next_ok_to_start.set()
assert len(running_tasks) == this_index + 2
# Prepare place to put this coroutine's exceptions if not won
exceptions.append(None)
assert len(exceptions) == this_index + 1
Expand All @@ -120,31 +139,36 @@ async def run_one_coro(ok_to_start, previous_failed) -> None:
# up as done() == True, cancelled() == False, exception() ==
# asyncio.CancelledError. This behavior is specified in
# https://bugs.python.org/issue30048
for i, t in enumerate(running_tasks):
if i != this_index:
current_task = tasks.current_task(loop)
for t in running_tasks:
if t is not current_task:
t.cancel()

ok_to_start = locks.Event()
first_task = loop.create_task(run_one_coro(ok_to_start, None))
running_tasks.append(first_task)
# first_task has been appended to running_tasks so first_task is ok to start.
ok_to_start.set()
propagate_cancellation_error = None
try:
# Wait for a growing list of tasks to all finish: poor man's version of
# curio's TaskGroup or trio's nursery
done_count = 0
while done_count != len(running_tasks):
done, _ = await tasks.wait(running_tasks)
done_count = len(done)
ok_to_start = locks.Event()
first_task = loop.create_task(run_one_coro(ok_to_start, None))
running_tasks.add(first_task)
first_task.add_done_callback(task_done)
# first_task has been appended to running_tasks so first_task is ok to start.
ok_to_start.set()
propagate_cancellation_error = None
# Make sure no tasks are left running if we leave this function
while running_tasks:
on_completed_fut = loop.create_future()
try:
await on_completed_fut
except exceptions_mod.CancelledError as ex:
propagate_cancellation_error = ex
for task in running_tasks:
task.cancel(*ex.args)
on_completed_fut = None
if __debug__ and unhandled_exceptions:
# If run_one_coro raises an unhandled exception, it's probably a
# programming error, and I want to see it.
if __debug__:
for d in done:
if d.done() and not d.cancelled() and d.exception():
raise d.exception()
raise ExceptionGroup("staggered race failed", unhandled_exceptions)
if propagate_cancellation_error is not None:
raise propagate_cancellation_error
return winner_result, winner_index, exceptions
finally:
del exceptions
# Make sure no tasks are left running if we leave this function
for t in running_tasks:
t.cancel()
del exceptions, propagate_cancellation_error, unhandled_exceptions
Loading

0 comments on commit 0063a32

Please sign in to comment.