Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into safer-tuples
  • Loading branch information
markshannon committed Nov 8, 2024
commit 003264fb1ed023375eca1ff44a204f563d938bfd
149 changes: 1 addition & 148 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2660,158 +2660,11 @@ Changes in the C API
}

Note that ``Py_TRASHCAN_BEGIN`` has a second argument which
should be the deallocation function it is in.

* On Windows, ``Python.h`` no longer includes the ``<stddef.h>`` standard
header file. If needed, it should now be included explicitly. For example, it
provides ``offsetof()`` function, and ``size_t`` and ``ptrdiff_t`` types.
Including ``<stddef.h>`` explicitly was already needed by all other
platforms, the ``HAVE_STDDEF_H`` macro is only defined on Windows.
(Contributed by Victor Stinner in :gh:`108765`.)

should be the deallocation function it is in. The new macros were
* The :c:func:`PyTuple_SET_ITEM` inline function may not be passed ``NULL``.
This has always been the documented behavior, but was not enforced for

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.python.org/dev/c-api/tuple.html#c.PyTuple_SET_ITEM and https://docs.python.org/dev/c-api/tuple.html#c.PyTuple_SetItem don't say that the second argument must not be NULL. I suggest to modify the doc to be extra explicit about it.

the value until now. :c:var:``Py_None` should be used instead of ``NULL``.

Deprecated
----------

* Passing optional arguments *maxsplit*, *count* and *flags* in module-level
functions :func:`re.split`, :func:`re.sub` and :func:`re.subn` as positional
arguments is now deprecated.
In future Python versions these parameters will be
:ref:`keyword-only <keyword-only_parameter>`.
(Contributed by Serhiy Storchaka in :gh:`56166`.)

* Deprecate the old ``Py_UNICODE`` and ``PY_UNICODE_TYPE`` types: use directly
the :c:type:`wchar_t` type instead. Since Python 3.3, ``Py_UNICODE`` and
``PY_UNICODE_TYPE`` are just aliases to :c:type:`wchar_t`.
(Contributed by Victor Stinner in :gh:`105156`.)

* Deprecate old Python initialization functions:

* :c:func:`PySys_ResetWarnOptions`:
clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
* :c:func:`Py_GetExecPrefix`: get :data:`sys.exec_prefix` instead.
* :c:func:`Py_GetPath`: get :data:`sys.path` instead.
* :c:func:`Py_GetPrefix`: get :data:`sys.prefix` instead.
* :c:func:`Py_GetProgramFullPath`: get :data:`sys.executable` instead.
* :c:func:`Py_GetProgramName`: get :data:`sys.executable` instead.
* :c:func:`Py_GetPythonHome`: get :c:member:`PyConfig.home` or
:envvar:`PYTHONHOME` environment variable instead.

Functions scheduled for removal in Python 3.15.
(Contributed by Victor Stinner in :gh:`105145`.)

* Deprecate the :c:func:`PyImport_ImportModuleNoBlock` function which is just
an alias to :c:func:`PyImport_ImportModule` since Python 3.3.
Scheduled for removal in Python 3.15.
(Contributed by Victor Stinner in :gh:`105396`.)

* Deprecate the :c:func:`PyWeakref_GetObject` and
:c:func:`PyWeakref_GET_OBJECT` functions, which return a :term:`borrowed
reference`: use the new :c:func:`PyWeakref_GetRef` function instead, it
returns a :term:`strong reference`. The `pythoncapi-compat project
<https://github.com/python/pythoncapi-compat/>`__ can be used to get
:c:func:`PyWeakref_GetRef` on Python 3.12 and older.
(Contributed by Victor Stinner in :gh:`105927`.)

Removed
-------

* Removed chained :class:`classmethod` descriptors (introduced in
:gh:`63272`). This can no longer be used to wrap other descriptors
such as :class:`property`. The core design of this feature was flawed
and caused a number of downstream problems. To "pass-through" a
:class:`classmethod`, consider using the :attr:`!__wrapped__`
attribute that was added in Python 3.10. (Contributed by Raymond
Hettinger in :gh:`89519`.)

