Skip to content

Commit 65ddd2c

Browse files
committed
Merge branch 'master' into pep757-sapi/143869
2 parents c7262fd + 780e969 commit 65ddd2c

32 files changed

Lines changed: 690 additions & 382 deletions

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_flowgraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int _PyCfg_OptimizeCodeUnit(struct _PyCfgBuilder *g, PyObject *consts, PyObject
2727
struct _PyCfgBuilder* _PyCfg_FromInstructionSequence(_PyInstructionSequence *seq);
2828
int _PyCfg_ToInstructionSequence(struct _PyCfgBuilder *g, _PyInstructionSequence *seq);
2929
int _PyCfg_OptimizedCfgToInstructionSequence(struct _PyCfgBuilder *g, _PyCompile_CodeUnitMetadata *umd,
30-
int code_flags, int *stackdepth, int *nlocalsplus,
30+
int *stackdepth, int *nlocalsplus,
3131
_PyInstructionSequence *seq);
3232

3333
PyCodeObject *

Include/internal/pycore_instruction_sequence.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ int _PyInstructionSequence_SetAnnotationsCode(_PyInstructionSequence *seq,
7373
_PyInstructionSequence *annotations);
7474
int _PyInstructionSequence_AddNested(_PyInstructionSequence *seq, _PyInstructionSequence *nested);
7575
void PyInstructionSequence_Fini(_PyInstructionSequence *seq);
76+
_PyInstruction _PyInstructionSequence_GetInstruction(_PyInstructionSequence *seq, int pos);
7677

7778
extern PyTypeObject _PyInstructionSequence_Type;
7879
#define _PyInstructionSequence_Check(v) Py_IS_TYPE((v), &_PyInstructionSequence_Type)

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ Known values:
290290
Python 3.15a4 3657 (Add BINARY_OP_SUBSCR_USTR_INT)
291291
Python 3.15a4 3658 (Optimize bytecode for list/set called on genexp)
292292
Python 3.15a4 3659 (Add CALL_FUNCTION_EX specialization)
293+
Python 3.15a4 3660 (Change generator preamble code)
293294
294295
295296
Python 3.16 will start with 3700
@@ -303,7 +304,7 @@ PC/launcher.c must also be updated.
303304
304305
*/
305306

306-
#define PYC_MAGIC_NUMBER 3659
307+
#define PYC_MAGIC_NUMBER 3660
307308
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
308309
(little-endian) and then appending b'\r\n'. */
309310
#define PYC_MAGIC_NUMBER_TOKEN \

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/test/test_compile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ def return_genexp():
12981298
x
12991299
in
13001300
y)
1301-
genexp_lines = [0, 4, 2, 0, 4]
1301+
genexp_lines = [4, 0, 4, 2, 0, 4]
13021302

13031303
genexp_code = return_genexp.__code__.co_consts[0]
13041304
code_lines = self.get_code_lines(genexp_code)

Lib/test/test_dis.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,11 @@ def foo(x):
875875
Disassembly of <code object <genexpr> at 0x..., file "%s", line %d>:
876876
-- COPY_FREE_VARS 1
877877
878-
%4d RETURN_GENERATOR
878+
%4d LOAD_FAST 0 (.0)
879+
GET_ITER
880+
RETURN_GENERATOR
879881
POP_TOP
880882
L1: RESUME 0
881-
LOAD_FAST 0 (.0)
882-
GET_ITER
883883
L2: FOR_ITER 14 (to L3)
884884
STORE_FAST 1 (z)
885885
LOAD_DEREF 2 (x)
@@ -897,7 +897,7 @@ def foo(x):
897897
-- L4: CALL_INTRINSIC_1 3 (INTRINSIC_STOPITERATION_ERROR)
898898
RERAISE 1
899899
ExceptionTable:
900-
L1 to L4 -> L4 [0] lasti
900+
L1 to L4 -> L4 [2] lasti
901901
""" % (dis_nested_1,
902902
__file__,
903903
_h.__code__.co_firstlineno + 3,

Lib/test/test_generators.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -357,21 +357,25 @@ def gen(it):
357357
yield x
358358
return gen(range(10))
359359

360-
def process_tests(self, get_generator):
361-
for obj in self.iterables:
362-
g_obj = get_generator(obj)
363-
with self.subTest(g_obj=g_obj, obj=obj):
364-
self.assertListEqual(list(g_obj), list(obj))
360+
def process_tests(self, get_generator, changes_iterable):
361+
if changes_iterable:
362+
for obj in self.iterables:
363+
g_obj = get_generator(obj)
364+
with self.subTest(g_obj=g_obj, obj=obj):
365+
self.assertListEqual(list(g_obj), list(obj))
365366

366-
g_iter = get_generator(iter(obj))
367-
with self.subTest(g_iter=g_iter, obj=obj):
368-
self.assertListEqual(list(g_iter), list(obj))
367+
g_iter = get_generator(iter(obj))
368+
with self.subTest(g_iter=g_iter, obj=obj):
369+
self.assertListEqual(list(g_iter), list(obj))
369370

370371
err_regex = "'.*' object is not iterable"
371372
for obj in self.non_iterables:
372373
g_obj = get_generator(obj)
373374
with self.subTest(g_obj=g_obj):
374-
self.assertRaisesRegex(TypeError, err_regex, list, g_obj)
375+
if changes_iterable:
376+
self.assertRaisesRegex(TypeError, err_regex, list, g_obj)
377+
else:
378+
next(g_obj)
375379

376380
def test_modify_f_locals(self):
377381
def modify_f_locals(g, local, obj):
@@ -384,22 +388,22 @@ def get_generator_genexpr(obj):
384388
def get_generator_genfunc(obj):
385389
return modify_f_locals(self.genfunc(), 'it', obj)
386390

387-
self.process_tests(get_generator_genexpr)
388-
self.process_tests(get_generator_genfunc)
391+
self.process_tests(get_generator_genexpr, False)
392+
self.process_tests(get_generator_genfunc, True)
389393

390394
def test_new_gen_from_gi_code(self):
391395
def new_gen_from_gi_code(g, obj):
392396
generator_func = types.FunctionType(g.gi_code, {})
393397
return generator_func(obj)
394398

395-
def get_generator_genexpr(obj):
396-
return new_gen_from_gi_code(self.genexpr(), obj)
399+
for obj in self.non_iterables:
400+
with self.assertRaises(TypeError):
401+
new_gen_from_gi_code(self.genexpr(), obj)
397402

398403
def get_generator_genfunc(obj):
399404
return new_gen_from_gi_code(self.genfunc(), obj)
400405

401-
self.process_tests(get_generator_genexpr)
402-
self.process_tests(get_generator_genfunc)
406+
self.process_tests(get_generator_genfunc, True)
403407

404408

405409
class ExceptionTest(unittest.TestCase):

Lib/test/test_inspect/test_inspect.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6266,6 +6266,10 @@ def test_stat_module_has_signatures(self):
62666266
import stat
62676267
self._test_module_has_signatures(stat)
62686268

6269+
def test_struct_module_has_signatures(self):
6270+
import struct
6271+
self._test_module_has_signatures(struct)
6272+
62696273
def test_string_module_has_signatures(self):
62706274
import string
62716275
self._test_module_has_signatures(string)

0 commit comments

Comments
 (0)