Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cb6db8b

Browse filesBrowse files
author
Erlend Egeberg Aasland
authored
bpo-41861: Convert _sqlite3 PrepareProtocolType to heap type (GH-22428)
1 parent d332e7b commit cb6db8b
Copy full SHA for cb6db8b

File tree

5 files changed

+33
-54
lines changed
Filter options

5 files changed

+33
-54
lines changed

‎Modules/_sqlite/microprotocols.c

Copy file name to clipboardExpand all lines: Modules/_sqlite/microprotocols.c
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pysqlite_microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast)
5656
PyObject* key;
5757
int rc;
5858

59-
if (proto == NULL) proto = (PyObject*)&pysqlite_PrepareProtocolType;
59+
if (proto == NULL) proto = (PyObject*)pysqlite_PrepareProtocolType;
6060

6161
key = Py_BuildValue("(OO)", (PyObject*)type, proto);
6262
if (!key) {
@@ -152,7 +152,7 @@ PyObject *
152152
pysqlite_adapt(pysqlite_Cursor *self, PyObject *args)
153153
{
154154
PyObject *obj, *alt = NULL;
155-
PyObject *proto = (PyObject*)&pysqlite_PrepareProtocolType;
155+
PyObject *proto = (PyObject*)pysqlite_PrepareProtocolType;
156156

157157
if (!PyArg_ParseTuple(args, "O|OO", &obj, &proto, &alt)) return NULL;
158158
return pysqlite_microprotocols_adapt(obj, proto, alt);

‎Modules/_sqlite/module.c

Copy file name to clipboardExpand all lines: Modules/_sqlite/module.c
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args)
176176
pysqlite_BaseTypeAdapted = 1;
177177
}
178178

179-
rc = pysqlite_microprotocols_add(type, (PyObject*)&pysqlite_PrepareProtocolType, caster);
179+
rc = pysqlite_microprotocols_add(type, (PyObject*)pysqlite_PrepareProtocolType, caster);
180180
if (rc == -1)
181181
return NULL;
182182

@@ -357,15 +357,15 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
357357
(pysqlite_connection_setup_types() < 0) ||
358358
(pysqlite_cache_setup_types(module) < 0) ||
359359
(pysqlite_statement_setup_types() < 0) ||
360-
(pysqlite_prepare_protocol_setup_types() < 0)
360+
(pysqlite_prepare_protocol_setup_types(module) < 0)
361361
) {
362362
Py_XDECREF(module);
363363
return NULL;
364364
}
365365

366366
ADD_TYPE(module, pysqlite_ConnectionType);
367367
ADD_TYPE(module, pysqlite_CursorType);
368-
ADD_TYPE(module, pysqlite_PrepareProtocolType);
368+
ADD_TYPE(module, *pysqlite_PrepareProtocolType);
369369
ADD_TYPE(module, pysqlite_RowType);
370370

371371
if (!(dict = PyModule_GetDict(module))) {

‎Modules/_sqlite/prepare_protocol.c

Copy file name to clipboardExpand all lines: Modules/_sqlite/prepare_protocol.c
+24-45Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,54 +30,33 @@ int pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol* self, PyObject* arg
3030

3131
void pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol* self)
3232
{
33-
Py_TYPE(self)->tp_free((PyObject*)self);
33+
PyTypeObject *tp = Py_TYPE(self);
34+
35+
tp->tp_free(self);
36+
Py_DECREF(tp);
3437
}
3538

