From 7f95ec3e7405ea5f44adc3584e297a3191118f32 Mon Sep 17 00:00:00 2001 From: ram vikram singh Date: Tue, 24 Jan 2023 14:59:22 +0530 Subject: [PATCH] gh-101152: Implement PEP 699 (GH-101193) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Ken Jin --- Doc/whatsnew/3.12.rst | 5 +++++ Include/cpython/dictobject.h | 4 ++++ .../Build/2023-01-21-10-31-35.gh-issue-101152.xvM8pL.rst | 3 +++ Modules/_testcapimodule.c | 3 +++ 4 files changed, 15 insertions(+) create mode 100644 Misc/NEWS.d/next/Build/2023-01-21-10-31-35.gh-issue-101152.xvM8pL.rst diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 3cab8971245..2f9ca1102d3 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -430,6 +430,11 @@ Deprecated Before, the Python implementation emitted :exc:`FutureWarning`, and the C implementation emitted nothing. +* In accordance with :pep:`699`, the ``ma_version_tag`` field in :c:type:`PyDictObject` + is deprecated for extension modules. Accessing this field will generate a compiler + warning at compile time. This field will be removed in Python 3.14. + (Contributed by Ramvikrams and Kumar Aditya in :gh:`101193`. PEP by Ken Jin.) + Pending Removal in Python 3.13 ------------------------------ diff --git a/Include/cpython/dictobject.h b/Include/cpython/dictobject.h index 2dff59ef0b8..5001f356544 100644 --- a/Include/cpython/dictobject.h +++ b/Include/cpython/dictobject.h @@ -16,7 +16,11 @@ typedef struct { /* Dictionary version: globally unique, value change each time the dictionary is modified */ +#ifdef Py_BUILD_CORE uint64_t ma_version_tag; +#else + Py_DEPRECATED(3.12) uint64_t ma_version_tag; +#endif PyDictKeysObject *ma_keys; diff --git a/Misc/NEWS.d/next/Build/2023-01-21-10-31-35.gh-issue-101152.xvM8pL.rst b/Misc/NEWS.d/next/Build/2023-01-21-10-31-35.gh-issue-101152.xvM8pL.rst new file mode 100644 index 00000000000..e35b6178aa4 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2023-01-21-10-31-35.gh-issue-101152.xvM8pL.rst @@ -0,0 +1,3 @@ +In accordance with :PEP:`699`, the ``ma_version_tag`` field in :c:type:`PyDictObject` +is deprecated for extension modules. Accessing this field will generate a compiler +warning at compile time. This field will be removed in Python 3.14. diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 486988b4e34..46c025bf534 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2148,7 +2148,10 @@ dict_get_version(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) return NULL; + _Py_COMP_DIAG_PUSH + _Py_COMP_DIAG_IGNORE_DEPR_DECLS version = dict->ma_version_tag; + _Py_COMP_DIAG_POP static_assert(sizeof(unsigned long long) >= sizeof(version), "version is larger than unsigned long long");