Skip to content

Commit 40097b8

Browse files
authored
Merge branch 'python:main' into check-signals-without-gil
2 parents c021340 + 9434709 commit 40097b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1271
-237
lines changed

Doc/c-api/object.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,21 @@ Object Protocol
737737
caller must hold a :term:`strong reference` to *obj* when calling this.
738738
739739
.. versionadded:: 3.14
740+
741+
.. c:function:: int PyUnstable_Object_IsUniquelyReferenced(PyObject *op)
742+
743+
Determine if *op* only has one reference.
744+
745+
On GIL-enabled builds, this function is equivalent to
746+
:c:expr:`Py_REFCNT(op) == 1`.
747+
748+
On a :term:`free threaded <free threading>` build, this checks if *op*'s
749+
:term:`reference count` is equal to one and additionally checks if *op*
750+
is only used by this thread. :c:expr:`Py_REFCNT(op) == 1` is **not**
751+
thread-safe on free threaded builds; prefer this function.
752+
753+
The caller must hold an :term:`attached thread state`, despite the fact
754+
that this function doesn't call into the Python interpreter. This function
755+
cannot fail.
756+
757+
.. versionadded:: 3.14

Doc/c-api/refcounting.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ of Python objects.
2323
2424
Use the :c:func:`Py_SET_REFCNT()` function to set an object reference count.
2525
26-
See also the function :c:func:`PyUnstable_Object_IsUniqueReferencedTemporary()`.
26+
.. note::
27+
28+
On :term:`free threaded <free threading>` builds of Python, returning 1
29+
isn't sufficient to determine if it's safe to treat *o* as having no
30+
access by other threads. Use :c:func:`PyUnstable_Object_IsUniquelyReferenced`
31+
for that instead.
32+
33+
See also the function :c:func:`PyUnstable_Object_IsUniqueReferencedTemporary()`.
2734
2835
.. versionchanged:: 3.10
2936
:c:func:`Py_REFCNT()` is changed to the inline static function.

Doc/whatsnew/3.14.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,11 @@ pdb
14431443
fill in a 4-space indentation now, instead of inserting a ``\t`` character.
14441444
(Contributed by Tian Gao in :gh:`130471`.)
14451445

1446+
* Auto-indent is introduced in :mod:`pdb` multi-line input. It will either
1447+
keep the indentation of the last line or insert a 4-space indentation when
1448+
it detects a new code block.
1449+
(Contributed by Tian Gao in :gh:`133350`.)
1450+
14461451
* ``$_asynctask`` is added to access the current asyncio task if applicable.
14471452
(Contributed by Tian Gao in :gh:`124367`.)
14481453

@@ -2464,6 +2469,10 @@ New features
24642469
be used in some cases as a replacement for checking if :c:func:`Py_REFCNT`
24652470
is ``1`` for Python objects passed as arguments to C API functions.
24662471

2472+
* Add :c:func:`PyUnstable_Object_IsUniquelyReferenced` as a replacement for
2473+
``Py_REFCNT(op) == 1`` on :term:`free threaded <free threading>` builds.
2474+
(Contributed by Peter Bierma in :gh:`133140`.)
2475+
24672476

24682477
Limited C API changes
24692478
---------------------

Include/cpython/funcobject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ static inline PyObject* PyFunction_GET_GLOBALS(PyObject *func) {
9797
}
9898
#define PyFunction_GET_GLOBALS(func) PyFunction_GET_GLOBALS(_PyObject_CAST(func))
9999

100+
static inline PyObject* PyFunction_GET_BUILTINS(PyObject *func) {
101+
return _PyFunction_CAST(func)->func_builtins;
102+
}
103+
#define PyFunction_GET_BUILTINS(func) PyFunction_GET_BUILTINS(_PyObject_CAST(func))
104+
100105
static inline PyObject* PyFunction_GET_MODULE(PyObject *func) {
101106
return _PyFunction_CAST(func)->func_module;
102107
}

Include/cpython/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,5 @@ PyAPI_FUNC(int) PyUnstable_IsImmortal(PyObject *);
501501
// before calling this function in order to avoid spurious failures.
502502
PyAPI_FUNC(int) PyUnstable_TryIncRef(PyObject *);
503503
PyAPI_FUNC(void) PyUnstable_EnableTryIncRef(PyObject *);
504+
505+
PyAPI_FUNC(int) PyUnstable_Object_IsUniquelyReferenced(PyObject *);

Include/internal/pycore_code.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,57 @@ extern int _Py_ClearUnusedTLBC(PyInterpreterState *interp);
570570
#endif
571571

572572

573+
typedef struct {
574+
int total;
575+
struct co_locals_counts {
576+
int total;
577+
struct {
578+
int total;
579+
int numposonly;
580+
int numposorkw;
581+
int numkwonly;
582+
int varargs;
583+
int varkwargs;
584+
} args;
585+
int numpure;
586+
struct {
587+
int total;
588+
// numargs does not contribute to locals.total.
589+
int numargs;
590+
int numothers;
591+
} cells;
592+
struct {
593+
int total;
594+
int numpure;
595+
int numcells;
596+
} hidden;
597+
} locals;
598+
int numfree; // nonlocal
599+
struct co_unbound_counts {
600+
int total;
601+
struct {
602+
int total;
603+
int numglobal;
604+
int numbuiltin;
605+
int numunknown;
606+
} globals;
607+
int numattrs;
608+
int numunknown;
609+
} unbound;
610+
} _PyCode_var_counts_t;
611+
612+
PyAPI_FUNC(void) _PyCode_GetVarCounts(
613+
PyCodeObject *,
614+
_PyCode_var_counts_t *);
615+
PyAPI_FUNC(int) _PyCode_SetUnboundVarCounts(
616+
PyThreadState *,
617+
PyCodeObject *,
618+
_PyCode_var_counts_t *,
619+
PyObject *globalnames,
620+
PyObject *attrnames,
621+
PyObject *globalsns,
622+
PyObject *builtinsns);
623+
573624
PyAPI_FUNC(int) _PyCode_ReturnsOnlyNone(PyCodeObject *);
574625

575626

Lib/ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ def main(args=None):
630630
import argparse
631631
import sys
632632

633-
parser = argparse.ArgumentParser()
633+
parser = argparse.ArgumentParser(color=True)
634634
parser.add_argument('infile', nargs='?', default='-',
635635
help='the file to parse; defaults to stdin')
636636
parser.add_argument('-m', '--mode', default='exec',

Lib/calendar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ def timegm(tuple):
810810

811811
def main(args=None):
812812
import argparse
813-
parser = argparse.ArgumentParser()
813+
parser = argparse.ArgumentParser(color=True)
814814
textgroup = parser.add_argument_group('text only arguments')
815815
htmlgroup = parser.add_argument_group('html only arguments')
816816
textgroup.add_argument(

Lib/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def interact(banner=None, readfunc=None, local=None, exitmsg=None, local_exit=Fa
385385
if __name__ == "__main__":
386386
import argparse
387387

388-
parser = argparse.ArgumentParser()
388+
parser = argparse.ArgumentParser(color=True)
389389
parser.add_argument('-q', action='store_true',
390390
help="don't print version and copyright messages")
391391
args = parser.parse_args()

Lib/compileall.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ def main():
317317
import argparse
318318

319319
parser = argparse.ArgumentParser(
320-
description='Utilities to support installing Python libraries.')
320+
description='Utilities to support installing Python libraries.',
321+
color=True,
322+
)
321323
parser.add_argument('-l', action='store_const', const=0,
322324
default=None, dest='maxlevels',
323325
help="don't recurse into subdirectories")

0 commit comments

Comments
 (0)