Skip to content

Commit

Permalink
Merge branch 'main' into wasi-CI
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcannon authored Mar 11, 2024
2 parents ee8676f + 113053a commit 8f1719e
Show file tree
Hide file tree
Showing 68 changed files with 1,416 additions and 539 deletions.
25 changes: 24 additions & 1 deletion Doc/c-api/hash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PyHash API
----------

See also the :c:member:`PyTypeObject.tp_hash` member.
See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`.

.. c:type:: Py_hash_t
Expand All @@ -17,6 +17,29 @@ See also the :c:member:`PyTypeObject.tp_hash` member.

.. versionadded:: 3.2

.. c:macro:: PyHASH_MODULUS
The `Mersenne prime <https://en.wikipedia.org/wiki/Mersenne_prime>`_ ``P = 2**n -1``, used for numeric hash scheme.

.. versionadded:: 3.13

.. c:macro:: PyHASH_BITS
The exponent ``n`` of ``P`` in :c:macro:`PyHASH_MODULUS`.

.. versionadded:: 3.13

.. c:macro:: PyHASH_INF
The hash value returned for a positive infinity.

.. versionadded:: 3.13

.. c:macro:: PyHASH_IMAG
The multiplier used for the imaginary part of a complex number.

.. versionadded:: 3.13

.. c:type:: PyHash_FuncDef
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/dataclasses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ Using dataclasses, *if* this code was valid::
class D:
x: list = [] # This code raises ValueError
def add(self, element):
self.x += element
self.x.append(element)

it would generate code similar to::

Expand All @@ -728,7 +728,7 @@ it would generate code similar to::
def __init__(self, x=x):
self.x = x
def add(self, element):
self.x += element
self.x.append(element)

assert D().x is D().x

Expand Down
2 changes: 2 additions & 0 deletions Doc/library/resource.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ platform.

The largest area of mapped memory which the process may occupy.

.. availability:: FreeBSD >= 11.


.. data:: RLIMIT_AS

Expand Down
18 changes: 18 additions & 0 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ Miscellaneous options
:mod:`__main__`. This can be used to execute code early during Python
initialization. Python needs to be :ref:`built in debug mode <debug-build>`
for this option to exist. See also :envvar:`PYTHON_PRESITE`.
* :samp:`-X gil={0,1}` forces the GIL to be disabled or enabled,
respectively. Only available in builds configured with
:option:`--disable-gil`. See also :envvar:`PYTHON_GIL`.

It also allows passing arbitrary values and retrieving them through the
:data:`sys._xoptions` dictionary.
Expand Down Expand Up @@ -601,6 +604,9 @@ Miscellaneous options
.. versionchanged:: 3.13
Added the ``-X cpu_count`` and ``-X presite`` options.

.. versionchanged:: 3.13
Added the ``-X gil`` option.

.. _using-on-controlling-color:

Controlling color
Expand Down Expand Up @@ -1138,6 +1144,18 @@ conflict.

.. versionadded:: 3.13

.. envvar:: PYTHON_GIL

If this variable is set to ``1``, the global interpreter lock (GIL) will be
forced on. Setting it to ``0`` forces the GIL off.

See also the :option:`-X gil <-X>` command-line option, which takes
precedence over this variable.

Needs Python configured with the :option:`--disable-gil` build option.

.. versionadded:: 3.13

Debug-mode variables
~~~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 3 additions & 0 deletions Include/cpython/initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ typedef struct PyConfig {
int int_max_str_digits;

int cpu_count;
#ifdef Py_GIL_DISABLED
int enable_gil;
#endif

/* --- Path configuration inputs ------------ */
int pathconfig_warnings;
Expand Down
16 changes: 11 additions & 5 deletions Include/cpython/pyhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@
reduction modulo the prime 2**_PyHASH_BITS - 1. */

#if SIZEOF_VOID_P >= 8
# define _PyHASH_BITS 61
# define PyHASH_BITS 61
#else
# define _PyHASH_BITS 31
# define PyHASH_BITS 31
#endif

#define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1)
#define _PyHASH_INF 314159
#define _PyHASH_IMAG _PyHASH_MULTIPLIER
#define PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1)
#define PyHASH_INF 314159
#define PyHASH_IMAG _PyHASH_MULTIPLIER

/* Aliases kept for backward compatibility with Python 3.12 */
#define _PyHASH_BITS PyHASH_BITS
#define _PyHASH_MODULUS PyHASH_MODULUS
#define _PyHASH_INF PyHASH_INF
#define _PyHASH_IMAG PyHASH_IMAG

/* Helpers for hash functions */
PyAPI_FUNC(Py_hash_t) _Py_HashDouble(PyObject *, double);
Expand Down
5 changes: 5 additions & 0 deletions Include/internal/pycore_gil.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ extern "C" {
#define FORCE_SWITCHING

struct _gil_runtime_state {
#ifdef Py_GIL_DISABLED
/* Whether or not this GIL is being used. Can change from 0 to 1 at runtime
if, for example, a module that requires the GIL is loaded. */
int enabled;
#endif
/* microseconds (the Python API uses seconds, though) */
unsigned long interval;
/* Last PyThreadState holding / having held the GIL. This helps us
Expand Down
12 changes: 12 additions & 0 deletions Include/internal/pycore_initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ typedef enum {
_PyConfig_INIT_ISOLATED = 3
} _PyConfigInitEnum;

typedef enum {
/* For now, this means the GIL is enabled.
gh-116329: This will eventually change to "the GIL is disabled but can
be reenabled by loading an incompatible extension module." */
_PyConfig_GIL_DEFAULT = -1,

/* The GIL has been forced off or on, and will not be affected by module loading. */
_PyConfig_GIL_DISABLE = 0,
_PyConfig_GIL_ENABLE = 1,
} _PyConfigGILEnum;

// Export for '_testembed' program
PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);

Expand Down
4 changes: 4 additions & 0 deletions Include/internal/pycore_mimalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ typedef enum {
# define MI_DEBUG 0
#endif

#ifdef _Py_THREAD_SANITIZER
# define MI_TSAN 1
#endif

#include "mimalloc.h"
#include "mimalloc/types.h"
#include "mimalloc/internal.h"
Expand Down
34 changes: 17 additions & 17 deletions Include/internal/pycore_opcode_metadata.h

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

6 changes: 4 additions & 2 deletions Include/internal/pycore_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec(
PyAPI_FUNC(PyTime_t) _PyTime_FromSeconds(int seconds);

// Create a timestamp from a number of seconds in double.
// Export for '_socket' shared extension.
PyAPI_FUNC(PyTime_t) _PyTime_FromSecondsDouble(double seconds, _PyTime_round_t round);
extern int _PyTime_FromSecondsDouble(
double seconds,
_PyTime_round_t round,
PyTime_t *result);

// Macro to create a timestamp from a number of seconds, no integer overflow.
// Only use the macro for small values, prefer _PyTime_FromSeconds().
Expand Down
28 changes: 14 additions & 14 deletions Include/internal/pycore_uop_metadata.h

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

2 changes: 1 addition & 1 deletion Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def _args_from_interpreter_flags():
if dev_mode:
args.extend(('-X', 'dev'))
for opt in ('faulthandler', 'tracemalloc', 'importtime',
'frozen_modules', 'showrefcount', 'utf8'):
'frozen_modules', 'showrefcount', 'utf8', 'gil'):
if opt in xoptions:
value = xoptions[opt]
if value is True:
Expand Down
Loading

0 comments on commit 8f1719e

Please sign in to comment.