8000 bpo-41861: Convert sqlite3 cache and node types to heap types by erlend-aasland · Pull Request #22417 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41861: Convert sqlite3 cache and node types to heap types #22417

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

Merged
Merged
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 NodeType to heap type
  • Loading branch information
Erlend E. Aasland committed Sep 26, 2020
commit c3cedc5bf17c029d75facc9b5f0479826c9d9321
65 changes: 17 additions & 48 deletions Modules/_sqlite/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pysqlite_Node* pysqlite_new_node(PyObject* key, PyObject* data)
{
pysqlite_Node* node;

node = (pysqlite_Node*) (pysqlite_NodeType.tp_alloc(&pysqlite_NodeType, 0));
node = (pysqlite_Node*) (pysqlite_NodeType->tp_alloc(pysqlite_NodeType, 0));
if (!node) {
return NULL;
}
Expand All @@ -52,6 +52,7 @@ void pysqlite_node_dealloc(pysqlite_Node* self)
Py_DECREF(self->data);

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

int pysqlite_cache_init(pysqlite_Cache* self, PyObject* args, PyObject* kwargs)
Expand Down Expand Up @@ -254,47 +255,19 @@ PyObject* pysqlite_cache_display(pysqlite_Cache* self, PyObject* args)
Py_RETURN_NONE;
}

PyTypeObject pysqlite_NodeType = {
PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME "Node", /* tp_name */
sizeof(pysqlite_Node), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)pysqlite_node_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|Py_TPFLAGS_BASETYPE, /* 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)0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0 /* tp_free */
static PyType_Slot pysqlite_NodeType_slots[] = {
{Py_tp_dealloc, pysqlite_node_dealloc},
{Py_tp_new, PyType_GenericNew},
{0, NULL},
};

PyType_Spec pysqlite_NodeType_spec = {
.name = MODULE_NAME ".Node",
.basicsize = sizeof(pysqlite_Node),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE,
.slots = pysqlite_NodeType_slots,
};
PyTypeObject *pysqlite_NodeType = NULL;

static PyMethodDef cache_methods[] = {
{"get", (PyCFunction)pysqlite_cache_get, METH_O,
Expand Down Expand Up @@ -322,13 +295,9 @@ PyTypeObject *pysqlite_CacheType = NULL;

extern int pysqlite_cache_setup_types(void)
{
int rc;

pysqlite_NodeType.tp_new = PyType_GenericNew;

rc = PyType_Ready(&pysqlite_NodeType);
if (rc < 0) {
return rc;
pysqlite_NodeType = (PyTypeObject *)PyType_FromSpec(&pysqlite_NodeType_spec);
if (pysqlite_NodeType == NULL) {
return -1;
}

pysqlite_CacheType = (PyTypeObject *)PyType_FromSpec(&pysqlite_CacheType_spec);
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ typedef struct
int decref_factory;
} pysqlite_Cache;

extern PyTypeObject pysqlite_NodeType;
extern PyTypeObject *pysqlite_NodeType;
extern PyTypeObject *pysqlite_CacheType;

int pysqlite_node_init(pysqlite_Node* self, PyObject* args, PyObject* kwargs);
Expand Down
0