bpo-42064: Move sqlite3 types to global state (GH-26537)

* Move connection type to global state
* Move cursor type to global state
* Move prepare protocol type to global state
* Move row type to global state
* Move statement type to global state
* ADD_TYPE takes a pointer
* pysqlite_get_state is now static inline
This commit is contained in:
Erlend Egeberg Aasland 2021-06-15 14:47:34 +02:00 committed by GitHub
parent 8ebd9447e9
commit 10a5c806d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 103 additions and 70 deletions

View file

@ -23,13 +23,16 @@
#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)
@ -62,7 +65,7 @@ pysqlite_row_dealloc(PyObject *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')
/
@ -71,7 +74,7 @@ _sqlite3.Row.__new__ as pysqlite_row_new
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;
@ -216,7 +219,8 @@ static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other,
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) {
@ -258,14 +262,14 @@ static PyType_Spec row_spec = {
.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;
}