8000 gh-134043: use `_PyObject_GetMethodStackRef` in pattern matching by kumaraditya303 · Pull Request #136356 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134043: use _PyObject_GetMethodStackRef in pattern matching #136356

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
Merged
Changes from all 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
10 changes: 6 additions & 4 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,14 @@ _PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys)
PyObject *seen = NULL;
PyObject *dummy = NULL;
PyObject *values = NULL;
PyObject *get = NULL;
// We use the two argument form of map.get(key, default) for two reasons:
// - Atomically check for a key and get its value without error handling.
// - Don't cause key creation or resizing in dict subclasses like
// collections.defaultdict that define __missing__ (or similar).
int meth_found = _PyObject_GetMethod(map, &_Py_ID(get), &get);
_PyCStackRef cref;
_PyThreadState_PushCStackRef(tstate, &cref);
int meth_found = _PyObject_GetMethodStackRef(tstate, map, &_Py_ID(get), &cref.ref);
PyObject *get = PyStackRef_AsPyObjectBorrow(cref.ref);
if (get == NULL) {
goto fail;
}
Expand Down Expand Up @@ -682,12 +684,12 @@ _PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys)
}
// Success:
done:
Py_DECREF(get);
_PyThreadState_PopCStackRef(tstate, &cref);
Py_DECREF(seen);
Py_DECREF(dummy);
return values;
fail:
Py_XDECREF(get);
_PyThreadState_PopCStackRef(tstate, &cref);
Py_XDECREF(seen);
Py_XDECREF(dummy);
Py_XDECREF(values);
Expand Down
Loading
0