8000 bpo-41861: Convert sqlite3 to PEP 384 by erlend-aasland · Pull Request #22409 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41861: Convert sqlite3 to PEP 384 #22409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Convert StatementType to heap type
  • Loading branch information
Erlend E. Aasland committed Sep 25, 2020
commit 49393c76c243766ae9e88fb610dc95092b4212f2
2 changes: 1 addition & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py

_pysqlite_drop_unused_statement_references(self);

statement = PyObject_New(pysqlite_Statement, &pysqlite_StatementType);
statement = PyObject_New(pysqlite_Statement, pysqlite_StatementType);
if (!statement) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args)

if (self->statement->in_use) {
Py_SETREF(self->statement,
PyObject_New(pysqlite_Statement, &pysqlite_StatementType));
PyObject_New(pysqlite_Statement, pysqlite_StatementType));
if (!self->statement) {
goto error;
}
Expand Down
65 changes: 23 additions & 42 deletions Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ void pysqlite_statement_dealloc(pysqlite_Statement* self)
}

Py_TYPE(self)->tp_free((PyObject*)self);
Py_DECREF(pysqlite_StatementType);
}

/*
Expand Down Expand Up @@ -458,50 +459,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 pysqlite_StatementType_members[] = {
{"__weaklistoffset__", T_PYSSIZET, offsetof(pysqlite_Statement, in_weakreflist), READONLY},
{NULL},
};
static PyType_Slot pysqlite_StatementType_slots[] = {
{Py_tp_members, pysqlite_StatementType_members},
{Py_tp_dealloc, pysqlite_statement_dealloc},
{Py_tp_new, PyType_GenericNew},
{0, NULL},
};

PyType_Spec pysqlite_StatementType_spec = {
.name = MODULE_NAME ".Statement",
.basicsize = sizeof(pysqlite_Statement),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
.slots = pysqlite_StatementType_slots,
};
PyTypeObject *pysqlite_StatementType = NULL;

extern int pysqlite_statement_setup_types(void)
{
pysqlite_StatementType.tp_new = PyType_GenericNew;
return PyType_Ready(&pysqlite_StatementType);
pysqlite_StatementType = (PyTypeObject *)PyType_FromSpec(&pysqlite_StatementType_spec);
if (pysqlite_StatementType == NULL) {
return -1;
}
return 0;
}
2 changes: 1 addition & 1 deletion Modules/_sqlite/statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct
PyObject* in_weakreflist; /* List of weak references */
} pysqlite_Statement;

extern PyTypeObject pysqlite_StatementType;
extern PyTypeObject *pysqlite_StatementType;

int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql);
void pysqlite_statement_dealloc(pysqlite_Statement* self);
Expand Down
0