Skip to content

Commit 3597dd6

Browse files
authored
Merge branch 'main' into feat/core/async-with-suggesetions-128398
2 parents 34ad9a4 + e77d678 commit 3597dd6

Some content is hidden

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

45 files changed

+1682
-1054
lines changed

Doc/howto/perf_profiling.rst

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,28 @@ files in the current directory which are ELF images for all the JIT trampolines
254254
that were created by Python.
255255

256256
.. warning::
257-
Notice that when using ``--call-graph dwarf`` the ``perf`` tool will take
257+
When using ``--call-graph dwarf``, the ``perf`` tool will take
258258
snapshots of the stack of the process being profiled and save the
259-
information in the ``perf.data`` file. By default the size of the stack dump
260-
is 8192 bytes but the user can change the size by passing the size after
261-
comma like ``--call-graph dwarf,4096``. The size of the stack dump is
262-
important because if the size is too small ``perf`` will not be able to
263-
unwind the stack and the output will be incomplete. On the other hand, if
264-
the size is too big, then ``perf`` won't be able to sample the process as
265-
frequently as it would like as the overhead will be higher.
259+
information in the ``perf.data`` file. By default, the size of the stack dump
260+
is 8192 bytes, but you can change the size by passing it after
261+
a comma like ``--call-graph dwarf,16384``.
266262

263+
The size of the stack dump is important because if the size is too small
264+
``perf`` will not be able to unwind the stack and the output will be
265+
incomplete. On the other hand, if the size is too big, then ``perf`` won't
266+
be able to sample the process as frequently as it would like as the overhead
267+
will be higher.
268+
269+
The stack size is particularly important when profiling Python code compiled
270+
with low optimization levels (like ``-O0``), as these builds tend to have
271+
larger stack frames. If you are compiling Python with ``-O0`` and not seeing
272+
Python functions in your profiling output, try increasing the stack dump
273+
size to 65528 bytes (the maximum)::
274+
275+
$ perf record -F 9999 -g -k 1 --call-graph dwarf,65528 -o perf.data python -Xperf_jit my_script.py
276+
277+
Different compilation flags can significantly impact stack sizes:
278+
279+
- Builds with ``-O0`` typically have much larger stack frames than those with ``-O1`` or higher
280+
- Adding optimizations (``-O1``, ``-O2``, etc.) typically reduces stack size
281+
- Frame pointers (``-fno-omit-frame-pointer``) generally provide more reliable stack unwinding

Doc/library/dis.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,9 +1354,6 @@ iterations of the loop.
13541354
If ``STACK[-1]`` is not ``None``, increments the bytecode counter by *delta*.
13551355
``STACK[-1]`` is popped.
13561356

1357-
This opcode is a pseudo-instruction, replaced in final bytecode by
1358-
the directed versions (forward/backward).
1359-
13601357
.. versionadded:: 3.11
13611358

13621359
.. versionchanged:: 3.12
@@ -1368,9 +1365,6 @@ iterations of the loop.
13681365
If ``STACK[-1]`` is ``None``, increments the bytecode counter by *delta*.
13691366
``STACK[-1]`` is popped.
13701367

1371-
This opcode is a pseudo-instruction, replaced in final bytecode by
1372-
the directed versions (forward/backward).
1373-
13741368
.. versionadded:: 3.11
13751369

13761370
.. versionchanged:: 3.12

Doc/using/cmdline.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ source.
7373

7474
.. audit-event:: cpython.run_command command cmdoption-c
7575

76+
.. versionchanged:: next
77+
*command* is automatically dedented before execution.
78+
7679
.. option:: -m <module-name>
7780

7881
Search :data:`sys.path` for the named module and execute its contents as

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ Other language changes
474474
explicitly overridden in the subclass.
475475
(Contributed by Tomasz Pytel in :gh:`132329`.)
476476

477+
* The command line option :option:`-c` now automatically dedents its code
478+
argument before execution. The auto-dedentation behavior mirrors
479+
:func:`textwrap.dedent`.
480+
(Contributed by Jon Crall and Steven Sun in :gh:`103998`.)
481+
477482
* Improve error message when an object supporting the synchronous (resp.
478483
asynchronous) context manager protocol is entered using :keyword:`async
479484
with` (resp. :keyword:`with`) instead of :keyword:`with` (resp.

Include/internal/pycore_emscripten_trampoline.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,18 @@ _PyEM_TrampolineCall(PyCFunctionWithKeywords func,
3737
PyObject* kw);
3838

3939
#define _PyCFunction_TrampolineCall(meth, self, args) \
40-
_PyEM_TrampolineCall( \
41-
(*(PyCFunctionWithKeywords)(void(*)(void))(meth)), (self), (args), NULL)
40+
_PyEM_TrampolineCall(*_PyCFunctionWithKeywords_CAST(meth), (self), (args), NULL)
4241

4342
#define _PyCFunctionWithKeywords_TrampolineCall(meth, self, args, kw) \
4443
_PyEM_TrampolineCall((meth), (self), (args), (kw))
4544

46-
#define descr_set_trampoline_call(set, obj, value, closure) \
47-
((int)_PyEM_TrampolineCall((PyCFunctionWithKeywords)(set), (obj), (value), (PyObject*)(closure)))
45+
#define descr_set_trampoline_call(set, obj, value, closure) \
46+
((int)_PyEM_TrampolineCall(_PyCFunctionWithKeywords_CAST(set), (obj), \
47+
(value), (PyObject*)(closure)))
4848

49-
#define descr_get_trampoline_call(get, obj, closure) \
50-
_PyEM_TrampolineCall((PyCFunctionWithKeywords)(get), (obj), (PyObject*)(closure), NULL)
49+
#define descr_get_trampoline_call(get, obj, closure) \
50+
_PyEM_TrampolineCall(_PyCFunctionWithKeywords_CAST(get), (obj), \
51+
(PyObject*)(closure), NULL)
5152

5253

5354
#else // defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE)

Include/internal/pycore_unicodeobject.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ extern Py_ssize_t _PyUnicode_InsertThousandsGrouping(
247247
Py_UCS4 *maxchar,
248248
int forward);
249249

250+
/* Dedent a string.
251+
Behaviour is expected to be an exact match of `textwrap.dedent`.
252+
Return a new reference on success, NULL with exception set on error.
253+
*/
254+
extern PyObject* _PyUnicode_Dedent(PyObject *unicode);
255+
250256
/* --- Misc functions ----------------------------------------------------- */
251257

252258
extern PyObject* _PyUnicode_FormatLong(PyObject *, int, int, int);

Include/internal/pycore_uop_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/methodobject.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *,
3333
typedef PyCFunctionFast _PyCFunctionFast;
3434
typedef PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords;
3535

36-
// Cast an function to the PyCFunction type to use it with PyMethodDef.
36+
// Cast a function to the PyCFunction type to use it with PyMethodDef.
3737
//
3838
// This macro can be used to prevent compiler warnings if the first parameter
3939
// uses a different pointer type than PyObject* (ex: METH_VARARGS and METH_O
@@ -49,8 +49,17 @@ typedef PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords;
4949
// used to prevent a compiler warning. If the function has a single parameter,
5050
// it triggers an undefined behavior when Python calls it with 2 parameters
5151
// (bpo-33012).
52-
#define _PyCFunction_CAST(func) \
53-
_Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
52+
#define _PyCFunction_CAST(func) \
53+
_Py_FUNC_CAST(PyCFunction, func)
54+
// The macros below are given for semantic convenience, allowing users
55+
// to see whether a cast to suppress an undefined behavior is necessary.
56+
// Note: At runtime, the original function signature must be respected.
57+
#define _PyCFunctionFast_CAST(func) \
58+
_Py_FUNC_CAST(PyCFunctionFast, func)
59+
#define _PyCFunctionWithKeywords_CAST(func) \
60+
_Py_FUNC_CAST(PyCFunctionWithKeywords, func)
61+
#define _PyCFunctionFastWithKeywords_CAST(func) \
62+
_Py_FUNC_CAST(PyCFunctionFastWithKeywords, func)
5463

5564
PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
5665
PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);

Include/pyport.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@
3636
// Macro to use the more powerful/dangerous C-style cast even in C++.
3737
#define _Py_CAST(type, expr) ((type)(expr))
3838

39+
// Cast a function to another function type T.
40+
//
41+
// The macro first casts the function to the "void func(void)" type
42+
// to prevent compiler warnings.
43+
//
44+
// Note that using this cast only prevents the compiler from emitting
45+
// warnings, but does not prevent an undefined behavior at runtime if
46+
// the original function signature is not respected.
47+
#define _Py_FUNC_CAST(T, func) _Py_CAST(T, _Py_CAST(void(*)(void), (func)))
48+
3949
// Static inline functions should use _Py_NULL rather than using directly NULL
4050
// to prevent C++ compiler warnings. On C23 and newer and on C++11 and newer,
4151
// _Py_NULL is defined as nullptr.

Lib/ctypes/_layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def get_layout(cls, input_fields, is_struct, base):
8484
raise ValueError('_align_ must be a non-negative integer')
8585
elif align == 0:
8686
# Setting `_align_ = 0` amounts to using the default alignment
87-
align == 1
87+
align = 1
8888

8989
if base:
9090
align = max(ctypes.alignment(base), align)

0 commit comments

Comments
 (0)