Skip to content

Commit f1ce753

Browse files
committed
Merge branch 'main' into small_int_immortal_v2
2 parents e232ca4 + 5fc6bb2 commit f1ce753

32 files changed

+299
-233
lines changed

Doc/c-api/object.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ Object Protocol
509509
iterated.
510510
511511
512+
.. c:function:: PyObject* PyObject_SelfIter(PyObject *obj)
513+
514+
This is equivalent to the Python ``__iter__(self): return self`` method.
515+
It is intended for :term:`iterator` types, to be used in the :c:member:`PyTypeObject.tp_iter` slot.
516+
517+
512518
.. c:function:: PyObject* PyObject_GetAIter(PyObject *o)
513519
514520
This is the equivalent to the Python expression ``aiter(o)``. Takes an

Doc/data/refcounts.dat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,9 @@ PyObject_RichCompareBool:PyObject*:o1:0:
18491849
PyObject_RichCompareBool:PyObject*:o2:0:
18501850
PyObject_RichCompareBool:int:opid::
18511851

1852+
PyObject_SelfIter:PyObject*::+1:
1853+
PyObject_SelfIter:PyObject*:obj:0:
1854+
18521855
PyObject_SetAttr:int:::
18531856
PyObject_SetAttr:PyObject*:o:0:
18541857
PyObject_SetAttr:PyObject*:attr_name:0:

Doc/library/http.cookies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Cookie Objects
9898
.. method:: BaseCookie.output(attrs=None, header='Set-Cookie:', sep='\r\n')
9999

100100
Return a string representation suitable to be sent as HTTP headers. *attrs* and
101-
*header* are sent to each :class:`Morsel`'s :meth:`output` method. *sep* is used
101+
*header* are sent to each :class:`Morsel`'s :meth:`~Morsel.output` method. *sep* is used
102102
to join the headers together, and is by default the combination ``'\r\n'``
103103
(CRLF).
104104

Doc/library/itertools.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ The following recipes have a more mathematical flavor:
10151015
.. testcode::
10161016

10171017
def powerset(iterable):
1018-
"powerset([1,2,3]) → () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
1018+
# powerset([1,2,3]) → () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)
10191019
s = list(iterable)
10201020
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
10211021

@@ -1104,11 +1104,6 @@ The following recipes have a more mathematical flavor:
11041104
data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p)))
11051105
yield from iter_index(data, 1, start=3)
11061106

1107-
def is_prime(n):
1108-
"Return True if n is prime."
1109-
# is_prime(1_000_000_000_000_403) → True
1110-
return n > 1 and all(n % p for p in sieve(math.isqrt(n) + 1))
1111-
11121107
def factor(n):
11131108
"Prime factors of n."
11141109
# factor(99) → 3 3 11
@@ -1123,6 +1118,11 @@ The following recipes have a more mathematical flavor:
11231118
if n > 1:
11241119
yield n
11251120

1121+
def is_prime(n):
1122+
"Return True if n is prime."
1123+
# is_prime(1_000_000_000_000_403) → True
1124+
return n > 1 and next(factor(n)) == n
1125+
11261126
def totient(n):
11271127
"Count of natural numbers up to n that are coprime to n."
11281128
# https://mathworld.wolfram.com/TotientFunction.html

Doc/library/traceback.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Module-Level Functions
274274
:class:`!TracebackException` objects are created from actual exceptions to
275275
capture data for later printing. They offer a more lightweight method of
276276
storing this information by avoiding holding references to
277-
:ref:`traceback<traceback-objects>` and :ref:`frame<frame-objects>` objects
277+
:ref:`traceback<traceback-objects>` and :ref:`frame<frame-objects>` objects.
278278
In addition, they expose more options to configure the output compared to
279279
the module-level functions described above.
280280

Include/internal/pycore_freelist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static inline int
5151
_PyFreeList_Push(struct _Py_freelist *fl, void *obj, Py_ssize_t maxsize)
5252
{
5353
if (fl->size < maxsize && fl->size >= 0) {
54-
*(void **)obj = fl->freelist;
54+
FT_ATOMIC_STORE_PTR_RELAXED(*(void **)obj, fl->freelist);
5555
fl->freelist = obj;
5656
fl->size++;
5757
OBJECT_STAT_INC(to_freelist);

Include/internal/pycore_freelist_state.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern "C" {
1414
# define Py_dicts_MAXFREELIST 80
1515
# define Py_dictkeys_MAXFREELIST 80
1616
# define Py_floats_MAXFREELIST 100
17+
# define Py_ints_MAXFREELIST 100
1718
# define Py_slices_MAXFREELIST 1
1819
# define Py_contexts_MAXFREELIST 255
1920
# define Py_async_gens_MAXFREELIST 80
@@ -35,6 +36,7 @@ struct _Py_freelist {
3536

3637
struct _Py_freelists {
3738
struct _Py_freelist floats;
39+
struct _Py_freelist ints;
3840
struct _Py_freelist tuples[PyTuple_MAXSAVESIZE];
3941
struct _Py_freelist lists;
4042
struct _Py_freelist dicts;

Include/internal/pycore_long.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ extern void _PyLong_FiniTypes(PyInterpreterState *interp);
5555

5656
/* other API */
5757

58+
PyAPI_FUNC(void) _PyLong_ExactDealloc(PyObject *self);
59+
5860
#define _PyLong_SMALL_INTS _Py_SINGLETON(small_ints)
5961

6062
// _PyLong_GetZero() and _PyLong_GetOne() must always be available

Include/internal/pycore_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ PyAPI_FUNC(void) _Py_SetImmortalUntracked(PyObject *op);
184184

185185
// Makes an immortal object mortal again with the specified refcnt. Should only
186186
// be used during runtime finalization.
187-
static inline void _Py_SetMortal(PyObject *op, Py_ssize_t refcnt)
187+
static inline void _Py_SetMortal(PyObject *op, short refcnt)
188188
{
189189
if (op) {
190190
assert(_Py_IsImmortal(op));

Include/refcount.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
377377
#if SIZEOF_VOID_P > 4
378378
/* If an object has been freed, it will have a negative full refcnt
379379
* If it has not it been freed, will have a very large refcnt */
380-
if (op->ob_refcnt_full <= 0 || op->ob_refcnt > (UINT32_MAX - (1<<20))) {
380+
if (op->ob_refcnt_full <= 0 || op->ob_refcnt > (((PY_UINT32_T)-1) - (1<<20))) {
381381
#else
382382
if (op->ob_refcnt <= 0) {
383383
#endif

0 commit comments

Comments
 (0)