Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit043db41

Browse files
committed
gh-124296: Remove private dictionary version tag (PEP 699)
1 parentf4997bb commit043db41

File tree

13 files changed

+35
-354
lines changed

13 files changed

+35
-354
lines changed

‎Include/cpython/dictobject.h‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@ typedef struct {
1414
/* Number of items in the dictionary */
1515
Py_ssize_tma_used;
1616

17-
/* Dictionary version: globally unique, value change each time
18-
the dictionary is modified */
19-
#ifdefPy_BUILD_CORE
20-
/* Bits 0-7 are for dict watchers.
17+
/* This is a private field for CPython's internal use.
18+
* Bits 0-7 are for dict watchers.
2119
* Bits 8-11 are for the watched mutation counter (used by tier2 optimization)
22-
* The remaining bits (12-63) are the actual version tag. */
23-
uint64_tma_version_tag;
24-
#else
25-
Py_DEPRECATED(3.12)uint64_tma_version_tag;
26-
#endif
20+
* The remaining bits are not currently used. */
21+
uint64_tma_watcher_tag;
2722

2823
PyDictKeysObject*ma_keys;
2924

‎Include/internal/pycore_dict.h‎

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -230,31 +230,6 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) {
230230
#defineDICT_WATCHER_MASK ((1 << DICT_MAX_WATCHERS) - 1)
231231
#defineDICT_WATCHER_AND_MODIFICATION_MASK ((1 << (DICT_MAX_WATCHERS + DICT_WATCHED_MUTATION_BITS)) - 1)
232232

233-
#ifdefPy_GIL_DISABLED
234-
235-
#defineTHREAD_LOCAL_DICT_VERSION_COUNT 256
236-
#defineTHREAD_LOCAL_DICT_VERSION_BATCH THREAD_LOCAL_DICT_VERSION_COUNT * DICT_VERSION_INCREMENT
237-
238-
staticinlineuint64_t
239-
dict_next_version(PyInterpreterState*interp)
240-
{
241-
PyThreadState*tstate=PyThreadState_GET();
242-
uint64_tcur_progress= (tstate->dict_global_version&
243-
(THREAD_LOCAL_DICT_VERSION_BATCH-1));
244-
if (cur_progress==0) {
245-
uint64_tnext=_Py_atomic_add_uint64(&interp->dict_state.global_version,
246-
THREAD_LOCAL_DICT_VERSION_BATCH);
247-
tstate->dict_global_version=next;
248-
}
249-
returntstate->dict_global_version+=DICT_VERSION_INCREMENT;
250-
}
251-
252-
#defineDICT_NEXT_VERSION(INTERP) dict_next_version(INTERP)
253-
254-
#else
255-
#defineDICT_NEXT_VERSION(INTERP) \
256-
((INTERP)->dict_state.global_version += DICT_VERSION_INCREMENT)
257-
#endif
258233

259234
PyAPI_FUNC(void)
260235
_PyDict_SendEvent(intwatcher_bits,
@@ -263,20 +238,19 @@ _PyDict_SendEvent(int watcher_bits,
263238
PyObject*key,
264239
PyObject*value);
265240

266-
staticinlineuint64_t
241+
staticinlinevoid
267242
_PyDict_NotifyEvent(PyInterpreterState*interp,
268243
PyDict_WatchEventevent,
269244
PyDictObject*mp,
270245
PyObject*key,
271246
PyObject*value)
272247
{
273248
assert(Py_REFCNT((PyObject*)mp)>0);
274-
intwatcher_bits=mp->ma_version_tag&DICT_WATCHER_MASK;
249+
intwatcher_bits=mp->ma_watcher_tag&DICT_WATCHER_MASK;
275250
if (watcher_bits) {
276251
RARE_EVENT_STAT_INC(watched_dict_modification);
277252
_PyDict_SendEvent(watcher_bits,event,mp,key,value);
278253
}
279-
returnDICT_NEXT_VERSION(interp) | (mp->ma_version_tag&DICT_WATCHER_AND_MODIFICATION_MASK);
280254
}
281255

282256
externPyDictObject*_PyObject_MaterializeManagedDict(PyObject*obj);

‎Include/internal/pycore_dict_state.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ extern "C" {
1212
#defineDICT_WATCHED_MUTATION_BITS 4
1313

1414
struct_Py_dict_state {
15-
/*Global counter used to set ma_version_tag field of dictionary.
16-
* It is incremented each time that a dictionary is created and each
17-
* time that a dictionary is modified. */
18-
uint64_tglobal_version;
1915
uint32_tnext_keys_version;
2016
PyDict_WatchCallbackwatchers[DICT_MAX_WATCHERS];
2117
};

‎Lib/test/test_dict_version.py‎

Lines changed: 0 additions & 191 deletions
This file was deleted.

‎Lib/test/test_free_threading/test_dict.py‎

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -142,41 +142,6 @@ def writer_func(l):
142142
forrefinthread_list:
143143
self.assertIsNone(ref())
144144

145-
@unittest.skipIf(_testcapiisNone,'need _testcapi module')
146-
deftest_dict_version(self):
147-
dict_version=_testcapi.dict_version
148-
THREAD_COUNT=10
149-
DICT_COUNT=10000
150-
lists= []
151-
writers= []
152-
153-
defwriter_func(thread_list):
154-
foriinrange(DICT_COUNT):
155-
thread_list.append(dict_version({}))
156-
157-
forxinrange(THREAD_COUNT):
158-
thread_list= []
159-
lists.append(thread_list)
160-
writer=Thread(target=partial(writer_func,thread_list))
161-
writers.append(writer)
162-
163-
forwriterinwriters:
164-
writer.start()
165-
166-
forwriterinwriters:
167-
writer.join()
168-
169-
total_len=0
170-
values=set()
171-
forthread_listinlists:
172-
forvinthread_list:
173-
ifvinvalues:
174-
print('dup',v, (v/4096)%256)
175-
values.add(v)
176-
total_len+=len(thread_list)
177-
versions=set(dict_versionforthread_listinlistsfordict_versioninthread_list)
178-
self.assertEqual(len(versions),THREAD_COUNT*DICT_COUNT)
179-
180145

181146
if__name__=="__main__":
182147
unittest.main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:c:type:`PyDictObject` no longer maintains a private version tag field
2+
``ma_version_tag`` per:pep:`699`. This field was originally added in
3+
Python 3.6 (:pep:`509`) and deprecated in Python 3.12.

‎Modules/_testcapi/dict.c‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,6 @@ dict_popstring_null(PyObject *self, PyObject *args)
181181
RETURN_INT(PyDict_PopString(dict,key,NULL));
182182
}
183183

184-
staticPyObject*
185-
dict_version(PyObject*self,PyObject*dict)
186-
{
187-
if (!PyDict_Check(dict)) {
188-
PyErr_SetString(PyExc_TypeError,"expected dict");
189-
returnNULL;
190-
}
191-
_Py_COMP_DIAG_PUSH
192-
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
193-
returnPyLong_FromUnsignedLongLong(((PyDictObject*)dict)->ma_version_tag);
194-
_Py_COMP_DIAG_POP
195-
}
196-
197184
staticPyMethodDeftest_methods[]= {
198185
{"dict_containsstring",dict_containsstring,METH_VARARGS},
199186
{"dict_getitemref",dict_getitemref,METH_VARARGS},
@@ -204,7 +191,6 @@ static PyMethodDef test_methods[] = {
204191
{"dict_pop_null",dict_pop_null,METH_VARARGS},
205192
{"dict_popstring",dict_popstring,METH_VARARGS},
206193
{"dict_popstring_null",dict_popstring_null,METH_VARARGS},
207-
{"dict_version",dict_version,METH_O},
208194
{NULL},
209195
};
210196

‎Modules/_testcapimodule.c‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,25 +1909,6 @@ getitem_with_error(PyObject *self, PyObject *args)
19091909
returnPyObject_GetItem(map,key);
19101910
}
19111911

1912-
staticPyObject*
1913-
dict_get_version(PyObject*self,PyObject*args)
1914-
{
1915-
PyDictObject*dict;
1916-
uint64_tversion;
1917-
1918-
if (!PyArg_ParseTuple(args,"O!",&PyDict_Type,&dict))
1919-
returnNULL;
1920-
1921-
_Py_COMP_DIAG_PUSH
1922-
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
1923-
version=dict->ma_version_tag;
1924-
_Py_COMP_DIAG_POP
1925-
1926-
static_assert(sizeof(unsigned long long) >=sizeof(version),
1927-
"version is larger than unsigned long long");
1928-
returnPyLong_FromUnsignedLongLong((unsigned long long)version);
1929-
}
1930-
19311912

19321913
staticPyObject*
19331914
raise_SIGINT_then_send_None(PyObject*self,PyObject*args)
@@ -3407,7 +3388,6 @@ static PyMethodDef TestMethods[] = {
34073388
{"return_result_with_error",return_result_with_error,METH_NOARGS},
34083389
{"getitem_with_error",getitem_with_error,METH_VARARGS},
34093390
{"Py_CompileString",pycompilestring,METH_O},
3410-
{"dict_get_version",dict_get_version,METH_VARARGS},
34113391
{"raise_SIGINT_then_send_None",raise_SIGINT_then_send_None,METH_VARARGS},
34123392
{"stack_pointer",stack_pointer,METH_NOARGS},
34133393
#ifdefW_STOPCODE

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp