Skip to content

Commit

Permalink
Merge branch 'main' into allow-any-object-as-code
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon committed Jun 9, 2023
2 parents d037c50 + 5cdd5ba commit ea51766
Show file tree
Hide file tree
Showing 98 changed files with 1,980 additions and 1,066 deletions.
24 changes: 16 additions & 8 deletions Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,24 @@ API Functions
.. versionadded:: 3.2
.. XXX deprecated, will be removed
.. c:function:: int PyArg_Parse(PyObject *args, const char *format, ...)
Function used to deconstruct the argument lists of "old-style" functions ---
these are functions which use the :const:`METH_OLDARGS` parameter parsing
method, which has been removed in Python 3. This is not recommended for use
in parameter parsing in new code, and most code in the standard interpreter
has been modified to no longer use this for that purpose. It does remain a
convenient way to decompose other tuples, however, and may continue to be
used for that purpose.
Parse the parameter of a function that takes a single positional parameter
into a local variable. Returns true on success; on failure, it returns
false and raises the appropriate exception.
Example::
// Function using METH_O calling convention
static PyObject*
my_function(PyObject *module, PyObject *arg)
{
int value;
if (!PyArg_Parse(arg, "i:my_function", &value)) {
return NULL;
}
// ... use value ...
}
.. c:function:: int PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...)
Expand Down
8 changes: 4 additions & 4 deletions Doc/library/tarfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ can be:
path to where the archive is extracted (i.e. the same path is used for all
members)::

filter(/, member: TarInfo, path: str) -> TarInfo | None
filter(member: TarInfo, path: str, /) -> TarInfo | None

The callable is called just before each member is extracted, so it can
take the current state of the disk into account.
Expand All @@ -928,13 +928,13 @@ Default named filters
The pre-defined, named filters are available as functions, so they can be
reused in custom filters:

.. function:: fully_trusted_filter(/, member, path)
.. function:: fully_trusted_filter(member, path)

Return *member* unchanged.

This implements the ``'fully_trusted'`` filter.

.. function:: tar_filter(/, member, path)
.. function:: tar_filter(member, path)

Implements the ``'tar'`` filter.

Expand All @@ -951,7 +951,7 @@ reused in custom filters:

Return the modified ``TarInfo`` member.

.. function:: data_filter(/, member, path)
.. function:: data_filter(member, path)

Implements the ``'data'`` filter.
In addition to what ``tar_filter`` does:
Expand Down
6 changes: 3 additions & 3 deletions Doc/library/urllib.parse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ to an absolute URL given a "base URL."
The module has been designed to match the internet RFC on Relative Uniform
Resource Locators. It supports the following URL schemes: ``file``, ``ftp``,
``gopher``, ``hdl``, ``http``, ``https``, ``imap``, ``mailto``, ``mms``,
``news``, ``nntp``, ``prospero``, ``rsync``, ``rtsp``, ``rtspu``, ``sftp``,
``shttp``, ``sip``, ``sips``, ``snews``, ``svn``, ``svn+ssh``, ``telnet``,
``wais``, ``ws``, ``wss``.
``news``, ``nntp``, ``prospero``, ``rsync``, ``rtsp``, ``rtsps``, ``rtspu``,
``sftp``, ``shttp``, ``sip``, ``sips``, ``snews``, ``svn``, ``svn+ssh``,
``telnet``, ``wais``, ``ws``, ``wss``.

The :mod:`urllib.parse` module defines functions that fall into two broad
categories: URL parsing and URL quoting. These are covered in detail in
Expand Down
10 changes: 10 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,8 @@ Removed
* The :mod:`!imp` module has been removed. (Contributed by Barry Warsaw in
:gh:`98040`.)

* Replace ``imp.new_module(name)`` with ``types.ModuleType(name)``.

* Removed the ``suspicious`` rule from the documentation Makefile, and
removed ``Doc/tools/rstlint.py``, both in favor of `sphinx-lint
<https://github.com/sphinx-contrib/sphinx-lint>`_.
Expand Down Expand Up @@ -1499,6 +1501,9 @@ Changes in the Python API
* Some incomplete or invalid Python code now raises :exc:`tokenize.TokenError` instead of
returning arbitrary ``ERRORTOKEN`` tokens when tokenizing it.

* Mixing tabs and spaces as indentation in the same file is not supported anymore and will
raise a :exc:`TabError`.

Build Changes
=============

Expand Down Expand Up @@ -1689,6 +1694,11 @@ New Features

(Contributed by Eddie Elizondo in :gh:`84436`.)

* In the limited C API version 3.12, :c:func:`Py_INCREF` and
:c:func:`Py_DECREF` functions are now implemented as opaque function calls to
hide implementation details.
(Contributed by Victor Stinner in :gh:`105387`.)

