* 3. This notice may not be removed or altered from any source distribution.
*/
-#define NEEDS_PY_IDENTIFIER
-
#include "module.h"
#include "structmember.h" // PyMemberDef
#include "connection.h"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=67369db2faf80891]*/
-_Py_IDENTIFIER(cursor);
-
static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
static void free_callback_context(callback_context *ctx);
static void set_callback_context(callback_context **ctx_pp,
callback_context *ctx);
static void connection_close(pysqlite_Connection *self);
+PyObject *_pysqlite_query_execute(pysqlite_Cursor *, int, PyObject *, PyObject *);
static PyObject *
new_statement_cache(pysqlite_Connection *self, pysqlite_state *state,
PyObject* function_result;
PyObject** aggregate_instance;
- _Py_IDENTIFIER(finalize);
int ok;
PyObject *exception, *value, *tb;
/* Keep the exception (if any) of the last call to step() */
PyErr_Fetch(&exception, &value, &tb);
- function_result = _PyObject_CallMethodIdNoArgs(*aggregate_instance, &PyId_finalize);
-
+ callback_context *ctx = (callback_context *)sqlite3_user_data(context);
+ assert(ctx != NULL);
+ function_result = PyObject_CallMethodNoArgs(*aggregate_instance,
+ ctx->state->str_finalize);
Py_DECREF(*aggregate_instance);
ok = 0;
PyObject *parameters)
/*[clinic end generated code: output=5be05ae01ee17ee4 input=fbd17c75c7140271]*/
{
- _Py_IDENTIFIER(execute);
- PyObject* cursor = 0;
PyObject* result = 0;
- cursor = _PyObject_CallMethodIdNoArgs((PyObject*)self, &PyId_cursor);
+ PyObject *cursor = pysqlite_connection_cursor_impl(self, NULL);
if (!cursor) {
goto error;
}
- result = _PyObject_CallMethodIdObjArgs(cursor, &PyId_execute, sql, parameters, NULL);
+ result = _pysqlite_query_execute((pysqlite_Cursor *)cursor, 0, sql, parameters);
if (!result) {
Py_CLEAR(cursor);
}
PyObject *sql, PyObject *parameters)
/*[clinic end generated code: output=776cd2fd20bfe71f input=4feab80659ffc82b]*/
{
- _Py_IDENTIFIER(executemany);
- PyObject* cursor = 0;
PyObject* result = 0;
- cursor = _PyObject_CallMethodIdNoArgs((PyObject*)self, &PyId_cursor);
+ PyObject *cursor = pysqlite_connection_cursor_impl(self, NULL);
if (!cursor) {
goto error;
}
- result = _PyObject_CallMethodIdObjArgs(cursor, &PyId_executemany, sql,
- parameters, NULL);
+ result = _pysqlite_query_execute((pysqlite_Cursor *)cursor, 1, sql, parameters);
if (!result) {
Py_CLEAR(cursor);
}
PyObject *script_obj)
/*[clinic end generated code: output=4c4f9d77aa0ae37d input=b27ae5c24ffb8b43]*/
{
- _Py_IDENTIFIER(executescript);
- PyObject* cursor = 0;
PyObject* result = 0;
- cursor = _PyObject_CallMethodIdNoArgs((PyObject*)self, &PyId_cursor);
+ PyObject *cursor = pysqlite_connection_cursor_impl(self, NULL);
if (!cursor) {
goto error;
}
- result = _PyObject_CallMethodIdObjArgs(cursor, &PyId_executescript,
- script_obj, NULL);
+ PyObject *meth = self->state->str_executescript; // borrowed ref.
+ result = PyObject_CallMethodObjArgs(cursor, meth, script_obj, NULL);
if (!result) {
Py_CLEAR(cursor);
}
pysqlite_connection_iterdump_impl(pysqlite_Connection *self)
/*[clinic end generated code: output=586997aaf9808768 input=53bc907cb5eedb85]*/
{
- _Py_IDENTIFIER(_iterdump);
PyObject* retval = NULL;
PyObject* module = NULL;
PyObject* module_dict;
goto finally;
}
- pyfn_iterdump = _PyDict_GetItemIdWithError(module_dict, &PyId__iterdump);
+ PyObject *meth = PyUnicode_InternFromString("_iterdump");
+ if (meth == NULL) {
+ goto finally;
+ }
+ pyfn_iterdump = PyDict_GetItemWithError(module_dict, meth);
+ Py_DECREF(meth);
if (!pyfn_iterdump) {
if (!PyErr_Occurred()) {
PyErr_SetString(self->OperationalError,
* 3. This notice may not be removed or altered from any source distribution.
*/
-#define NEEDS_PY_IDENTIFIER
-
#include "cursor.h"
#include "module.h"
#include "util.h"
PyObject *key;
PyObject *upcase_key;
PyObject *retval;
- _Py_IDENTIFIER(upper);
key = PyUnicode_FromStringAndSize(keystr, keylen);
if (!key) {
return NULL;
}
- upcase_key = _PyObject_CallMethodIdNoArgs(key, &PyId_upper);
+ upcase_key = PyObject_CallMethodNoArgs(key, state->str_upper);
Py_DECREF(key);
if (!upcase_key) {
return NULL;
return PyObject_Vectorcall(cache, args + 1, nargsf, NULL);
}
-static PyObject *
+PyObject *
_pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument)
{
PyObject* parameters_list = NULL;
* 3. This notice may not be removed or altered from any source distribution.
*/
-#define NEEDS_PY_IDENTIFIER
-
#include <Python.h>
#include "cursor.h"
pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
PyObject *proto, PyObject *alt)
{
- _Py_IDENTIFIER(__adapt__);
- _Py_IDENTIFIER(__conform__);
PyObject *adapter, *key, *adapted;
/* we don't check for exact type conformance as specified in PEP 246
}
/* try to have the protocol adapt this object */
- if (_PyObject_LookupAttrId(proto, &PyId___adapt__, &adapter) < 0) {
+ if (_PyObject_LookupAttr(proto, state->str___adapt__, &adapter) < 0) {
return NULL;
}
if (adapter) {
}
/* and finally try to have the object adapt itself */
- if (_PyObject_LookupAttrId(obj, &PyId___conform__, &adapter) < 0) {
+ if (_PyObject_LookupAttr(obj, state->str___conform__, &adapter) < 0) {
return NULL;
}
if (adapter) {
* 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"
{
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;
}
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;
}
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;
}
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)
{
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;
PyTypeObject *PrepareProtocolType;
PyTypeObject *RowType;
PyTypeObject *StatementType;
+
+ /* Pointers to interned strings */
+ PyObject *str___adapt__;
+ PyObject *str___conform__;
+ PyObject *str_executescript;
+ PyObject *str_finalize;
+ PyObject *str_upper;
} pysqlite_state;
extern pysqlite_state pysqlite_global_state;