* Remove many APIs (functions, macros, variables) with names prefixed by
``_Py`` or ``_PY`` (considered as private API). If your project is affected
by one of these removals and you consider that the removed API should remain
available, please open a new issue to request a public C API and
add ``cc @vstinner`` to the issue to notify Victor Stinner.
(Contributed by Victor Stinner in :gh:`106320`.)

* Remove functions deprecated in Python 3.9:

* ``PyEval_CallObject()``, ``PyEval_CallObjectWithKeywords()``: use
:c:func:`PyObject_CallNoArgs` or :c:func:`PyObject_Call` instead.
Warning: :c:func:`PyObject_Call` positional arguments must be a
:class:`tuple` and must not be ``NULL``, keyword arguments must be a
:class:`dict` or ``NULL``, whereas removed functions checked arguments type
and accepted ``NULL`` positional and keyword arguments.
To replace ``PyEval_CallObjectWithKeywords(func, NULL, kwargs)`` with
:c:func:`PyObject_Call`, pass an empty tuple as positional arguments using
:c:func:`PyTuple_New(0) <PyTuple_New>`.
* ``PyEval_CallFunction()``: use :c:func:`PyObject_CallFunction` instead.
* ``PyEval_CallMethod()``: use :c:func:`PyObject_CallMethod` instead.
* ``PyCFunction_Call()``: use :c:func:`PyObject_Call` instead.

(Contributed by Victor Stinner in :gh:`105107`.)

* Remove old buffer protocols deprecated in Python 3.0. Use :ref:`bufferobjects` instead.

* :c:func:`!PyObject_CheckReadBuffer`: Use :c:func:`PyObject_CheckBuffer` to
test if the object supports the buffer protocol.
Note that :c:func:`PyObject_CheckBuffer` doesn't guarantee that
:c:func:`PyObject_GetBuffer` will succeed.
To test if the object is actually readable, see the next example
of :c:func:`PyObject_GetBuffer`.

* :c:func:`!PyObject_AsCharBuffer`, :c:func:`!PyObject_AsReadBuffer`:
:c:func:`PyObject_GetBuffer` and :c:func:`PyBuffer_Release` instead:

.. code-block:: c

Py_buffer view;
if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) < 0) {
return NULL;
}
// Use `view.buf` and `view.len` to read from the buffer.
// You may need to cast buf as `(const char*)view.buf`.
PyBuffer_Release(&view);

* :c:func:`!PyObject_AsWriteBuffer`: Use
:c:func:`PyObject_GetBuffer` and :c:func:`PyBuffer_Release` instead:

.. code-block:: c

Py_buffer view;
if (PyObject_GetBuffer(obj, &view, PyBUF_WRITABLE) < 0) {
return NULL;
}
// Use `view.buf` and `view.len` to write to the buffer.
PyBuffer_Release(&view);

(Contributed by Inada Naoki in :gh:`85275`.)

* Remove the following old functions to configure the Python initialization,
deprecated in Python 3.11:

* ``PySys_AddWarnOptionUnicode()``: use :c:member:`PyConfig.warnoptions` instead.
* ``PySys_AddWarnOption()``: use :c:member:`PyConfig.warnoptions` instead.
* ``PySys_AddXOption()``: use :c:member:`PyConfig.xoptions` instead.
* ``PySys_HasWarnOptions()``: use :c:member:`PyConfig.xoptions` instead.
* ``PySys_SetArgvEx()``: set :c:member:`PyConfig.argv` instead.
* ``PySys_SetArgv()``: set :c:member:`PyConfig.argv` instead.
* ``PySys_SetPath()``: set :c:member:`PyConfig.module_search_paths` instead.
* ``Py_SetPath()``: set :c:member:`PyConfig.module_search_paths` instead.
* ``Py_SetProgramName()``: set :c:member:`PyConfig.program_name` instead.
* ``Py_SetPythonHome()``: set :c:member:`PyConfig.home` instead.
* ``Py_SetStandardStreamEncoding()``: set :c:member:`PyConfig.stdio_encoding`
instead, and set also maybe :c:member:`PyConfig.legacy_windows_stdio` (on
Windows).
* ``_Py_SetProgramFullPath()``: set :c:member:`PyConfig.executable` instead.

