Skip to content

Commit

Permalink
Merge branch 'main' into pythongh-117657-seq-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoV committed Apr 17, 2024
2 parents a9907b8 + b6c62c7 commit 778de8e
Show file tree
Hide file tree
Showing 69 changed files with 1,552 additions and 547 deletions.
9 changes: 5 additions & 4 deletions Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,14 @@ For convenience, some of these functions will always return a
.. c:function:: PyObject* PyErr_SetFromWindowsErr(int ierr)
This is a convenience function to raise :exc:`WindowsError`. If called with
This is a convenience function to raise :exc:`OSError`. If called with
*ierr* of ``0``, the error code returned by a call to :c:func:`!GetLastError`
is used instead. It calls the Win32 function :c:func:`!FormatMessage` to retrieve
the Windows description of error code given by *ierr* or :c:func:`!GetLastError`,
then it constructs a tuple object whose first item is the *ierr* value and whose
second item is the corresponding error message (gotten from
:c:func:`!FormatMessage`), and then calls ``PyErr_SetObject(PyExc_WindowsError,
then it constructs a :exc:`OSError` object with the :attr:`~OSError.winerror`
attribute set to the error code, the :attr:`~OSError.strerror` attribute
set to the corresponding error message (gotten from
:c:func:`!FormatMessage`), and then calls ``PyErr_SetObject(PyExc_OSError,
object)``. This function always returns ``NULL``.
.. availability:: Windows.
Expand Down
30 changes: 29 additions & 1 deletion Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The following functions can be safely called before Python is initialized:
:c:func:`Py_Initialize`: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPath`,
:c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`,
:c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`,
and :c:func:`Py_GetProgramName`.
:c:func:`Py_GetProgramName` and :c:func:`PyEval_InitThreads`.


.. _global-conf-vars:
Expand Down Expand Up @@ -326,6 +326,7 @@ Initializing and finalizing the interpreter
.. c:function:: void Py_Initialize()
.. index::
single: PyEval_InitThreads()
single: modules (in module sys)
single: path (in module sys)
pair: module; builtins
Expand Down Expand Up @@ -841,6 +842,33 @@ code, or when embedding the Python interpreter:
This thread's interpreter state.
.. c:function:: void PyEval_InitThreads()
.. index::
single: PyEval_AcquireThread()
single: PyEval_ReleaseThread()
single: PyEval_SaveThread()
single: PyEval_RestoreThread()
Deprecated function which does nothing.
In Python 3.6 and older, this function created the GIL if it didn't exist.
.. versionchanged:: 3.9
The function now does nothing.
.. versionchanged:: 3.7
This function is now called by :c:func:`Py_Initialize()`, so you don't
have to call it yourself anymore.
.. versionchanged:: 3.2
This function cannot be called before :c:func:`Py_Initialize()` anymore.
.. deprecated:: 3.9
.. index:: pair: module; _thread
.. c:function:: PyThreadState* PyEval_SaveThread()
Release the global interpreter lock (if it has been created) and reset the
Expand Down
1 change: 1 addition & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ features:

.. audit-event:: os.chmod path,mode,dir_fd os.chmod

.. versionadded:: 3.3
.. versionchanged:: 3.3
Added support for specifying *path* as an open file descriptor,
and the *dir_fd* and *follow_symlinks* arguments.

Expand Down Expand Up @@ -2166,7 +2166,7 @@ features:
The function is limited on WASI, see :ref:`wasm-availability` for more
information.

.. versionadded:: 3.3
.. versionchanged:: 3.3
Added support for specifying *path* as an open file descriptor,
and the *dir_fd* and *follow_symlinks* arguments.

Expand Down Expand Up @@ -2310,7 +2310,7 @@ features:
.. versionchanged:: 3.2
The *path* parameter became optional.

.. versionadded:: 3.3
.. versionchanged:: 3.3
Added support for specifying *path* as an open file descriptor.

.. versionchanged:: 3.6
Expand Down
86 changes: 86 additions & 0 deletions Doc/tools/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,90 @@
{{ "}" }}
</style>
{{ super() }}

<meta name="readthedocs-addons-api-version" content="1">
<script type="text/javascript">
function onSwitch(event) {
const option = event.target.selectedIndex;
const item = event.target.options[option];
window.location.href = item.dataset.url;
}

document.addEventListener("readthedocs-addons-data-ready", function(event) {
const config = event.detail.data()

// Add some mocked hardcoded versions pointing to the official
// documentation while migrating to Read the Docs.
// These are only for testing purposes.
// TODO: remove them when managing all the versions on Read the Docs,
// since all the "active, built and not hidden" versions will be shown automatically.
let versions = config.versions.active.concat([
{
slug: "dev (3.13)",
urls: {
documentation: "https://docs.python.org/3.13/",
}
},
{
slug: "3.12",
urls: {
documentation: "https://docs.python.org/3.12/",
}
},
{
slug: "3.11",
urls: {
documentation: "https://docs.python.org/3.11/",
}
},
]);

const versionSelect = `
<select id="version_select">
${ versions.map(
(version) => `
<option
value="${ version.slug }"
${ config.versions.current.slug === version.slug ? 'selected="selected"' : '' }
data-url="${ version.urls.documentation }">
${ version.slug }
</option>`
).join("\n") }
</select>
`;

// Prepend the current language to the options on the selector
let languages = config.projects.translations.concat(config.projects.current);
languages = languages.sort((a, b) => a.language.name.localeCompare(b.language.name));

const languageSelect = `
<select id="language_select">
${ languages.map(
(translation) => `
<option
value="${ translation.slug }"
${ config.projects.current.slug === translation.slug ? 'selected="selected"' : '' }
data-url="${ translation.urls.documentation }">
${ translation.language.name }
</option>`
).join("\n") }
</select>
`;

// Query all the placeholders because there are different ones for Desktop/Mobile
const versionPlaceholders = document.querySelectorAll(".version_switcher_placeholder");
for (placeholder of versionPlaceholders) {
placeholder.innerHTML = versionSelect;
let selectElement = placeholder.querySelector("select");
selectElement.addEventListener("change", onSwitch);
}

const languagePlaceholders = document.querySelectorAll(".language_switcher_placeholder");
for (placeholder of languagePlaceholders) {
placeholder.innerHTML = languageSelect;
let selectElement = placeholder.querySelector("select");
selectElement.addEventListener("change", onSwitch);
}
});
</script>
{% endblock %}
6 changes: 3 additions & 3 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2027,9 +2027,9 @@ Removed
added in Python 3.8 and the old macros were deprecated in Python 3.11.
(Contributed by Irit Katriel in :gh:`105111`.)

* Remove ``PyEval_InitThreads()`` and ``PyEval_ThreadsInitialized()``
functions, deprecated in Python 3.9. Since Python 3.7, ``Py_Initialize()``
always creates the GIL: calling ``PyEval_InitThreads()`` did nothing and
* Remove ``PyEval_ThreadsInitialized()``
function, deprecated in Python 3.9. Since Python 3.7, ``Py_Initialize()``
always creates the GIL: calling ``PyEval_InitThreads()`` does nothing and
``PyEval_ThreadsInitialized()`` always returned non-zero.
(Contributed by Victor Stinner in :gh:`105182`.)

Expand Down
2 changes: 2 additions & 0 deletions Include/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(PyFrameObject *f, int exc);
PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);

Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);

PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);

Expand Down
47 changes: 25 additions & 22 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ without deallocating anything (and so unbounded call-stack depth is avoided).
When the call stack finishes unwinding again, code generated by the END macro
notices this, and calls another routine to deallocate all the objects that
may have been added to the list of deferred deallocations. In effect, a
chain of N deallocations is broken into (N-1)/(_PyTrash_UNWIND_LEVEL-1) pieces,
with the call stack never exceeding a depth of _PyTrash_UNWIND_LEVEL.
chain of N deallocations is broken into (N-1)/(Py_TRASHCAN_HEADROOM-1) pieces,
with the call stack never exceeding a depth of Py_TRASHCAN_HEADROOM.
Since the tp_dealloc of a subclass typically calls the tp_dealloc of the base
class, we need to ensure that the trashcan is only triggered on the tp_dealloc
Expand All @@ -461,30 +461,33 @@ passed as second argument to Py_TRASHCAN_BEGIN().
/* Python 3.9 private API, invoked by the macros below. */
PyAPI_FUNC(int) _PyTrash_begin(PyThreadState *tstate, PyObject *op);
PyAPI_FUNC(void) _PyTrash_end(PyThreadState *tstate);

PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyThreadState *tstate, PyObject *op);
PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(PyThreadState *tstate);


/* Python 3.10 private API, invoked by the Py_TRASHCAN_BEGIN(). */
PyAPI_FUNC(int) _PyTrash_cond(PyObject *op, destructor dealloc);

#define Py_TRASHCAN_BEGIN_CONDITION(op, cond) \
do { \
PyThreadState *_tstate = NULL; \
/* If "cond" is false, then _tstate remains NULL and the deallocator \
* is run normally without involving the trashcan */ \
if (cond) { \
_tstate = PyThreadState_GetUnchecked(); \
if (_PyTrash_begin(_tstate, _PyObject_CAST(op))) { \
break; \
} \
}
/* The body of the deallocator is here. */
#define Py_TRASHCAN_END \
if (_tstate) { \
_PyTrash_end(_tstate); \
} \
} while (0);
/* To avoid raising recursion errors during dealloc trigger trashcan before we reach
* recursion limit. To avoid trashing, we don't attempt to empty the trashcan until
* we have headroom above the trigger limit */
#define Py_TRASHCAN_HEADROOM 50

#define Py_TRASHCAN_BEGIN(op, dealloc) \
Py_TRASHCAN_BEGIN_CONDITION((op), \
_PyTrash_cond(_PyObject_CAST(op), (destructor)(dealloc)))
do { \
PyThreadState *tstate = PyThreadState_Get(); \
if (tstate->c_recursion_remaining <= Py_TRASHCAN_HEADROOM && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \
_PyTrash_thread_deposit_object(tstate, (PyObject *)op); \
break; \
} \
tstate->c_recursion_remaining--;
/* The body of the deallocator is here. */
#define Py_TRASHCAN_END \
tstate->c_recursion_remaining++; \
if (tstate->delete_later && tstate->c_recursion_remaining > (Py_TRASHCAN_HEADROOM*2)) { \
_PyTrash_thread_destroy_chain(tstate); \
} \
} while (0);


PyAPI_FUNC(void *) PyObject_GetItemData(PyObject *obj);
Expand Down
7 changes: 1 addition & 6 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ typedef struct _stack_chunk {
PyObject * data[1]; /* Variable sized */
} _PyStackChunk;

struct _py_trashcan {
int delete_nesting;
PyObject *delete_later;
};

struct _ts {
/* See Python/ceval.c for comments explaining most fields */

Expand Down Expand Up @@ -152,7 +147,7 @@ struct _ts {
*/
unsigned long native_thread_id;

struct _py_trashcan trash;
PyObject *delete_later;

/* Tagged pointer to top-most critical section, or zero if there is no
* active critical section. Critical sections are only used in
Expand Down
4 changes: 4 additions & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(co_stacksize)
STRUCT_FOR_ID(co_varnames)
STRUCT_FOR_ID(code)
STRUCT_FOR_ID(col_offset)
STRUCT_FOR_ID(command)
STRUCT_FOR_ID(comment_factory)
STRUCT_FOR_ID(compile_mode)
Expand Down Expand Up @@ -402,6 +403,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(encode)
STRUCT_FOR_ID(encoding)
STRUCT_FOR_ID(end)
STRUCT_FOR_ID(end_col_offset)
STRUCT_FOR_ID(end_lineno)
STRUCT_FOR_ID(end_offset)
STRUCT_FOR_ID(endpos)
Expand Down Expand Up @@ -522,6 +524,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(kw1)
STRUCT_FOR_ID(kw2)
STRUCT_FOR_ID(kwdefaults)
STRUCT_FOR_ID(label)
STRUCT_FOR_ID(lambda)
STRUCT_FOR_ID(last)
STRUCT_FOR_ID(last_exc)
Expand Down Expand Up @@ -585,6 +588,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(namespaces)
STRUCT_FOR_ID(narg)
STRUCT_FOR_ID(ndigits)
STRUCT_FOR_ID(nested)
STRUCT_FOR_ID(new_file_name)
STRUCT_FOR_ID(new_limit)
STRUCT_FOR_ID(newline)
Expand Down

0 comments on commit 778de8e

Please sign in to comment.