Skip to content

Commit 9194bbf

Browse files
authored
Merge branch 'main' into fix-forwardrefs-dont-hash-cells
2 parents 55e07ae + c461aa9 commit 9194bbf

39 files changed

Lines changed: 617 additions & 225 deletions

.github/CODEOWNERS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ Tools/wasm/config.site-wasm32-emscripten @freakboy3742 @emmatyping
176176
Tools/wasm/emscripten @freakboy3742 @emmatyping
177177

178178
# WebAssembly (WASI)
179-
Tools/wasm/wasi-env @brettcannon @emmatyping
180-
Tools/wasm/wasi.py @brettcannon @emmatyping
181-
Tools/wasm/wasi @brettcannon @emmatyping
179+
Tools/wasm/wasi-env @brettcannon @emmatyping @savannahostrowski
180+
Tools/wasm/wasi.py @brettcannon @emmatyping @savannahostrowski
181+
Tools/wasm/wasi @brettcannon @emmatyping @savannahostrowski
182182

183183
# Windows
184184
PC/ @python/windows-team

Doc/c-api/long.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
453453
454454
Otherwise, returns the number of bytes required to store the value.
455455
If this is equal to or less than *n_bytes*, the entire value was copied.
456-
All *n_bytes* of the buffer are written: large buffers are padded with
457-
zeroes.
456+
All *n_bytes* of the buffer are written: remaining bytes filled by
457+
copies of the sign bit.
458458
459459
If the returned value is greater than *n_bytes*, the value was
460460
truncated: as many of the lowest bits of the value as could fit are written,

Doc/c-api/memory.rst

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,39 @@ The following type-oriented macros are provided for convenience. Note that
293293
294294
Same as :c:func:`PyMem_Free`.
295295
296-
In addition, the following macro sets are provided for calling the Python memory
297-
allocator directly, without involving the C API functions listed above. However,
298-
note that their use does not preserve binary compatibility across Python
299-
versions and is therefore deprecated in extension modules.
300-
301-
* ``PyMem_MALLOC(size)``
302-
* ``PyMem_NEW(type, size)``
303-
* ``PyMem_REALLOC(ptr, size)``
304-
* ``PyMem_RESIZE(ptr, type, size)``
305-
* ``PyMem_FREE(ptr)``
306-
* ``PyMem_DEL(ptr)``
296+
297+
Deprecated aliases
298+
------------------
299+
300+
These are :term:`soft deprecated` aliases to existing functions and macros.
301+
They exist solely for backwards compatibility.
302+
303+
.. list-table::
304+
:widths: auto
305+
:header-rows: 1
306+
307+
* * Deprecated alias
308+
* Corresponding function or macro
309+
* * .. c:macro:: PyMem_MALLOC(size)
310+
* :c:func:`PyMem_Malloc`
311+
* * .. c:macro:: PyMem_NEW(type, size)
312+
* :c:macro:`PyMem_New`
313+
* * .. c:macro:: PyMem_REALLOC(ptr, size)
314+
* :c:func:`PyMem_Realloc`
315+
* * .. c:macro:: PyMem_RESIZE(ptr, type, size)
316+
* :c:macro:`PyMem_Resize`
317+
* * .. c:macro:: PyMem_FREE(ptr)
318+
* :c:func:`PyMem_Free`
319+
* * .. c:macro:: PyMem_DEL(ptr)
320+
* :c:func:`PyMem_Free`
321+
322+
.. versionchanged:: 3.4
323+
324+
The macros are now aliases of the corresponding functions and macros.
325+
Previously, their behavior was the same, but their use did not necessarily
326+
preserve binary compatibility across Python versions.
327+
328+
.. deprecated:: 2.0
307329
308330
309331
.. _objectinterface:

Doc/library/select.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ linearly scanned again. :c:func:`!select` is *O*\ (*highest file descriptor*), w
478478

479479
.. versionchanged:: 3.15
480480
Accepts any real number as *timeout*, not only integer or float.
481+
If ``ppoll()`` function is available, *timeout* has a resolution
482+
of ``1`` ns (``1e-6`` ms) instead of ``1`` ms.
481483

482484

483485
.. _kqueue-objects:

