Visitar URL original
bpo-41861: Convert sqlite3 to PEP 384 by erlend-aasland · Pull Request #22409 · python/cpython · GitHub
Skip to content
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 PrepareProtocolType to heap type
  • Loading branch information
Erlend E. Aasland
Erlend E. Aasland committed Sep 25, 2020
commit 914082ffab92661d3a92ea1c53665ac6c73eb003
4 changes: 2 additions & 2 deletions Modules/_sqlite/microprotocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pysqlite_microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast)
PyObject* key;
int rc;

if (proto == NULL) proto = (PyObject*)&pysqlite_PrepareProtocolType;
if (proto == NULL) proto = (PyObject*)pysqlite_PrepareProtocolType;

key = Py_BuildValue("(OO)", (PyObject*)type, proto);
if (!key) {
Expand Down Expand Up @@ -152,7 +152,7 @@ PyObject *
pysqlite_adapt(pysqlite_Cursor *self, PyObject *args)
{
PyObject *obj, *alt = NULL;
PyObject *proto = (PyObject*)&pysqlite_PrepareProtocolType;
PyObject *proto = (PyObject*)pysqlite_PrepareProtocolType;

if (!PyArg_ParseTuple(args, "O|OO", &obj, &proto, &alt)) return NULL;
return pysqlite_microprotocols_adapt(obj, proto, alt);
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args)
pysqlite_BaseTypeAdapted = 1;
}

rc = pysqlite_microprotocols_add(type, (PyObject*)&pysqlite_PrepareProtocolType, caster);
rc = pysqlite_microprotocols_add(type, (PyObject*)pysqlite_PrepareProtocolType, caster);
if (rc == -1)
return NULL;

Expand Down Expand Up @@ -365,7 +365,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void)

ADD_TYPE(module, pysqlite_ConnectionType);
ADD_TYPE(module, pysqlite_CursorType);
ADD_TYPE(module, pysqlite_PrepareProtocolType);
ADD_TYPE(module, *pysqlite_PrepareProtocolType);
ADD_TYPE(module, *pysqlite_RowType);

if (!(dict = PyModule_GetDict(module))) {
Expand Down
62 changes: 19 additions & 43 deletions Modules/_sqlite/prepare_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,51 +33,27 @@ void pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol* self)
Py_TYPE(self)->tp_free((PyObject*)self);
}

PyTypeObject pysqlite_PrepareProtocolType= {
PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME ".PrepareProtocol", /* tp_name */
sizeof(pysqlite_PrepareProtocol), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)pysqlite_prepare_protocol_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 */
0, /* 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)pysqlite_prepare_protocol_init, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0 /* tp_free */
static PyType_Slot pysqlite_PrepareProtocolType_slots[] = {
{Py_tp_dealloc, pysqlite_prepare_protocol_dealloc},
{Py_tp_new, PyType_GenericNew},
{Py_tp_init, pysqlite_prepare_protocol_init},
{0, NULL},
};

static PyType_Spec pysqlite_PrepareProtocolType_spec = {
.name = MODULE_NAME ".PrepareProtocol",
.basicsize = sizeof(pysqlite_PrepareProtocol),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
.slots = pysqlite_PrepareProtocolType_slots,
};

PyTypeObject *pysqlite_PrepareProtocolType = NULL;

extern int pysqlite_prepare_protocol_setup_types(void)
{
pysqlite_PrepareProtocolType.tp_new = PyType_GenericNew;
Py_SET_TYPE(&pysqlite_PrepareProtocolType, &PyType_Type);
return PyType_Ready(&pysqlite_PrepareProtocolType);
pysqlite_PrepareProtocolType = (PyTypeObject *)PyType_FromSpec(&pysqlite_PrepareProtocolType_spec);
if (pysqlite_PrepareProtocolType == NULL) {
return -1;
}
return 0;
}
2 changes: 1 addition & 1 deletion Modules/_sqlite/prepare_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct
PyObject_HEAD
} pysqlite_PrepareProtocol;

extern PyTypeObject pysqlite_PrepareProtocolType;
extern PyTypeObject *pysqlite_PrepareProtocolType;

int pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol* self, PyObject* args, PyObject* kwargs);
void pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol* self);
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
if (!_need_adapt(current_param)) {
adapted = current_param;
} else {
adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, current_param);
adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)pysqlite_PrepareProtocolType, current_param);
Py_DECREF(current_param);
if (!adapted) {
return;
Expand Down Expand Up @@ -306,7 +306,7 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
if (!_need_adapt(current_param)) {
adapted = current_param;
} else {
adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, current_param);
adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)pysqlite_PrepareProtocolType, current_param);
Py_DECREF(current_param);
if (!adapted) {
return;
Expand Down