Porting to Python 3.12
----------------------

Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ Deprecated
Use the ``'w'`` format code instead.
(contributed by Hugo van Kemenade in :gh:`80480`)

* :mod:`ctypes`: Deprecate undocumented :func:`!ctypes.SetPointerType`
and :func:`!ctypes.ARRAY` functions.
Replace ``ctypes.SetPointerType(item_type, size)`` with ``item_type * size``.
(Contributed by Victor Stinner in :gh:`105733`.)


Removed
=======

Expand Down
2 changes: 2 additions & 0 deletions Include/cpython/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _P
PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);

PyAPI_FUNC(int) _PyEval_MakePendingCalls(PyThreadState *);

PyAPI_FUNC(Py_ssize_t) PyUnstable_Eval_RequestCodeExtraIndex(freefunc);
// Old name -- remove when this API changes:
_Py_DEPRECATED_EXTERNALLY(3.12) static inline Py_ssize_t
Expand Down
10 changes: 7 additions & 3 deletions Include/cpython/initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,

/* --- PyInterpreterConfig ------------------------------------ */

#define PyInterpreterConfig_DEFAULT_GIL (0)
#define PyInterpreterConfig_SHARED_GIL (1)
#define PyInterpreterConfig_OWN_GIL (2)

typedef struct {
// XXX "allow_object_sharing"? "own_objects"?
int use_main_obmalloc;
Expand All @@ -252,7 +256,7 @@ typedef struct {
int allow_threads;
int allow_daemon_threads;
int check_multi_interp_extensions;
int own_gil;
int gil;
} PyInterpreterConfig;

#define _PyInterpreterConfig_INIT \
Expand All @@ -263,7 +267,7 @@ typedef struct {
.allow_threads = 1, \
.allow_daemon_threads = 0, \
.check_multi_interp_extensions = 1, \
.own_gil = 1, \
.gil = PyInterpreterConfig_OWN_GIL, \
}

#define _PyInterpreterConfig_LEGACY_INIT \
Expand All @@ -274,7 +278,7 @@ typedef struct {
.allow_threads = 1, \
.allow_daemon_threads = 1, \
.check_multi_interp_extensions = 0, \
.own_gil = 0, \
.gil = PyInterpreterConfig_SHARED_GIL, \
}

/* --- Helper functions --------------------------------------- */
Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
PyAPI_FUNC(int) _PyEval_AddPendingCall(
PyInterpreterState *interp,
int (*func)(void *),
void *arg);
void *arg,
int mainthreadonly);
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
#ifdef HAVE_FORK
extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
Expand Down
38 changes: 20 additions & 18 deletions Include/internal/pycore_ceval_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ extern "C" {
#include "pycore_gil.h" // struct _gil_runtime_state


struct _pending_calls {
int busy;
PyThread_type_lock lock;
/* Request for running pending calls. */
_Py_atomic_int calls_to_do;
/* Request for looking at the `async_exc` field of the current
thread state.
Guarded by the GIL. */
int async_exc;
#define NPENDINGCALLS 32
struct _pending_call {
int (*func)(void *);
void *arg;
} calls[NPENDINGCALLS];
int first;
int last;
};

typedef enum {
PERF_STATUS_FAILED = -1, // Perf trampoline is in an invalid state
PERF_STATUS_NO_INIT = 0, // Perf trampoline is not initialized
Expand Down Expand Up @@ -49,6 +67,8 @@ struct _ceval_runtime_state {
the main thread of the main interpreter can handle signals: see
_Py_ThreadCanHandleSignals(). */
_Py_atomic_int signals_pending;
/* Pending calls to be made only on the main thread. */
struct _pending_calls pending_mainthread;
};

#ifdef PY_HAVE_PERF_TRAMPOLINE
Expand All @@ -62,24 +82,6 @@ struct _ceval_runtime_state {
#endif


struct _pending_calls {
int busy;
PyThread_type_lock lock;
/* Request for running pending calls. */
_Py_atomic_int calls_to_do;
/* Request for looking at the `async_exc` field of the current
thread state.
Guarded by the GIL. */
int async_exc;
#define NPENDINGCALLS 32
struct {
int (*func)(void *);
void *arg;
} calls[NPENDINGCALLS];
int first;
int last;
};

struct _ceval_state {
/* This single variable consolidates all requests to break out of
the fast path in the eval loop. */
Expand Down
5 changes: 2 additions & 3 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.

8 changes: 0 additions & 8 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ _Py_ThreadCanHandleSignals(PyInterpreterState *interp)
}


/* Only execute pending calls on the main thread. */
static inline int
_Py_ThreadCanHandlePendingCalls(void)
{
return _Py_IsMainThread();
}


/* Variable and static inline functions for in-line access to current thread
and interpreter state */

Expand Down
18 changes: 10 additions & 8 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,11 @@ PyAPI_FUNC(void) _Py_DecRef(PyObject *);

static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
{
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API)
// Stable ABI for Python built in debug mode. _Py_IncRef() was added to
// Python 3.10.0a7, use Py_IncRef() on older Python versions. Py_IncRef()
// accepts NULL whereas _Py_IncRef() doesn't.
#if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
// Stable ABI implements Py_INCREF() as a function call on limited C API
// version 3.12 and newer, and on Python built in debug mode. _Py_IncRef()
// was added to Python 3.10.0a7, use Py_IncRef() on older Python versions.
// Py_IncRef() accepts NULL whereas _Py_IncRef() doesn't.
# if Py_LIMITED_API+0 >= 0x030a00A7
_Py_IncRef(op);
# else
Expand Down Expand Up @@ -647,10 +648,11 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
# define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
#endif

#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API)
// Stable ABI for Python built in debug mode. _Py_DecRef() was added to Python
// 3.10.0a7, use Py_DecRef() on older Python versions. Py_DecRef() accepts NULL
// whereas _Py_IncRef() doesn't.
#if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
// Stable ABI implements Py_DECREF() as a function call on limited C API
// version 3.12 and newer, and on Python built in debug mode. _Py_DecRef() was
// added to Python 3.10.0a7, use Py_DecRef() on older Python versions.
// Py_DecRef() accepts NULL whereas _Py_IncRef() doesn't.
static inline void Py_DECREF(PyObject *op) {
# if Py_LIMITED_API+0 >= 0x030a00A7
_Py_DecRef(op);
Expand Down
6 changes: 4 additions & 2 deletions Lib/ctypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,9 @@ def create_unicode_buffer(init, size=None):
raise TypeError(init)


# XXX Deprecated
def SetPointerType(pointer, cls):
import warnings
warnings._deprecated("ctypes.SetPointerType", remove=(3, 15))
if _pointer_type_cache.get(cls, None) is not None:
raise RuntimeError("This type already exists in the cache")
if id(pointer) not in _pointer_type_cache:
Expand All @@ -312,8 +313,9 @@ def SetPointerType(pointer, cls):
_pointer_type_cache[cls] = pointer
del _pointer_type_cache[id(pointer)]

# XXX Deprecated
def ARRAY(typ, len):
import warnings
warnings._deprecated("ctypes.ARRAY", remove=(3, 15))
return typ * len

################################################################
Expand Down
2 changes: 1 addition & 1 deletion Lib/ctypes/_endian.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from ctypes import *
from ctypes import Array, Structure, Union

_array_type = type(Array)

Expand Down
5 changes: 2 additions & 3 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.12b1 3531 (Add PEP 695 changes)
# Python 3.13a1 3550 (Plugin optimizer support)
# Python 3.13a1 3551 (Compact superinstructions)

# Python 3.13a1 3554 (Add SET_FUNCTION_ATTRIBUTE)
# Python 3.13a1 3552 (Add SET_FUNCTION_ATTRIBUTE)

# Python 3.14 will start with 3600

Expand All @@ -465,7 +464,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3554).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3552).to_bytes(2, 'little') + b'\r\n'

_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

Expand Down
5 changes: 4 additions & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1813,13 +1813,16 @@ def run_in_subinterp(code):
return _testcapi.run_in_subinterp(code)


def run_in_subinterp_with_config(code, **config):
def run_in_subinterp_with_config(code, *, own_gil=None, **config):
"""
Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc
module is enabled.
"""
_check_tracemalloc()
import _testcapi
if own_gil is not None:
assert 'gil' not in config, (own_gil, config)
config['gil'] = 2 if own_gil else 1
return _testcapi.run_in_subinterp_with_config(code, **config)


Expand Down
9 changes: 7 additions & 2 deletions Lib/test/support/threading_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ def join_thread(thread, timeout=None):

@contextlib.contextmanager
def start_threads(threads, unlock=None):
import faulthandler
try:
import faulthandler
except ImportError:
# It isn't supported on subinterpreters yet.
faulthandler = None
threads = list(threads)
started = []
try:
Expand Down Expand Up @@ -147,7 +151,8 @@ def start_threads(threads, unlock=None):
finally:
started = [t for t in started if t.is_alive()]
if started:
faulthandler.dump_traceback(sys.stdout)
if faulthandler is not None:
faulthandler.dump_traceback(sys.stdout)
raise AssertionError('Unable to join %d threads' % len(started))


Expand Down
Loading

0 comments on commit ea51766

Please sign in to comment.