Skip to content

Commit 55aa240

Browse files
committed
Address partial review
1 parent d0a9f07 commit 55aa240

File tree

8 files changed

+23
-63
lines changed

8 files changed

+23
-63
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_typeobject.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ typedef int (*_py_validate_type)(PyTypeObject *);
278278
// and if the validation is passed, it will set the ``tp_version`` as valid
279279
// tp_version_tag from the ``ty``.
280280
extern int _PyType_Validate(PyTypeObject *ty, _py_validate_type validate, unsigned int *tp_version);
281-
extern PyObject *_PyType_GetItemFromCache(PyTypeObject *type);
282-
extern PyObject *_PyType_GetItemFromCacheWithVersion(PyTypeObject *type, uint32_t *version);
283-
extern int _PyType_CacheGetItemForSpecialization(PyTypeObject *type, PyObject *descriptor);
281+
extern int _PyType_CacheGetItemForSpecialization(PyHeapTypeObject *ht, PyObject *descriptor);
284282

285283
#ifdef __cplusplus
286284
}

Include/internal/pycore_uop_metadata.h

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

Objects/typeobject.c

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5693,16 +5693,12 @@ _PyType_CacheInitForSpecialization(PyHeapTypeObject *type, PyObject *init,
56935693
}
56945694

56955695
int
5696-
_PyType_CacheGetItemForSpecialization(PyTypeObject *type, PyObject *descriptor)
5696+
_PyType_CacheGetItemForSpecialization(PyHeapTypeObject *ht, PyObject *descriptor)
56975697
{
56985698
int ret = 0;
5699-
if (!type) {
5700-
return -1;
5701-
}
57025699
BEGIN_TYPE_LOCK();
57035700
// This pointer is invalidated by PyType_Modified (see the comment on
57045701
// struct _specialization_cache):
5705-
PyHeapTypeObject *ht = (PyHeapTypeObject *)type;
57065702
PyFunctionObject *func = (PyFunctionObject *)descriptor;
57075703
uint32_t version = _PyFunction_GetVersionForCurrentState(func);
57085704
if (!_PyFunction_IsVersionValid(version)) {
@@ -5716,40 +5712,6 @@ _PyType_CacheGetItemForSpecialization(PyTypeObject *type, PyObject *descriptor)
57165712
return ret;
57175713
}
57185714

5719-
PyObject *
5720-
_PyType_GetItemFromCache(PyTypeObject *type)
5721-
{
5722-
PyObject *res = NULL;
5723-
BEGIN_TYPE_LOCK();
5724-
PyHeapTypeObject *ht = (PyHeapTypeObject *)type;
5725-
res = ht->_spec_cache.getitem;
5726-
if (res == NULL || !PyFunction_Check(res)) {
5727-
res = NULL;
5728-
}
5729-
END_TYPE_LOCK();
5730-
return res;
5731-
}
5732-
5733-
PyObject *
5734-
_PyType_GetItemFromCacheWithVersion(PyTypeObject *type, uint32_t *version)
5735-
{
5736-
PyObject *res = NULL;
5737-
BEGIN_TYPE_LOCK();
5738-
PyHeapTypeObject *ht = (PyHeapTypeObject *)type;
5739-
res = ht->_spec_cache.getitem;
5740-
if (res == NULL) {
5741-
goto end;
5742-
}
5743-
if (!PyFunction_Check(res)) {
5744-
res = NULL;
5745-
goto end;
5746-
}
5747-
*version = ht->_spec_cache.getitem_version;
5748-
end:
5749-
END_TYPE_LOCK();
5750-
return res;
5751-
}
5752-
57535715
static void
57545716
set_flags(PyTypeObject *self, unsigned long mask, unsigned long flags)
57555717
{

Python/bytecodes.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,10 +867,11 @@ dummy_func(
867867
op(_BINARY_SUBSCR_CHECK_FUNC, (container, unused -- container, unused)) {
868868
PyTypeObject *tp = Py_TYPE(PyStackRef_AsPyObjectBorrow(container));
869869
DEOPT_IF(!PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE));
870-
uint32_t cached_version;
871-
PyObject *getitem = _PyType_GetItemFromCacheWithVersion(tp, &cached_version);
870+
PyHeapTypeObject *ht = (PyHeapTypeObject *)tp;
871+
PyObject *getitem = FT_ATOMIC_LOAD_PTR_RELAXED(ht->_spec_cache.getitem);
872872
DEOPT_IF(getitem == NULL);
873873
assert(PyFunction_Check(getitem));
874+
uint32_t cached_version = FT_ATOMIC_LOAD_UINT32_RELAXED(ht->_spec_cache.getitem_version);
874875
DEOPT_IF(((PyFunctionObject *)getitem)->func_version != cached_version);
875876
PyCodeObject *code = (PyCodeObject *)PyFunction_GET_CODE(getitem);
876877
assert(code->co_argcount == 2);
@@ -880,7 +881,8 @@ dummy_func(
880881

881882
op(_BINARY_SUBSCR_INIT_CALL, (container, sub -- new_frame: _PyInterpreterFrame* )) {
882883
PyTypeObject *tp = Py_TYPE(PyStackRef_AsPyObjectBorrow(container));
883-
PyObject *getitem = _PyType_GetItemFromCache(tp);
884+
PyHeapTypeObject *ht = (PyHeapTypeObject *)tp;
885+
PyObject *getitem = FT_ATOMIC_LOAD_PTR_RELAXED(ht->_spec_cache.getitem);
884886
DEOPT_IF(getitem == NULL);
885887
new_frame = _PyFrame_PushUnchecked(tstate, PyStackRef_FromPyObjectNew(getitem), 2, frame);
886888
new_frame->localsplus[0] = container;

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

Python/specialize.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,9 @@ _Py_Specialize_BinarySubscr(
17801780
SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
17811781
goto fail;
17821782
}
1783-
if (_PyType_CacheGetItemForSpecialization(container_type, descriptor) < 0) {
1783+
1784+
PyHeapTypeObject *ht = (PyHeapTypeObject *)container_type;
1785+
if (_PyType_CacheGetItemForSpecialization(ht, descriptor) < 0) {
17841786
SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OUT_OF_VERSIONS);
17851787
goto fail;
17861788
}

0 commit comments

Comments
 (0)