8000 gh-134043: use `_PyObject_GetMethodStackRef` in pattern matching (#13… · python/cpython@89f06a3 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 89f06a3

Browse files
gh-134043: use _PyObject_GetMethodStackRef in pattern matching (#136356)
1 parent 5b78c85 commit 89f06a3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Python/ceval.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,14 @@ _PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys)
627627
PyObject *seen = NULL;
628628
PyObject *dummy = NULL;
629629
PyObject *values = NULL;
630-
PyObject *get = NULL;
631630
// We use the two argument form of map.get(key, default) for two reasons:
632631
// - Atomically check for a key and get its value without error handling.
633632
// - Don't cause key creation or resizing in dict subclasses like
634633
// collections.defaultdict that define __missing__ (or similar).
635-
int meth_found = _PyObject_GetMethod(map, &_Py_ID(get), &get);
634+
_PyCStackRef cref;
635+
_PyThreadState_PushCStackRef(tstate, &cref);
636+
int meth_found = _PyObject_GetMethodStackRef(tstate, map, &_Py_ID(get), &cref.ref);
637+
PyObject *get = PyStackRef_AsPyObjectBorrow(cref.ref);
636638
if (get == NULL) {
637639
goto fail;
638640
}
@@ -682,12 +684,12 @@ _PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys)
682684
}
683685
// Success:
684686
done:
685-
Py_DECREF(get);
687+
_PyThreadState_PopCStackRef(tstate, &cref);
686688
Py_DECREF(seen);
687689
Py_DECREF(dummy);
688690
return values;
689691
fail:
690-
Py_XDECREF(get);
692+
_PyThreadState_PopCStackRef(tstate, &cref);
691693
Py_XDECREF(seen);
692694
Py_XDECREF(dummy);
693695
Py_XDECREF(values);

0 commit comments

Comments
 (0)
0