diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-11-10 20:49:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 20:49:24 (GMT) |
commit | afac3c9b7eace4a3e503e93bb76eda32d8217ad7 (patch) | |
tree | 7b5a24775041e6667e89180e682d58dd26ff67cf /Modules | |
parent | 771bd3c94a366547e0c3451a72a430e1132c1ac1 (diff) | |
download | cpython-afac3c9b7eace4a3e503e93bb76eda32d8217ad7.zip cpython-afac3c9b7eace4a3e503e93bb76eda32d8217ad7.tar.gz cpython-afac3c9b7eace4a3e503e93bb76eda32d8217ad7.tar.bz2 |
gh-111789: Simplify the sqlite code (GH-111829)
Use new C API functions PyDict_GetItemRef() and
PyMapping_GetOptionalItemString().
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sqlite/cursor.c | 14 | ||||
-rw-r--r-- | Modules/_sqlite/microprotocols.c | 9 |
2 files changed, 6 insertions, 17 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 618ce53..f95df61 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -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 @@ -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, ¤t_param); if (!current_param) { if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_LookupError)) { PyErr_Format(state->ProgrammingError, diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c index 92f0148..f77458d 100644 --- a/Modules/_sqlite/microprotocols.c +++ b/Modules/_sqlite/microprotocols.c @@ -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) { |