36-
PyTypeObject pysqlite_PrepareProtocolType= {
37-
PyVarObject_HEAD_INIT(NULL, 0)
38-
MODULE_NAME ".PrepareProtocol", /* tp_name */
39-
sizeof(pysqlite_PrepareProtocol), /* tp_basicsize */
40-
0, /* tp_itemsize */
41-
(destructor)pysqlite_prepare_protocol_dealloc, /* tp_dealloc */
42-
0, /* tp_vectorcall_offset */
43-
0, /* tp_getattr */
44-
0, /* tp_setattr */
45-
0, /* tp_as_async */
46-
0, /* tp_repr */
47-
0, /* tp_as_number */
48-
0, /* tp_as_sequence */
49-
0, /* tp_as_mapping */
50-
0, /* tp_hash */
51-
0, /* tp_call */
52-
0, /* tp_str */
53-
0, /* tp_getattro */
54-
0, /* tp_setattro */
55-
0, /* tp_as_buffer */
56-
Py_TPFLAGS_DEFAULT, /* tp_flags */
57-
0, /* tp_doc */
58-
0, /* tp_traverse */
59-
0, /* tp_clear */
60-
0, /* tp_richcompare */
61-
0, /* tp_weaklistoffset */
62-
0, /* tp_iter */
63-
0, /* tp_iternext */
64-
0, /* tp_methods */
65-
0, /* tp_members */
66-
0, /* tp_getset */
67-
0, /* tp_base */
68-
0, /* tp_dict */
69-
0, /* tp_descr_get */
70-
0, /* tp_descr_set */
71-
0, /* tp_dictoffset */
72-
(initproc)pysqlite_prepare_protocol_init, /* tp_init */
73-
0, /* tp_alloc */
74-
0, /* tp_new */
75-
0 /* tp_free */
39+
static PyType_Slot type_slots[] = {
40+
{Py_tp_dealloc, pysqlite_prepare_protocol_dealloc},
41+
{Py_tp_new, PyType_GenericNew},
42+
{Py_tp_init, pysqlite_prepare_protocol_init},
43+
{0, NULL},
44+
};
45+
46+
static PyType_Spec type_spec = {
47+
.name = MODULE_NAME ".PrepareProtocol",
48+
.basicsize = sizeof(pysqlite_PrepareProtocol),
49+
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
50+
.slots = type_slots,
7651
};
7752

78-
extern int pysqlite_prepare_protocol_setup_types(void)
53+
PyTypeObject *pysqlite_PrepareProtocolType = NULL;
54+
55+
extern int pysqlite_prepare_protocol_setup_types(PyObject *module)
7956
{
80-
pysqlite_PrepareProtocolType.tp_new = PyType_GenericNew;
81-
Py_SET_TYPE(&pysqlite_PrepareProtocolType, &PyType_Type);
82-
return PyType_Ready(&pysqlite_PrepareProtocolType);
57+
pysqlite_PrepareProtocolType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &type_spec, NULL);
58+
if (pysqlite_PrepareProtocolType == NULL) {
59+
return -1;
60+
}
61+
return 0;
8362
}

‎Modules/_sqlite/prepare_protocol.h

Copy file name to clipboardExpand all lines: Modules/_sqlite/prepare_protocol.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ typedef struct
3131
PyObject_HEAD
3232
} pysqlite_PrepareProtocol;
3333

34-
extern PyTypeObject pysqlite_PrepareProtocolType;
34+
extern PyTypeObject *pysqlite_PrepareProtocolType;
3535

3636
int pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol* self, PyObject* args, PyObject* kwargs);
3737
void pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol* self);
3838

39-
int pysqlite_prepare_protocol_setup_types(void);
39+
int pysqlite_prepare_protocol_setup_types(PyObject *module);
4040

4141
#define UNKNOWN (-1)
4242
#endif

‎Modules/_sqlite/statement.c

Copy file name to clipboardExpand all lines: Modules/_sqlite/statement.c
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
255255
if (!_need_adapt(current_param)) {
256256
adapted = current_param;
257257
} else {
258-
adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, current_param);
258+
adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)pysqlite_PrepareProtocolType, current_param);
259259
Py_DECREF(current_param);
260260
if (!adapted) {
261261
return;
@@ -306,7 +306,7 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
306306
if (!_need_adapt(current_param)) {
307307
adapted = current_param;
308308
} else {
309-
adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, current_param);
309+
adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)pysqlite_PrepareProtocolType, current_param);
310310
Py_DECREF(current_param);
311311
if (!adapted) {
312312
return;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.