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

GH-99293: Fix stale method caches and assertion errors in SWIG-generated modules#99294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Yhg1s wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromYhg1s:fix_assertion_errors
Open
Show file tree
Hide file tree
Changes fromall commits
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Fix an issue where extension modules could inadvertently trigger an assertion error in typeobject.c by clearing the Py_TPFLAGS_VALID_VERSION_TAG tp_flag without clearing the tp_version_tag field. (Extension modules should use PyType_Modified() instead, however.)

Choose a reason for hiding this comment

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

I just noticedPy_TPFLAGS_VALID_VERSION_TAG isn't actually documented.

Suggested change
Fix an issue where extension modules could inadvertently trigger an assertion error in typeobject.c by clearing the Py_TPFLAGS_VALID_VERSION_TAG tp_flag without clearing the tp_version_tag field. (Extension modules should use PyType_Modified() instead, however.)
Fix an issue where extension modules could inadvertently trigger an assertion error in``typeobject.c`` by clearing the``Py_TPFLAGS_VALID_VERSION_TAG``:c:member:`~PyTypeObject.tp_flags` without clearing the:c:member:`~PyTypeObject.tp_version_tag` field. (Extension modules should use:c:func:`PyType_Modified` instead, however.)

9 changes: 7 additions & 2 deletionsObjects/typeobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4176,12 +4176,17 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
unsigned int h = MCACHE_HASH_METHOD(type, name);
struct type_cache *cache = get_type_cache();
struct type_cache_entry *entry = &cache->hashtable[h];
/* Some extension modules (e.g. those generated by SWIG) don't always
* change/clear tp_version_tag when they clear the
* Py_TPFLAGS_VALID_VERSION_TAG tp_flag, so check both tp_version_tag
* and the tp_flag. (Invalidated cache entries are replaced below.)
*/
if (entry->version == type->tp_version_tag &&
entry->name == name) {
entry->name == name &&
_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) {
#if MCACHE_STATS
cache->hits++;
#endif
assert(_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG));
return entry->value;
}

Copy link
Member

@Fidget-SpinnerFidget-SpinnerNov 9, 2022
edited
Loading

Choose a reason for hiding this comment

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

For other reviewers wondering what happens down this code path ifPy_TPFLAGS_VALID_VERSION_TAG is not set:

  1. A normal lookup happens where we walk the MRO.
  2. We assign a new version tag to the type. This setsPy_TPFLAGS_VALID_VERSION_TAG.

So this should be safe.

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp