aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/generated_cases.c.h
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-11-14 15:38:49 +0200
committerGitHub <noreply@github.com>2023-11-14 15:38:49 +0200
commitb11c443bb2ebfdd009e43ff208fa6324b658d15d (patch)
treebe88b76437cb273397ad5276796c008434e8ea6a /Python/generated_cases.c.h
parent4f04172c9287c507f1426e02ddfc432f1f3ade54 (diff)
downloadcpython-b11c443bb2ebfdd009e43ff208fa6324b658d15d.tar.gz
cpython-b11c443bb2ebfdd009e43ff208fa6324b658d15d.zip
gh-111789: Simplify bytecodes.c by using PyDict_GetItemRef() (GH-111978)
Diffstat (limited to 'Python/generated_cases.c.h')
-rw-r--r--Python/generated_cases.c.h64
1 files changed, 17 insertions, 47 deletions
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index b9a2b227549..6cbc54c8e62 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -896,18 +896,13 @@
dict = stack_pointer[-2];
DEOPT_IF(!PyDict_CheckExact(dict), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
- res = PyDict_GetItemWithError(dict, sub);
- if (res == NULL) {
- if (!_PyErr_Occurred(tstate)) {
- _PyErr_SetKeyError(sub);
- }
- Py_DECREF(dict);
- Py_DECREF(sub);
- if (true) goto pop_2_error;
+ int rc = PyDict_GetItemRef(dict, sub, &res);
+ if (rc == 0) {
+ _PyErr_SetKeyError(sub);
}
- Py_INCREF(res); // Do this before DECREF'ing dict, sub
Py_DECREF(dict);
Py_DECREF(sub);
+ if (rc <= 0) goto pop_2_error;
STACK_SHRINK(1);
stack_pointer[-1] = res;
DISPATCH();
@@ -1950,14 +1945,10 @@
GOTO_ERROR(error);
}
if (v == NULL) {
- v = PyDict_GetItemWithError(GLOBALS(), name);
- if (v != NULL) {
- Py_INCREF(v);
- }
- else if (_PyErr_Occurred(tstate)) {
+ if (PyDict_GetItemRef(GLOBALS(), name, &v) < 0) {
GOTO_ERROR(error);
}
- else {
+ if (v == NULL) {
if (PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0) {
GOTO_ERROR(error);
}
@@ -1990,14 +1981,10 @@
GOTO_ERROR(error);
}
if (v == NULL) {
- v = PyDict_GetItemWithError(GLOBALS(), name);
- if (v != NULL) {
- Py_INCREF(v);
- }
- else if (_PyErr_Occurred(tstate)) {
+ if (PyDict_GetItemRef(GLOBALS(), name, &v) < 0) {
GOTO_ERROR(error);
}
- else {
+ if (v == NULL) {
if (PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0) {
GOTO_ERROR(error);
}
@@ -2422,34 +2409,17 @@
if (true) goto error;
}
/* check if __annotations__ in locals()... */
- if (PyDict_CheckExact(LOCALS())) {
- ann_dict = _PyDict_GetItemWithError(LOCALS(),
- &_Py_ID(__annotations__));
- if (ann_dict == NULL) {
- if (_PyErr_Occurred(tstate)) goto error;
- /* ...if not, create a new one */
- ann_dict = PyDict_New();
- if (ann_dict == NULL) goto error;
- err = PyDict_SetItem(LOCALS(), &_Py_ID(__annotations__),
- ann_dict);
- Py_DECREF(ann_dict);
- if (err) goto error;
- }
+ if (PyMapping_GetOptionalItem(LOCALS(), &_Py_ID(__annotations__), &ann_dict) < 0) goto error;
+ if (ann_dict == NULL) {
+ ann_dict = PyDict_New();
+ if (ann_dict == NULL) goto error;
+ err = PyObject_SetItem(LOCALS(), &_Py_ID(__annotations__),
+ ann_dict);
+ Py_DECREF(ann_dict);
+ if (err) goto error;
}
else {
- /* do the same if locals() is not a dict */
- if (PyMapping_GetOptionalItem(LOCALS(), &_Py_ID(__annotations__), &ann_dict) < 0) goto error;
- if (ann_dict == NULL) {
- ann_dict = PyDict_New();
- if (ann_dict == NULL) goto error;
- err = PyObject_SetItem(LOCALS(), &_Py_ID(__annotations__),
- ann_dict);
- Py_DECREF(ann_dict);
- if (err) goto error;
- }
- else {
- Py_DECREF(ann_dict);
- }
+ Py_DECREF(ann_dict);
}
DISPATCH();
}