Skip to content

Commit e8e8aa0

Browse files
pythongh-111789: Use PyDict_GetItemRef() in sqlite
1 parent 178861b commit e8e8aa0

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

Modules/_sqlite/cursor.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,8 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
737737
if (!binding_name_obj) {
738738
return;
739739
}
740-
if (PyDict_CheckExact(parameters)) {
741-
PyObject *item = PyDict_GetItemWithError(parameters, binding_name_obj);
742-
current_param = Py_XNewRef(item);
743-
} else {
744-
current_param = PyObject_GetItem(parameters, binding_name_obj);
745-
}
740+
PyObject *current_param;
741+
(void)PyMapping_GetOptionalItem(parameters, binding_name_obj, &current_param);
746742
Py_DECREF(binding_name_obj);
747743
if (!current_param) {
748744
if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_LookupError)) {

Modules/_sqlite/microprotocols.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,15 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
8585
if (!key) {
8686
return NULL;
8787
}
88-
adapter = PyDict_GetItemWithError(state->psyco_adapters, key);
88+
if (PyDict_GetItemRef(state->psyco_adapters, key, &adapter) < 0) {
89+
return NULL;
90+
}
8991
Py_DECREF(key);
9092
if (adapter) {
91-
Py_INCREF(adapter);
9293
adapted = PyObject_CallOneArg(adapter, obj);
9394
Py_DECREF(adapter);
9495
return adapted;
9596
}
96-
if (PyErr_Occurred()) {
97-
return NULL;
98-
}
9997

10098
/* try to have the protocol adapt this object */
10199
if (PyObject_GetOptionalAttr(proto, state->str___adapt__, &adapter) < 0) {

0 commit comments

Comments
 (0)