Skip to content

gh-111789: Use PyDict_GetItemRef() in sqlite #111829

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
Show file tree
Hide file tree
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
14 changes: 2 additions & 12 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,6 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
} else if (PyDict_Check(parameters)) {
/* parameters passed as dictionary */
for (i = 1; i <= num_params_needed; i++) {
PyObject *binding_name_obj;
Py_BEGIN_ALLOW_THREADS
binding_name = sqlite3_bind_parameter_name(self->st, i);
Py_END_ALLOW_THREADS
Expand All @@ -733,17 +732,8 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
}

binding_name++; /* skip first char (the colon) */
binding_name_obj = PyUnicode_FromString(binding_name);
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);
}
Py_DECREF(binding_name_obj);
PyObject *current_param;
(void)PyMapping_GetOptionalItemString(parameters, binding_name, &current_param);
if (!current_param) {
if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_LookupError)) {
PyErr_Format(state->ProgrammingError,
Expand Down
9 changes: 4 additions & 5 deletions Modules/_sqlite/microprotocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,16 @@ 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) {
Py_DECREF(key);
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