Include/internal/pycore_backoff.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern "C" {
1212
#include <assert.h>
1313
#include <stdbool.h>
1414
#include "pycore_structs.h" // _Py_BackoffCounter
15-
#include "pycore_tstate.h" // _PyPolicy
15+
#include "pycore_interp_structs.h" // _PyOptimizationConfig
1616

1717
/* 16-bit countdown counters using exponential backoff.
1818
@@ -128,11 +128,11 @@ trigger_backoff_counter(void)
128128
#define JUMP_BACKWARD_INITIAL_VALUE 4000
129129
#define JUMP_BACKWARD_INITIAL_BACKOFF 6
130130
static inline _Py_BackoffCounter
131-
initial_jump_backoff_counter(_PyPolicy *policy)
131+
initial_jump_backoff_counter(_PyOptimizationConfig *opt_config)
132132
{
133133
return make_backoff_counter(
134-
policy->interp.jump_backward_initial_value,
135-
policy->interp.jump_backward_initial_backoff);
134+
opt_config->jump_backward_initial_value,
135+
opt_config->jump_backward_initial_backoff);
136136
}
137137

138138
/* Initial exit temperature.
@@ -143,11 +143,11 @@ initial_jump_backoff_counter(_PyPolicy *policy)
143143
#define SIDE_EXIT_INITIAL_BACKOFF 6
144144

145145
static inline _Py_BackoffCounter
146-
initial_temperature_backoff_counter(_PyPolicy *policy)
146+
initial_temperature_backoff_counter(_PyOptimizationConfig *opt_config)
147147
{
148148
return make_backoff_counter(
149-
policy->jit.side_exit_initial_value,
150-
policy->jit.side_exit_initial_backoff);
149+
opt_config->side_exit_initial_value,
150+
opt_config->side_exit_initial_backoff);
151151
}
152152

153153
/* Unreachable backoff counter. */

Include/internal/pycore_interp_structs.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,21 @@ typedef struct _rare_events {
398398
uint8_t func_modification;
399399
} _rare_events;
400400

401+
// Optimization configuration for the interpreter.
402+
// This groups all thresholds and optimization flags for both JIT and interpreter.
403+
typedef struct _PyOptimizationConfig {
404+
// Interpreter optimization thresholds
405+
uint16_t jump_backward_initial_value;
406+
uint16_t jump_backward_initial_backoff;
407+
408+
// JIT optimization thresholds
409+
uint16_t side_exit_initial_value;
410+
uint16_t side_exit_initial_backoff;
411+
412+
// Optimization flags
413+
bool specialization_enabled;
414+
} _PyOptimizationConfig;
415+
401416
struct
402417
Bigint {
403418
struct Bigint *next;
@@ -945,6 +960,9 @@ struct _is {
945960
PyObject *common_consts[NUM_COMMON_CONSTANTS];
946961
bool jit;
947962
bool compiling;
963+
964+
// Optimization configuration (thresholds and flags for JIT and interpreter)
965+
_PyOptimizationConfig opt_config;
948966
struct _PyExecutorObject *executor_list_head;
949967
struct _PyExecutorObject *executor_deletion_list_head;
950968
struct _PyExecutorObject *cold_executor;

Include/internal/pycore_tstate.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,6 @@ typedef struct _PyJitTracerState {
6464

6565
#endif
6666

67-
typedef struct _PyJitPolicy {
68-
uint16_t side_exit_initial_value;
69-
uint16_t side_exit_initial_backoff;
70-
} _PyJitPolicy;
71-
72-
typedef struct _PyInterpreterPolicy {
73-
uint16_t jump_backward_initial_value;
74-
uint16_t jump_backward_initial_backoff;
75-
} _PyInterpreterPolicy;
76-
77-
typedef struct _PyPolicy {
78-
_PyJitPolicy jit;
79-
_PyInterpreterPolicy interp;
80-
} _PyPolicy;
81-
8267
// Every PyThreadState is actually allocated as a _PyThreadStateImpl. The
8368
// PyThreadState fields are exposed as part of the C API, although most fields
8469
// are intended to be private. The _PyThreadStateImpl fields not exposed.
@@ -157,7 +142,6 @@ typedef struct _PyThreadStateImpl {
157142
#if _Py_TIER2
158143
_PyJitTracerState *jit_tracer_state;
159144
#endif
160-
_PyPolicy policy;
161145
} _PyThreadStateImpl;
162146

163147
#ifdef __cplusplus

Lib/_pyio.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -952,20 +952,21 @@ def write(self, b):
952952
if isinstance(b, str):
953953
raise TypeError("can't write str to binary stream")
954954
with memoryview(b) as view:
955-
n = view.nbytes # Size of any bytes-like object
956955
if self.closed:
957956
raise ValueError("write to closed file")
958-
if n == 0:
959-
return 0
960957

961-
with self._lock:
962-
pos = self._pos
963-
if pos > len(self._buffer):
964-
# Pad buffer to pos with null bytes.
965-
self._buffer.resize(pos)
966-
self._buffer[pos:pos + n] = b
967-
self._pos += n
968-
return n
958+
n = view.nbytes # Size of any bytes-like object
959+
if n == 0:
960+
return 0
961+
962+
with self._lock:
963+
pos = self._pos
964+
if pos > len(self._buffer):
965+
# Pad buffer to pos with null bytes.
966+
self._buffer.resize(pos)
967+
self._buffer[pos:pos + n] = view
968+
self._pos += n
969+
return n
969970

970971
def seek(self, pos, whence=0):
971972
if self.closed:

Lib/functools.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def _unwrap_partialmethod(func):
517517
### LRU Cache function decorator
518518
################################################################################
519519

520-
_CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"])
520+
_CacheInfo = namedtuple("CacheInfo", ("hits", "misses", "maxsize", "currsize"))
521521

522522
def _make_key(args, kwds, typed,
523523
kwd_mark = (object(),),
@@ -539,13 +539,15 @@ def _make_key(args, kwds, typed,
539539
# distinct call from f(y=2, x=1) which will be cached separately.
540540
key = args
541541
if kwds:
542+
key = list(key)
542543
key += kwd_mark
543544
for item in kwds.items():
544545
key += item
546+
key = tuple(key)
545547
if typed:
546-
key += tuple(type(v) for v in args)
548+
key += tuple([type(v) for v in args])
547549
if kwds:
548-
key += tuple(type(v) for v in kwds.values())
550+
key += tuple([type(v) for v in kwds.values()])
549551
elif len(key) == 1 and type(key[0]) in fasttypes:
550552
return key[0]
551553
return key

Lib/test/datetimetester.py

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,24 +2706,20 @@ def utcfromtimestamp(*args, **kwargs):
27062706
self.assertEqual(zero.second, 0)
27072707
self.assertEqual(zero.microsecond, 0)
27082708
one = fts(1e-6)
2709-
try:
2710-
minus_one = fts(-1e-6)
2711-
except OSError:
2712-
# localtime(-1) and gmtime(-1) is not supported on Windows
2713-
pass
2714-
else:
2715-
self.assertEqual(minus_one.second, 59)
2716-
self.assertEqual(minus_one.microsecond, 999999)
2717-
2718-
t = fts(-1e-8)
2719-
self.assertEqual(t, zero)
2720-
t = fts(-9e-7)
2721-
self.assertEqual(t, minus_one)
2722-
t = fts(-1e-7)
2723-
self.assertEqual(t, zero)
2724-
t = fts(-1/2**7)
2725-
self.assertEqual(t.second, 59)
2726-
self.assertEqual(t.microsecond, 992188)
2709+
minus_one = fts(-1e-6)
2710+
2711+
self.assertEqual(minus_one.second, 59)
2712+
self.assertEqual(minus_one.microsecond, 999999)
2713+
2714+
t = fts(-1e-8)
2715+
self.assertEqual(t, zero)
2716+
t = fts(-9e-7)
2717+
self.assertEqual(t, minus_one)
2718+
t = fts(-1e-7)
2719+
self.assertEqual(t, zero)
2720+
t = fts(-1/2**7)
2721+
self.assertEqual(t.second, 59)
2722+
self.assertEqual(t.microsecond, 992188)
27272723

27282724
t = fts(1e-7)
27292725
self.assertEqual(t, zero)
@@ -2752,22 +2748,18 @@ def utcfromtimestamp(*args, **kwargs):
27522748
self.assertEqual(zero.second, 0)
27532749
self.assertEqual(zero.microsecond, 0)
27542750
one = fts(D('0.000_001'))
2755-
try:
2756-
minus_one = fts(D('-0.000_001'))
2757-
except OSError:
2758-
# localtime(-1) and gmtime(-1) is not supported on Windows
2759-
pass
2760-
else:
2761-
self.assertEqual(minus_one.second, 59)
2762-
self.assertEqual(minus_one.microsecond, 999_999)
2751+
minus_one = fts(D('-0.000_001'))
2752+
2753+
self.assertEqual(minus_one.second, 59)
2754+
self.assertEqual(minus_one.microsecond, 999_999)
27632755

2764-
t = fts(D('-0.000_000_1'))
2765-
self.assertEqual(t, zero)
2766-
t = fts(D('-0.000_000_9'))
2767-
self.assertEqual(t, minus_one)
2768-
t = fts(D(-1)/2**7)
2769-
self.assertEqual(t.second, 59)
2770-
self.assertEqual(t.microsecond, 992188)
2756+
t = fts(D('-0.000_000_1'))
2757+
self.assertEqual(t, zero)
2758+
t = fts(D('-0.000_000_9'))
2759+
self.assertEqual(t, minus_one)
2760+
t = fts(D(-1)/2**7)
2761+
self.assertEqual(t.second, 59)
2762+
self.assertEqual(t.microsecond, 992188)
27712763

27722764
t = fts(D('0.000_000_1'))
27732765
self.assertEqual(t, zero)
@@ -2803,22 +2795,18 @@ def utcfromtimestamp(*args, **kwargs):
28032795
self.assertEqual(zero.second, 0)
28042796
self.assertEqual(zero.microsecond, 0)
28052797
one = fts(F(1, 1_000_000))
2806-
try:
2807-
minus_one = fts(F(-1, 1_000_000))
2808-
except OSError:
2809-
# localtime(-1) and gmtime(-1) is not supported on Windows
2810-
pass
2811-
else:
2812-
self.assertEqual(minus_one.second, 59)
2813-
self.assertEqual(minus_one.microsecond, 999_999)
2798+
minus_one = fts(F(-1, 1_000_000))
28142799

2815-
t = fts(F(-1, 10_000_000))
2816-
self.assertEqual(t, zero)
2817-
t = fts(F(-9, 10_000_000))
2818-
self.assertEqual(t, minus_one)
2819-
t = fts(F(-1, 2**7))
2820-
self.assertEqual(t.second, 59)
2821-
self.assertEqual(t.microsecond, 992188)
2800+
self.assertEqual(minus_one.second, 59)
2801+
self.assertEqual(minus_one.microsecond, 999_999)
2802+
2803+
t = fts(F(-1, 10_000_000))
2804+
self.assertEqual(t, zero)
2805+
t = fts(F(-9, 10_000_000))
2806+
self.assertEqual(t, minus_one)
2807+
t = fts(F(-1, 2**7))
2808+
self.assertEqual(t.second, 59)
2809+
self.assertEqual(t.microsecond, 992188)
28222810

28232811
t = fts(F(1, 10_000_000))
28242812
self.assertEqual(t, zero)
@@ -2860,6 +2848,7 @@ def test_timestamp_limits(self):
28602848
# If that assumption changes, this value can change as well
28612849
self.assertEqual(max_ts, 253402300799.0)
28622850

2851+
@unittest.skipIf(sys.platform == "win32", "Windows doesn't support min timestamp")
28632852
def test_fromtimestamp_limits(self):
28642853
try:
28652854
self.theclass.fromtimestamp(-2**32 - 1)
@@ -2899,6 +2888,7 @@ def test_fromtimestamp_limits(self):
28992888
# OverflowError, especially on 32-bit platforms.
29002889
self.theclass.fromtimestamp(ts)
29012890

2891+
@unittest.skipIf(sys.platform == "win32", "Windows doesn't support min timestamp")
29022892
def test_utcfromtimestamp_limits(self):
29032893
with self.assertWarns(DeprecationWarning):
29042894
try:
@@ -2960,13 +2950,11 @@ def test_insane_utcfromtimestamp(self):
29602950
self.assertRaises(OverflowError, self.theclass.utcfromtimestamp,
29612951
insane)
29622952

2963-
@unittest.skipIf(sys.platform == "win32", "Windows doesn't accept negative timestamps")
29642953
def test_negative_float_fromtimestamp(self):
29652954
# The result is tz-dependent; at least test that this doesn't
29662955
# fail (like it did before bug 1646728 was fixed).
29672956
self.theclass.fromtimestamp(-1.05)
29682957

2969-
@unittest.skipIf(sys.platform == "win32", "Windows doesn't accept negative timestamps")
29702958
def test_negative_float_utcfromtimestamp(self):
29712959
with self.assertWarns(DeprecationWarning):
29722960
d = self.theclass.utcfromtimestamp(-1.05)

0 commit comments

Comments
 (0)