Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
The simple method cache in typeobject.c uses thetp_version_tag field and thePy_TPFLAGS_VALID_VERSION_TAG bit in thetp_flags field to track changes on the type that might invalidate the cache. Unfortunately the code currently assumes that any code clearing the tp_flagalso clears the tp_version_tag, and checks this assumption with an assert. Unfortunately, many SWIG-generated extension modules violate this assertion.
SWIG prior to 4.1.0 cleared the tp_flags bit without touching the tp_version_tag field (https://github.com/swig/swig/blob/v4.0.2/Lib/python/pyrun.swg#L1230). This was unintentionally fixed in 4.1.0 by usingPyType_Modified() instead, but unfortunately there are a great many SWIG-generated extension modules checked in all over the place (e.g.https://github.com/OSGeo/gdal/blob/6bd07b20b3e55c2fc94da611244a615a4fd2991f/swig/python/extensions/osr_wrap.cpp#L2296) so we cannot assumetp_version_tag is changed when thetp_flag bit is cleared.
The end result is an assertion error when assertions are enabled (I would implore everyone to run tests with assertions enabled...), or potentially a stale cache entry when they are not. It's hard to gauge the likelihood of the stale cache entries. In the case of SWIG it's extremely unlikely, as SWIG merely sets thethis attribute on the type, which is not likely to be cached or looked up with_PyType_Lookup. For other cases where extension modules clear thetp_flag bit without changing thetp_version_tag it might be more likely.
(I have a PR to fix this already.)