Skip to content

Commit 9012fa7

Browse files
authored
gh-128863: Deprecate private C API functions (#128864)
Deprecate private C API functions: * _PyBytes_Join() * _PyDict_GetItemStringWithError() * _PyDict_Pop() * _PyThreadState_UncheckedGet() * _PyUnicode_AsString() * _Py_HashPointer() * _Py_fopen_obj() Replace _Py_HashPointer() with Py_HashPointer(). Remove references to deprecated functions.
1 parent 470a0a6 commit 9012fa7

File tree

16 files changed

+103
-30
lines changed

16 files changed

+103
-30
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Pending removal in Python 3.18
2+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3+
4+
* Deprecated private functions (:gh:`128863`):
5+
6+
* :c:func:`!_PyBytes_Join`: use :c:func:`PyBytes_Join`.
7+
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
8+
* :c:func:`!_PyDict_Pop()`: :c:func:`PyDict_Pop`.
9+
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
10+
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
11+
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
12+
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.
13+
14+
The `pythoncapi-compat project
15+
<https://github.com/python/pythoncapi-compat/>`__ can be used to get these
16+
new public functions on Python 3.13 and older.

Doc/whatsnew/3.14.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,12 +1376,31 @@ Deprecated
13761376
13771377
.. include:: ../deprecations/c-api-pending-removal-in-3.15.rst
13781378

1379+
.. include:: ../deprecations/c-api-pending-removal-in-3.18.rst
1380+
13791381
.. include:: ../deprecations/c-api-pending-removal-in-future.rst
13801382

13811383
* The ``PyMonitoring_FireBranchEvent`` function is deprecated and should
13821384
be replaced with calls to :c:func:`PyMonitoring_FireBranchLeftEvent`
13831385
and :c:func:`PyMonitoring_FireBranchRightEvent`.
13841386

1387+
* The following private functions are deprecated and planned for removal in
1388+
Python 3.18:
1389+
1390+
* :c:func:`!_PyBytes_Join`: use :c:func:`PyBytes_Join`.
1391+
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
1392+
* :c:func:`!_PyDict_Pop()`: use :c:func:`PyDict_Pop`.
1393+
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
1394+
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
1395+
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
1396+
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.
1397+
1398+
The `pythoncapi-compat project`_ can be used to get these new public
1399+
functions on Python 3.13 and older.
1400+
1401+
(Contributed by Victor Stinner in :gh:`128863`.)
1402+
1403+
13851404
Removed
13861405
-------
13871406

Include/cpython/bytesobject.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@ static inline Py_ssize_t PyBytes_GET_SIZE(PyObject *op) {
3434

3535
PyAPI_FUNC(PyObject*) PyBytes_Join(PyObject *sep, PyObject *iterable);
3636

37-
// Alias kept for backward compatibility
38-
#define _PyBytes_Join PyBytes_Join
37+
// Deprecated alias kept for backward compatibility
38+
Py_DEPRECATED(3.14) static inline PyObject*
39+
_PyBytes_Join(PyObject *sep, PyObject *iterable)
40+
{
41+
return PyBytes_Join(sep, iterable);
42+
}

Include/cpython/dictobject.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
6868

6969
PyAPI_FUNC(int) PyDict_Pop(PyObject *dict, PyObject *key, PyObject **result);
7070
PyAPI_FUNC(int) PyDict_PopString(PyObject *dict, const char *key, PyObject **result);
71-
PyAPI_FUNC(PyObject *) _PyDict_Pop(PyObject *dict, PyObject *key, PyObject *default_value);
71+
72+
// Use PyDict_Pop() instead
73+
Py_DEPRECATED(3.14) PyAPI_FUNC(PyObject *) _PyDict_Pop(
74+
PyObject *dict,
75+
PyObject *key,
76+
PyObject *default_value);
7277

7378
/* Dictionary watchers */
7479

Include/cpython/fileutils.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ PyAPI_FUNC(FILE*) Py_fopen(
66
PyObject *path,
77
const char *mode);
88

9-
// Deprecated alias to Py_fopen() kept for backward compatibility
10-
Py_DEPRECATED(3.14) PyAPI_FUNC(FILE*) _Py_fopen_obj(
11-
PyObject *path,
12-
const char *mode);
9+
// Deprecated alias kept for backward compatibility
10+
Py_DEPRECATED(3.14) static inline FILE*
11+
_Py_fopen_obj(PyObject *path, const char *mode)
12+
{
13+
return Py_fopen(path, mode);
14+
}
1315

1416
PyAPI_FUNC(int) Py_fclose(FILE *file);

Include/cpython/pyhash.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
/* Helpers for hash functions */
3030
PyAPI_FUNC(Py_hash_t) _Py_HashDouble(PyObject *, double);
3131

32-
// Kept for backward compatibility
33-
#define _Py_HashPointer Py_HashPointer
34-
3532

3633
/* hash function definition */
3734
typedef struct {
@@ -44,6 +41,14 @@ typedef struct {
4441
PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
4542

4643
PyAPI_FUNC(Py_hash_t) Py_HashPointer(const void *ptr);
44+
45+
// Deprecated alias kept for backward compatibility
46+
Py_DEPRECATED(3.14) static inline Py_hash_t
47+
_Py_HashPointer(const void *ptr)
48+
{
49+
return Py_HashPointer(ptr);
50+
}
51+
4752
PyAPI_FUNC(Py_hash_t) PyObject_GenericHash(PyObject *);
4853

4954
PyAPI_FUNC(Py_hash_t) Py_HashBuffer(const void *ptr, Py_ssize_t len);

Include/cpython/pystate.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,12 @@ struct _ts {
239239
* if it is NULL. */
240240
PyAPI_FUNC(PyThreadState *) PyThreadState_GetUnchecked(void);
241241

242-
// Alias kept for backward compatibility
243-
#define _PyThreadState_UncheckedGet PyThreadState_GetUnchecked
242+
// Deprecated alias kept for backward compatibility
243+
Py_DEPRECATED(3.14) static inline PyThreadState*
244+
_PyThreadState_UncheckedGet(void)
245+
{
246+
return PyThreadState_GetUnchecked();
247+
}
244248

245249

246250
// Disable tracing and profiling.

Include/cpython/unicodeobject.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,12 @@ _PyUnicodeWriter_Dealloc(_PyUnicodeWriter *writer);
630630

631631
PyAPI_FUNC(const char *) PyUnicode_AsUTF8(PyObject *unicode);
632632

633-
// Alias kept for backward compatibility
634-
#define _PyUnicode_AsString PyUnicode_AsUTF8
633+
// Deprecated alias kept for backward compatibility
634+
Py_DEPRECATED(3.14) static inline const char*
635+
_PyUnicode_AsString(PyObject *unicode)
636+
{
637+
return PyUnicode_AsUTF8(unicode);
638+
}
635639

636640

637641
/* === Characters Type APIs =============================================== */

Lib/test/audit-tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class C(A):
187187

188188

189189
def test_open(testfn):
190-
# SSLContext.load_dh_params uses _Py_fopen_obj rather than normal open()
190+
# SSLContext.load_dh_params uses Py_fopen() rather than normal open()
191191
try:
192192
import ssl
193193

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
The following private functions are deprecated and planned for removal in
2+
Python 3.18:
3+
4+
* :c:func:`!_PyBytes_Join`: use :c:func:`PyBytes_Join`.
5+
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
6+
* :c:func:`!_PyDict_Pop()`: use :c:func:`PyDict_Pop`.
7+
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
8+
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
9+
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
10+
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.
11+
12+
The `pythoncapi-compat project
13+
<https://github.com/python/pythoncapi-compat/>`__ can be used to get these new
14+
public functions on Python 3.13 and older.
15+
16+
Patch by Victor Stinner.

0 commit comments

Comments
 (0)