Skip to content

Commit fce79a6

Browse files
Merge remote-tracking branch 'upstream/main' into pure
2 parents 01be0c6 + 394d798 commit fce79a6

File tree

6 files changed

+49
-10
lines changed

6 files changed

+49
-10
lines changed

Doc/library/math.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ Floating point manipulation functions
387387
.. function:: issubnormal(x)
388388

389389
Return ``True`` if *x* is a subnormal number, that is a finite
390-
nonzero number with a magnitude smaller than the smallest positive normal
391-
number, see :data:`sys.float_info.min`. Return ``False`` otherwise.
390+
nonzero number with a magnitude smaller than :data:`sys.float_info.min`.
391+
Return ``False`` otherwise.
392392

393393
.. versionadded:: next
394394

Doc/library/stdtypes.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,14 @@ expression support in the :mod:`re` module).
18411841
unless an encoding error actually occurs,
18421842
:ref:`devmode` is enabled
18431843
or a :ref:`debug build <debug-build>` is used.
1844+
For example::
1845+
1846+
>>> encoded_str_to_bytes = 'Python'.encode()
1847+
>>> type(encoded_str_to_bytes)
1848+
<class 'bytes'>
1849+
>>> encoded_str_to_bytes
1850+
b'Python'
1851+
18441852

18451853
.. versionchanged:: 3.1
18461854
Added support for keyword arguments.
@@ -1855,7 +1863,19 @@ expression support in the :mod:`re` module).
18551863
Return ``True`` if the string ends with the specified *suffix*, otherwise return
18561864
``False``. *suffix* can also be a tuple of suffixes to look for. With optional
18571865
*start*, test beginning at that position. With optional *end*, stop comparing
1858-
at that position.
1866+
at that position. Using *start* and *end* is equivalent to
1867+
``str[start:end].endswith(suffix)``. For example::
1868+
1869+
>>> 'Python'.endswith('on')
1870+
True
1871+
>>> 'a tuple of suffixes'.endswith(('at', 'in'))
1872+
False
1873+
>>> 'a tuple of suffixes'.endswith(('at', 'es'))
1874+
True
1875+
>>> 'Python is amazing'.endswith('is', 0, 9)
1876+
True
1877+
1878+
See also :meth:`startswith` and :meth:`removesuffix`.
18591879

18601880

18611881
.. method:: str.expandtabs(tabsize=8)

Doc/library/uuid.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ The :mod:`uuid` module defines the following functions:
257257
non-specified arguments are substituted for a pseudo-random integer of
258258
appropriate size.
259259

260-
By default, *a*, *b* and *c* are generated by a non-cryptographically
260+
By default, *a*, *b* and *c* are not generated by a cryptographically
261261
secure pseudo-random number generator (CSPRNG). Use :func:`uuid4` when
262262
a UUID needs to be used in a security-sensitive context.
263263

Include/internal/pycore_freelist_state.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern "C" {
1616
# define Py_dicts_MAXFREELIST 80
1717
# define Py_dictkeys_MAXFREELIST 80
1818
# define Py_floats_MAXFREELIST 100
19+
# define Py_complexes_MAXFREELIST 100
1920
# define Py_ints_MAXFREELIST 100
2021
# define Py_slices_MAXFREELIST 1
2122
# define Py_ranges_MAXFREELIST 6
@@ -43,6 +44,7 @@ struct _Py_freelist {
4344

4445
struct _Py_freelists {
4546
struct _Py_freelist floats;
47+
struct _Py_freelist complexes;
4648
struct _Py_freelist ints;
4749
struct _Py_freelist tuples[PyTuple_MAXSAVESIZE];
4850
struct _Py_freelist lists;

Objects/complexobject.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/* Complex object implementation */
32

43
/* Borrows heavily from floatobject.c */
@@ -9,6 +8,7 @@
98
#include "pycore_call.h" // _PyObject_CallNoArgs()
109
#include "pycore_complexobject.h" // _PyComplex_FormatAdvancedWriter()
1110
#include "pycore_floatobject.h" // _Py_convert_int_to_double()
11+
#include "pycore_freelist.h" // _Py_FREELIST_FREE(), _Py_FREELIST_POP()
1212
#include "pycore_long.h" // _PyLong_GetZero()
1313
#include "pycore_object.h" // _PyObject_Init()
1414
#include "pycore_pymath.h" // _Py_ADJUST_ERANGE2()
@@ -410,16 +410,32 @@ complex_subtype_from_c_complex(PyTypeObject *type, Py_complex cval)
410410
PyObject *
411411
PyComplex_FromCComplex(Py_complex cval)
412412
{
413-
/* Inline PyObject_New */
414-
PyComplexObject *op = PyObject_Malloc(sizeof(PyComplexObject));
413+
PyComplexObject *op = _Py_FREELIST_POP(PyComplexObject, complexes);
414+
415415
if (op == NULL) {
416-
return PyErr_NoMemory();
416+
/* Inline PyObject_New */
417+
op = PyObject_Malloc(sizeof(PyComplexObject));
418+
if (op == NULL) {
419+
return PyErr_NoMemory();
420+
}
421+
_PyObject_Init((PyObject*)op, &PyComplex_Type);
417422
}
418-
_PyObject_Init((PyObject*)op, &PyComplex_Type);
419423
op->cval = cval;
420424
return (PyObject *) op;
421425
}
422426

427+
static void
428+
complex_dealloc(PyObject *op)
429+
{
430+
assert(PyComplex_Check(op));
431+
if (PyComplex_CheckExact(op)) {
432+
_Py_FREELIST_FREE(complexes, op, PyObject_Free);
433+
}
434+
else {
435+
Py_TYPE(op)->tp_free(op);
436+
}
437+
}
438+
423439
static PyObject *
424440
complex_subtype_from_doubles(PyTypeObject *type, double real, double imag)
425441
{
@@ -1383,7 +1399,7 @@ PyTypeObject PyComplex_Type = {
13831399
"complex",
13841400
sizeof(PyComplexObject),
13851401
0,
1386-
0, /* tp_dealloc */
1402+
complex_dealloc, /* tp_dealloc */
13871403
0, /* tp_vectorcall_offset */
13881404
0, /* tp_getattr */
13891405
0, /* tp_setattr */

Objects/object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ _PyObject_ClearFreeLists(struct _Py_freelists *freelists, int is_finalization)
925925
// In the free-threaded build, freelists are per-PyThreadState and cleared in PyThreadState_Clear()
926926
// In the default build, freelists are per-interpreter and cleared in finalize_interp_types()
927927
clear_freelist(&freelists->floats, is_finalization, free_object);
928+
clear_freelist(&freelists->complexes, is_finalization, free_object);
928929
for (Py_ssize_t i = 0; i < PyTuple_MAXSAVESIZE; i++) {
929930
clear_freelist(&freelists->tuples[i], is_finalization, free_object);
930931
}

0 commit comments

Comments
 (0)