if (!args) {
goto exit;
}
- if (!PyObject_TypeCheck(args[0], pysqlite_ConnectionType)) {
- _PyArg_BadArgument("backup", "argument 'target'", (pysqlite_ConnectionType)->tp_name, args[0]);
+ if (!PyObject_TypeCheck(args[0], clinic_state()->ConnectionType)) {
+ _PyArg_BadArgument("backup", "argument 'target'", (clinic_state()->ConnectionType)->tp_name, args[0]);
goto exit;
}
target = (pysqlite_Connection *)args[0];
#ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
#define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
#endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
-/*[clinic end generated code: output=c1bf09db3bcd0105 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1ee2f6173f4acec3 input=a9049054013a1b77]*/
int return_value = -1;
pysqlite_Connection *connection;
- if (Py_IS_TYPE(self, pysqlite_CursorType) &&
+ if (Py_IS_TYPE(self, clinic_state()->CursorType) &&
!_PyArg_NoKeywords("Cursor", kwargs)) {
goto exit;
}
if (!_PyArg_CheckPositional("Cursor", PyTuple_GET_SIZE(args), 1, 1)) {
goto exit;
}
- if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), pysqlite_ConnectionType)) {
- _PyArg_BadArgument("Cursor", "argument 1", (pysqlite_ConnectionType)->tp_name, PyTuple_GET_ITEM(args, 0));
+ if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), clinic_state()->ConnectionType)) {
+ _PyArg_BadArgument("Cursor", "argument 1", (clinic_state()->ConnectionType)->tp_name, PyTuple_GET_ITEM(args, 0));
goto exit;
}
connection = (pysqlite_Connection *)PyTuple_GET_ITEM(args, 0);
{
return pysqlite_cursor_close_impl(self);
}
-/*[clinic end generated code: output=6a2d4d49784aa686 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e3a502bb26aaefa5 input=a9049054013a1b77]*/
{
PyObject *return_value = NULL;
PyObject *obj;
- PyObject *proto = (PyObject*)pysqlite_PrepareProtocolType;
+ PyObject *proto = (PyObject *)clinic_state()->PrepareProtocolType;
PyObject *alt = NULL;
if (!_PyArg_CheckPositional("adapt", nargs, 1, 3)) {
exit:
return return_value;
}
-/*[clinic end generated code: output=d87990f941c209fa input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e9c2442673289cab input=a9049054013a1b77]*/
pysqlite_Cursor *cursor;
PyObject *data;
- if ((type == pysqlite_RowType) &&
+ if ((type == clinic_state()->RowType) &&
!_PyArg_NoKeywords("Row", kwargs)) {
goto exit;
}
if (!_PyArg_CheckPositional("Row", PyTuple_GET_SIZE(args), 2, 2)) {
goto exit;
}
- if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), pysqlite_CursorType)) {
- _PyArg_BadArgument("Row", "argument 1", (pysqlite_CursorType)->tp_name, PyTuple_GET_ITEM(args, 0));
+ if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), clinic_state()->CursorType)) {
+ _PyArg_BadArgument("Row", "argument 1", (clinic_state()->CursorType)->tp_name, PyTuple_GET_ITEM(args, 0));
goto exit;
}
cursor = (pysqlite_Cursor *)PyTuple_GET_ITEM(args, 0);
{
return pysqlite_row_keys_impl(self);
}
-/*[clinic end generated code: output=8d29220b9cde035d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0382771b4fc85f36 input=a9049054013a1b77]*/
#define HAVE_TRACE_V2
#endif
+#define clinic_state() (pysqlite_get_state(NULL))
#include "clinic/connection.c.h"
+#undef clinic_state
+
/*[clinic input]
module _sqlite3
-class _sqlite3.Connection "pysqlite_Connection *" "pysqlite_ConnectionType"
+class _sqlite3.Connection "pysqlite_Connection *" "clinic_state()->ConnectionType"
[clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=aa796073bd8f69db]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=67369db2faf80891]*/
_Py_IDENTIFIER(cursor);
return NULL;
}
+ pysqlite_state *state = pysqlite_get_state(NULL);
if (factory == NULL) {
- factory = (PyObject*)pysqlite_CursorType;
+ factory = (PyObject *)state->CursorType;
}
cursor = PyObject_CallOneArg(factory, (PyObject *)self);
if (cursor == NULL)
return NULL;
- if (!PyObject_TypeCheck(cursor, pysqlite_CursorType)) {
+ if (!PyObject_TypeCheck(cursor, state->CursorType)) {
PyErr_Format(PyExc_TypeError,
"factory must return a cursor, not %.100s",
Py_TYPE(cursor)->tp_name);
/*[clinic input]
_sqlite3.Connection.backup as pysqlite_connection_backup
- target: object(type='pysqlite_Connection *', subclass_of='pysqlite_ConnectionType')
+ target: object(type='pysqlite_Connection *', subclass_of='clinic_state()->ConnectionType')
*
pages: int = -1
progress: object = None
pysqlite_Connection *target, int pages,
PyObject *progress, const char *name,
double sleep)
-/*[clinic end generated code: output=306a3e6a38c36334 input=30ae45fc420bfd3b]*/
+/*[clinic end generated code: output=306a3e6a38c36334 input=c759627ab1ad46ff]*/
{
int rc;
int sleep_ms = (int)(sleep * 1000.0);
.slots = connection_slots,
};
-PyTypeObject *pysqlite_ConnectionType = NULL;
-
int
pysqlite_connection_setup_types(PyObject *module)
{
- pysqlite_ConnectionType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &connection_spec, NULL);
- if (pysqlite_ConnectionType == NULL) {
+ PyObject *type = PyType_FromModuleAndSpec(module, &connection_spec, NULL);
+ if (type == NULL) {
return -1;
}
+ pysqlite_state *state = pysqlite_get_state(module);
+ state->ConnectionType = (PyTypeObject *)type;
return 0;
}
#include "cursor.h"
#include "module.h"
#include "util.h"
+
+#define clinic_state() (pysqlite_get_state(NULL))
#include "clinic/cursor.c.h"
+#undef clinic_state
/*[clinic input]
module _sqlite3
-class _sqlite3.Cursor "pysqlite_Cursor *" "pysqlite_CursorType"
+class _sqlite3.Cursor "pysqlite_Cursor *" "clinic_state()->CursorType"
[clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b2072d8db95411d5]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=3c5b8115c5cf30f1]*/
static const char errmsg_fetch_across_rollback[] = "Cursor needed to be reset because of commit/rollback and can no longer be fetched from.";
/*[clinic input]
_sqlite3.Cursor.__init__ as pysqlite_cursor_init
- connection: object(type='pysqlite_Connection *', subclass_of='pysqlite_ConnectionType')
+ connection: object(type='pysqlite_Connection *', subclass_of='clinic_state()->ConnectionType')
/
[clinic start generated code]*/
static int
pysqlite_cursor_init_impl(pysqlite_Cursor *self,
pysqlite_Connection *connection)
-/*[clinic end generated code: output=ac59dce49a809ca8 input=a8a4f75ac90999b2]*/
+/*[clinic end generated code: output=ac59dce49a809ca8 input=23d4265b534989fb]*/
{
Py_INCREF(connection);
Py_XSETREF(self->connection, connection);
.slots = cursor_slots,
};
-PyTypeObject *pysqlite_CursorType = NULL;
-
int
pysqlite_cursor_setup_types(PyObject *module)
{
- pysqlite_CursorType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &cursor_spec, NULL);
- if (pysqlite_CursorType == NULL) {
+ PyObject *type = PyType_FromModuleAndSpec(module, &cursor_spec, NULL);
+ if (type == NULL) {
return -1;
}
+ pysqlite_state *state = pysqlite_get_state(module);
+ state->CursorType = (PyTypeObject *)type;
return 0;
}
PyObject* key;
int rc;
- if (proto == NULL) proto = (PyObject*)pysqlite_PrepareProtocolType;
-
+ assert(type != NULL);
+ assert(proto != NULL);
key = Py_BuildValue("(OO)", (PyObject*)type, proto);
if (!key) {
return -1;
PyObject *adapter, *key, *adapted;
/* we don't check for exact type conformance as specified in PEP 246
- because the pysqlite_PrepareProtocolType type is abstract and there is no
+ because the PrepareProtocolType type is abstract and there is no
way to get a quotable object to be its instance */
/* look for an adapter in the registry */
#error "SQLite 3.7.15 or higher required"
#endif
+#define clinic_state() (pysqlite_get_state(NULL))
#include "clinic/module.c.h"
+#undef clinic_state
+
/*[clinic input]
module _sqlite3
[clinic start generated code]*/
pysqlite_state pysqlite_global_state;
-pysqlite_state *
-pysqlite_get_state(PyObject *Py_UNUSED(module))
-{
- return &pysqlite_global_state;
-}
-
static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
kwargs)
{
}
if (factory == NULL) {
- factory = (PyObject*)pysqlite_ConnectionType;
+ pysqlite_state *state = pysqlite_get_state(self);
+ factory = (PyObject *)state->ConnectionType;
}
return PyObject_Call(factory, args, kwargs);
pysqlite_BaseTypeAdapted = 1;
}
- rc = pysqlite_microprotocols_add(type, (PyObject*)pysqlite_PrepareProtocolType, caster);
- if (rc == -1)
+ pysqlite_state *state = pysqlite_get_state(NULL);
+ PyObject *protocol = (PyObject *)state->PrepareProtocolType;
+ rc = pysqlite_microprotocols_add(type, protocol, caster);
+ if (rc == -1) {
return NULL;
+ }
Py_RETURN_NONE;
}
_sqlite3.adapt as pysqlite_adapt
obj: object
- proto: object(c_default='(PyObject*)pysqlite_PrepareProtocolType') = PrepareProtocolType
+ proto: object(c_default='(PyObject *)clinic_state()->PrepareProtocolType') = PrepareProtocolType
alt: object = NULL
/
static PyObject *
pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
PyObject *alt)
-/*[clinic end generated code: output=0c3927c5fcd23dd9 input=a58ab77fb5ae22dd]*/
+/*[clinic end generated code: output=0c3927c5fcd23dd9 input=c8995aeb25d0e542]*/
{
return pysqlite_microprotocols_adapt(obj, proto, alt);
}
#define ADD_TYPE(module, type) \
do { \
- if (PyModule_AddType(module, &type) < 0) { \
+ if (PyModule_AddType(module, type) < 0) { \
goto error; \
} \
} while (0)
}
module = PyModule_Create(&_sqlite3module);
+ pysqlite_state *state = pysqlite_get_state(module);
if (!module ||
(pysqlite_row_setup_types(module) < 0) ||
goto error;
}
- ADD_TYPE(module, *pysqlite_ConnectionType);
- ADD_TYPE(module, *pysqlite_CursorType);
- ADD_TYPE(module, *pysqlite_PrepareProtocolType);
- ADD_TYPE(module, *pysqlite_RowType);
+ ADD_TYPE(module, state->ConnectionType);
+ ADD_TYPE(module, state->CursorType);
+ ADD_TYPE(module, state->PrepareProtocolType);
+ ADD_TYPE(module, state->RowType);
/*** Create DB-API Exception hierarchy */
ADD_EXCEPTION(module, "Error", pysqlite_Error, PyExc_Exception);
typedef struct {
PyObject *lru_cache;
+ PyTypeObject *ConnectionType;
+ PyTypeObject *CursorType;
+ PyTypeObject *PrepareProtocolType;
+ PyTypeObject *RowType;
+ PyTypeObject *StatementType;
} pysqlite_state;
-extern pysqlite_state *pysqlite_get_state(PyObject *module);
+extern pysqlite_state pysqlite_global_state;
+
+static inline pysqlite_state *
+pysqlite_get_state(PyObject *Py_UNUSED(module))
+{
+ return &pysqlite_global_state;
+}
extern PyObject* pysqlite_Error;
extern PyObject* pysqlite_Warning;
.slots = type_slots,
};
-PyTypeObject *pysqlite_PrepareProtocolType = NULL;
-
int
pysqlite_prepare_protocol_setup_types(PyObject *module)
{
- pysqlite_PrepareProtocolType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &type_spec, NULL);
- if (pysqlite_PrepareProtocolType == NULL) {
+ PyObject *type = PyType_FromModuleAndSpec(module, &type_spec, NULL);
+ if (type == NULL) {
return -1;
}
+ pysqlite_state *state = pysqlite_get_state(module);
+ state->PrepareProtocolType = (PyTypeObject *)type;
return 0;
}
#include "row.h"
#include "cursor.h"
+
+#define clinic_state() (pysqlite_get_state(NULL))
#include "clinic/row.c.h"
+#undef clinic_state
/*[clinic input]
module _sqlite3
-class _sqlite3.Row "pysqlite_Row *" "pysqlite_RowType"
+class _sqlite3.Row "pysqlite_Row *" "clinic_state()->RowType"
[clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=384227da65f250fd]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=966c53403d7f3a40]*/
static int
row_clear(pysqlite_Row *self)
@classmethod
_sqlite3.Row.__new__ as pysqlite_row_new
- cursor: object(type='pysqlite_Cursor *', subclass_of='pysqlite_CursorType')
+ cursor: object(type='pysqlite_Cursor *', subclass_of='clinic_state()->CursorType')
data: object(subclass_of='&PyTuple_Type')
/
static PyObject *
pysqlite_row_new_impl(PyTypeObject *type, pysqlite_Cursor *cursor,
PyObject *data)
-/*[clinic end generated code: output=10d58b09a819a4c1 input=f6cd7e6e0935828d]*/
+/*[clinic end generated code: output=10d58b09a819a4c1 input=b9e954ca31345dbf]*/
{
pysqlite_Row *self;
if (opid != Py_EQ && opid != Py_NE)
Py_RETURN_NOTIMPLEMENTED;
- if (PyObject_TypeCheck(_other, pysqlite_RowType)) {
+ pysqlite_state *state = pysqlite_get_state(NULL);
+ if (PyObject_TypeCheck(_other, state->RowType)) {
pysqlite_Row *other = (pysqlite_Row *)_other;
int eq = PyObject_RichCompareBool(self->description, other->description, Py_EQ);
if (eq < 0) {
.slots = row_slots,
};
-PyTypeObject *pysqlite_RowType = NULL;
-
int
pysqlite_row_setup_types(PyObject *module)
{
- pysqlite_RowType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &row_spec, NULL);
- if (pysqlite_RowType == NULL) {
+ PyObject *type = PyType_FromModuleAndSpec(module, &row_spec, NULL);
+ if (type == NULL) {
return -1;
}
+ pysqlite_state *state = pysqlite_get_state(module);
+ state->RowType = (PyTypeObject *)type;
return 0;
}
break;
}
+ pysqlite_state *state = pysqlite_get_state(NULL);
pysqlite_Statement *self = PyObject_GC_New(pysqlite_Statement,
- pysqlite_StatementType);
+ state->StatementType);
if (self == NULL) {
goto error;
}
void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters)
{
+ pysqlite_state *state = pysqlite_get_state(NULL);
PyObject* current_param;
PyObject* adapted;
const char* binding_name;
if (!_need_adapt(current_param)) {
adapted = current_param;
} else {
- adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)pysqlite_PrepareProtocolType, current_param);
+ PyObject *protocol = (PyObject *)state->PrepareProtocolType;
+ adapted = pysqlite_microprotocols_adapt(current_param,
+ protocol,
+ current_param);
Py_DECREF(current_param);
if (!adapted) {
return;
if (!_need_adapt(current_param)) {
adapted = current_param;
} else {
- adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)pysqlite_PrepareProtocolType, current_param);
+ PyObject *protocol = (PyObject *)state->PrepareProtocolType;
+ adapted = pysqlite_microprotocols_adapt(current_param,
+ protocol,
+ current_param);
Py_DECREF(current_param);
if (!adapted) {
return;
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.slots = stmt_slots,
};
-PyTypeObject *pysqlite_StatementType = NULL;
int
pysqlite_statement_setup_types(PyObject *module)
{
- pysqlite_StatementType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &stmt_spec, NULL);
- if (pysqlite_StatementType == NULL) {
+ PyObject *type = PyType_FromModuleAndSpec(module, &stmt_spec, NULL);
+ if (type == NULL) {
return -1;
}
+ pysqlite_state *state = pysqlite_get_state(module);
+ state->StatementType = (PyTypeObject *)type;
return 0;
}