mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
bpo-41861: Convert _sqlite3 RowType and StatementType to heap types (GH-22444)
This commit is contained in:
parent
fa7ce08017
commit
9031bd4fa4
9 changed files with 72 additions and 119 deletions
|
|
@ -371,6 +371,8 @@ void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
|
|||
|
||||
void pysqlite_statement_dealloc(pysqlite_Statement* self)
|
||||
{
|
||||
PyTypeObject *tp = Py_TYPE(self);
|
||||
|
||||
if (self->st) {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
sqlite3_finalize(self->st);
|
||||
|
|
@ -385,7 +387,8 @@ void pysqlite_statement_dealloc(pysqlite_Statement* self)
|
|||
PyObject_ClearWeakRefs((PyObject*)self);
|
||||
}
|
||||
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
tp->tp_free(self);
|
||||
Py_DECREF(tp);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -458,50 +461,30 @@ static int pysqlite_check_remaining_sql(const char* tail)
|
|||
return 0;
|
||||
}
|
||||
|
||||
PyTypeObject pysqlite_StatementType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
MODULE_NAME ".Statement", /* tp_name */
|
||||
sizeof(pysqlite_Statement), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor)pysqlite_statement_dealloc, /* tp_dealloc */
|
||||
0, /* tp_vectorcall_offset */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_as_async */
|
||||
0, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
0, /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
offsetof(pysqlite_Statement, in_weakreflist), /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
0, /* tp_new */
|
||||
0 /* tp_free */
|
||||
static PyMemberDef stmt_members[] = {
|
||||
{"__weaklistoffset__", T_PYSSIZET, offsetof(pysqlite_Statement, in_weakreflist), READONLY},
|
||||
{NULL},
|
||||
};
|
||||
static PyType_Slot stmt_slots[] = {
|
||||
{Py_tp_members, stmt_members},
|
||||
{Py_tp_dealloc, pysqlite_statement_dealloc},
|
||||
{Py_tp_new, PyType_GenericNew},
|
||||
{0, NULL},
|
||||
};
|
||||
|
||||
extern int pysqlite_statement_setup_types(void)
|
||||
static PyType_Spec stmt_spec = {
|
||||
.name = MODULE_NAME ".Statement",
|
||||
.basicsize = sizeof(pysqlite_Statement),
|
||||
.flags = Py_TPFLAGS_DEFAULT,
|
||||
.slots = stmt_slots,
|
||||
};
|
||||
PyTypeObject *pysqlite_StatementType = NULL;
|
||||
|
||||
extern int pysqlite_statement_setup_types(PyObject *module)
|
||||
{
|
||||
pysqlite_StatementType.tp_new = PyType_GenericNew;
|
||||
return PyType_Ready(&pysqlite_StatementType);
|
||||
pysqlite_StatementType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &stmt_spec, NULL);
|
||||
if (pysqlite_StatementType == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue