Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
gh-111789: Use PyDict_GetItemRef() in sqlite
  • Loading branch information
serhiy-storchaka committed Nov 7, 2023
commit e8e8aa0e7a9db9a999651b701e5f4317e4d6a999
8 changes: 2 additions & 6 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,8 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
if (!binding_name_obj) {
return;
}
if (PyDict_CheckExact(parameters)) {
PyObject *item = PyDict_GetItemWithError(parameters, binding_name_obj);
current_param = Py_XNewRef(item);
} else {
current_param = PyObject_GetItem(parameters, binding_name_obj);
}
PyObject *current_param;
(void)PyMapping_GetOptionalItem(parameters, binding_name_obj, &current_param);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyMapping_GetOptionalItem() includes a special case for dict, so there is no performance loss.

Py_DECREF(binding_name_obj);
if (!current_param) {
if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_LookupError)) {
Expand Down
8 changes: 3 additions & 5 deletions Modules/_sqlite/microprotocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,15 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
if (!key) {
return NULL;
}
adapter = PyDict_GetItemWithError(state->psyco_adapters, key);
if (PyDict_GetItemRef(state->psyco_adapters, key, &adapter) < 0) {
return NULL;
}
Py_DECREF(key);
if (adapter) {
Py_INCREF(adapter);
adapted = PyObject_CallOneArg(adapter, obj);
Py_DECREF(adapter);
return adapted;
}
if (PyErr_Occurred()) {
return NULL;
}

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