Use the new :c:type:`PyConfig` API of the :ref:`Python Initialization
Configuration <init-config>` instead (:pep:`587`), added to Python 3.8.
(Contributed by Victor Stinner in :gh:`105145`.)

* Remove the old trashcan macros ``Py_TRASHCAN_SAFE_BEGIN`` and
``Py_TRASHCAN_SAFE_END``. They should be replaced by the new macros
``Py_TRASHCAN_BEGIN`` and ``Py_TRASHCAN_END``. The new macros were
added in Python 3.8 and the old macros were deprecated in Python 3.11.
(Contributed by Irit Katriel in :gh:`105111`.)

Expand Down
44 changes: 0 additions & 44 deletions Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3751,50 +3751,6 @@ zip_longest_next(ziplongestobject *lz)
return result;
}

static PyObject *
zip_longest_reduce(ziplongestobject *lz, PyObject *Py_UNUSED(ignored))
{
ITERTOOL_PICKLE_DEPRECATION;
/* Create a new tuple with empty sequences where appropriate to pickle.
* Then use setstate to set the fillvalue
*/
int i;
PyObject *args = PyTuple_New(PyTuple_GET_SIZE(lz->ittuple));

if (args == NULL)
return NULL;
for (i=0; i<PyTuple_GET_SIZE(lz->ittuple); i++) {
PyObject *elem = PyTuple_GET_ITEM(lz->ittuple, i);
if (elem == Py_None) {
elem = PyTuple_New(0);
if (elem == NULL) {
Py_DECREF(args);
return NULL;
}
} else
Py_INCREF(elem);
PyTuple_SET_ITEM(args, i, elem);
}
return Py_BuildValue("ONO", Py_TYPE(lz), args, lz->fillvalue);
}

static PyObject *
zip_longest_setstate(ziplongestobject *lz, PyObject *state)
{
ITERTOOL_PICKLE_DEPRECATION;
Py_INCREF(state);
Py_XSETREF(lz->fillvalue, state);
Py_RETURN_NONE;
}

static PyMethodDef zip_longest_methods[] = {
{"__reduce__", (PyCFunction)zip_longest_reduce, METH_NOARGS,
reduce_doc},
{"__setstate__", (PyCFunction)zip_longest_setstate, METH_O,
setstate_doc},
{NULL, NULL} /* sentinel */
};

PyDoc_STRVAR(zip_longest_doc,
"zip_longest(*iterables, fillvalue=None)\n\
--\n\
Expand Down
2 changes: 1 addition & 1 deletion Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3163,7 +3163,7 @@ _PyList_AsTupleTakeItems(PyObject *v)
}

PyObject *
_PyList_FromArraySteal(PyObject *const *src, Py_ssize_t n)
_PyList_FromStackRefSteal(const _PyStackRef *src, Py_ssize_t n)
{
if (n == 0) {
return PyList_New(0);
Expand Down
10 changes: 4 additions & 6 deletions Objects/tupleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ tuple_alloc(Py_ssize_t size)
sizeof(PyObject *))) / sizeof(PyObject *)) {
return (PyTupleObject *)PyErr_NoMemory();
}
op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size);
if (op == NULL)
return NULL;
}
/* Check for overflow */
if ((size_t)size > ((size_t)PY_SSIZE_T_MAX - (sizeof(PyTupleObject) -
sizeof(PyObject *))) / sizeof(PyObject *)) {
return (PyTupleObject *)PyErr_NoMemory();
}
return PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size);
return op;
}

// The empty tuple singleton is not tracked by the GC.
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.