Skip to content

Commit 988d5cb

Browse files
yoneymeta-codesync[bot]
authored andcommitted
Address tsan warning in LOAD_GLOBAL lazy import check
Summary: Address tsan warning by checking lazy import status on validated stack reference `res` instead of raw pointer `res_o`. ThreadSanitizer: data race buck-out/v2/art/fbsource/third-party/python/3.14/patched/__python-headersFbcode__/4e20ba490b623089/buck-headers/object.h:270 in _Py_TYPE ================== ``` Reviewed By: alexmalyshev, itamaro Differential Revision: D95939637 fbshipit-source-id: a9b8271d11b76e7856276bbf46b566040415eff7
1 parent 3b6bed0 commit 988d5cb

2 files changed

Lines changed: 60 additions & 18 deletions

File tree

Python/bytecodes.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,13 +1809,19 @@ dummy_func(
18091809
assert(index < DK_SIZE(keys));
18101810
PyObject *res_o = FT_ATOMIC_LOAD_PTR_RELAXED(entries[index].me_value);
18111811
DEOPT_IF(res_o == NULL);
1812-
#ifdef META_PYTHON
1813-
DEOPT_IF(PyLazyImport_CheckExact(res_o));
1814-
#endif
18151812
#if Py_GIL_DISABLED
18161813
int increfed = _Py_TryIncrefCompareStackRef(&entries[index].me_value, res_o, &res);
18171814
DEOPT_IF(!increfed);
1815+
#ifdef META_PYTHON
1816+
if (PyLazyImport_CheckExact(PyStackRef_AsPyObjectBorrow(res))) {
1817+
PyStackRef_CLOSE(res);
1818+
DEOPT_IF(true);
1819+
}
1820+
#endif
18181821
#else
1822+
#ifdef META_PYTHON
1823+
DEOPT_IF(PyLazyImport_CheckExact(res_o));
1824+
#endif
18191825
res = PyStackRef_FromPyObjectNew(res_o);
18201826
#endif
18211827
STAT_INC(LOAD_GLOBAL, hit);
@@ -1831,13 +1837,19 @@ dummy_func(
18311837
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(keys);
18321838
PyObject *res_o = FT_ATOMIC_LOAD_PTR_RELAXED(entries[index].me_value);
18331839
DEOPT_IF(res_o == NULL);
1834-
#ifdef META_PYTHON
1835-
DEOPT_IF(PyLazyImport_CheckExact(res_o));
1836-
#endif
18371840
#if Py_GIL_DISABLED
18381841
int increfed = _Py_TryIncrefCompareStackRef(&entries[index].me_value, res_o, &res);
18391842
DEOPT_IF(!increfed);
1843+
#ifdef META_PYTHON
1844+
if (PyLazyImport_CheckExact(PyStackRef_AsPyObjectBorrow(res))) {
1845+
PyStackRef_CLOSE(res);
1846+
DEOPT_IF(true);
1847+
}
1848+
#endif
18401849
#else
1850+
#ifdef META_PYTHON
1851+
DEOPT_IF(PyLazyImport_CheckExact(res_o));
1852+
#endif
18411853
res = PyStackRef_FromPyObjectNew(res_o);
18421854
#endif
18431855
STAT_INC(LOAD_GLOBAL, hit);

Python/generated_cases.c.h

Lines changed: 42 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)