aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Modules/_sqlite/module.c
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2022-02-16 16:24:44 +0100
committerGitHub <noreply@github.com>2022-02-17 00:24:44 +0900
commitb2077117d125925210148294eefee28797b7ff4c (patch)
tree882ab0be1bbfa306c6f0371220947c5fcc8ca848 /Modules/_sqlite/module.c
parentd64f3caebe8f8e31ecd193e0bd25105400153ece (diff)
downloadcpython-b2077117d125925210148294eefee28797b7ff4c.tar.gz
cpython-b2077117d125925210148294eefee28797b7ff4c.zip
bpo-46541: Replace _Py_IDENTIFIER with _Py_ID in sqlite3 (GH-31351)
Diffstat (limited to 'Modules/_sqlite/module.c')
-rw-r--r--Modules/_sqlite/module.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index cfa4b970e73..35cdcbe0a5c 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -21,8 +21,6 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
-#define NEEDS_PY_IDENTIFIER
-
#include "connection.h"
#include "statement.h"
#include "cursor.h"
@@ -185,15 +183,14 @@ pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name,
{
PyObject* name = NULL;
PyObject* retval = NULL;
- _Py_IDENTIFIER(upper);
/* convert the name to upper case */
- name = _PyObject_CallMethodIdNoArgs(orig_name, &PyId_upper);
+ pysqlite_state *state = pysqlite_get_state(module);
+ name = PyObject_CallMethodNoArgs(orig_name, state->str_upper);
if (!name) {
goto error;
}
- pysqlite_state *state = pysqlite_get_state(module);
if (PyDict_SetItem(state->converters, name, callable) != 0) {
goto error;
}
@@ -593,6 +590,13 @@ module_traverse(PyObject *module, visitproc visit, void *arg)
Py_VISIT(state->lru_cache);
Py_VISIT(state->psyco_adapters);
+ // Interned strings
+ Py_VISIT(state->str___adapt__);
+ Py_VISIT(state->str___conform__);
+ Py_VISIT(state->str_executescript);
+ Py_VISIT(state->str_finalize);
+ Py_VISIT(state->str_upper);
+
return 0;
}
@@ -625,6 +629,13 @@ module_clear(PyObject *module)
Py_CLEAR(state->lru_cache);
Py_CLEAR(state->psyco_adapters);
+ // Interned strings
+ Py_CLEAR(state->str___adapt__);
+ Py_CLEAR(state->str___conform__);
+ Py_CLEAR(state->str_executescript);
+ Py_CLEAR(state->str_finalize);
+ Py_CLEAR(state->str_upper);
+
return 0;
}
@@ -650,6 +661,15 @@ do { \
ADD_TYPE(module, (PyTypeObject *)state->exc); \
} while (0)
+#define ADD_INTERNED(state, string) \
+do { \
+ PyObject *tmp = PyUnicode_InternFromString(#string); \
+ if (tmp == NULL) { \
+ goto error; \
+ } \
+ state->str_ ## string = tmp; \
+} while (0)
+
static int
module_exec(PyObject *module)
{
@@ -695,6 +715,13 @@ module_exec(PyObject *module)
ADD_EXCEPTION(module, state, DataError, state->DatabaseError);
ADD_EXCEPTION(module, state, NotSupportedError, state->DatabaseError);
+ /* Add interned strings */
+ ADD_INTERNED(state, __adapt__);
+ ADD_INTERNED(state, __conform__);
+ ADD_INTERNED(state, executescript);
+ ADD_INTERNED(state, finalize);
+ ADD_INTERNED(state, upper);
+
/* Set error constants */
if (add_error_constants(module) < 0) {
goto error;