Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1 | /* cache .c - a LRU cache |
| 2 | * |
Florent Xicluna | c934f32 | 2010-09-03 23:47:32 +0000 | [diff] [blame] | 3 | * Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de> |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4 | * |
| 5 | * This file is part of pysqlite. |
| 6 | * |
| 7 | * This software is provided 'as-is', without any express or implied |
| 8 | * warranty. In no event will the authors be held liable for any damages |
| 9 | * arising from the use of this software. |
| 10 | * |
| 11 | * Permission is granted to anyone to use this software for any purpose, |
| 12 | * including commercial applications, and to alter it and redistribute it |
| 13 | * freely, subject to the following restrictions: |
| 14 | * |
| 15 | * 1. The origin of this software must not be misrepresented; you must not |
| 16 | * claim that you wrote the original software. If you use this software |
| 17 | * in a product, an acknowledgment in the product documentation would be |
| 18 | * appreciated but is not required. |
| 19 | * 2. Altered source versions must be plainly marked as such, and must not be |
| 20 | * misrepresented as being the original software. |
| 21 | * 3. This notice may not be removed or altered from any source distribution. |
| 22 | */ |
| 23 | |
| 24 | #include "cache.h" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 25 | #include <limits.h> |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 26 | |
| 27 | /* only used internally */ |
Erlend Egeberg Aasland | bf838a6 | 2021-02-21 01:29:19 +0100 | [diff] [blame] | 28 | static pysqlite_Node * |
| 29 | pysqlite_new_node(PyObject *key, PyObject *data) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 30 | { |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 31 | pysqlite_Node* node; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 32 | |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 33 | node = (pysqlite_Node*) (pysqlite_NodeType->tp_alloc(pysqlite_NodeType, 0)); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 34 | if (!node) { |
| 35 | return NULL; |
| 36 | } |
| 37 | |
Erlend Egeberg Aasland | bf64d90 | 2020-12-27 12:05:33 +0100 | [diff] [blame] | 38 | node->key = Py_NewRef(key); |
| 39 | node->data = Py_NewRef(data); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 40 | |
| 41 | node->prev = NULL; |
| 42 | node->next = NULL; |
| 43 | |
| 44 | return node; |
| 45 | } |
| 46 | |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 47 | static int |
| 48 | node_traverse(pysqlite_Node *self, visitproc visit, void *arg) |
| 49 | { |
Miss Islington (bot) | ff359d7 | 2021-05-31 02:12:27 -0700 | [diff] [blame] | 50 | Py_VISIT(Py_TYPE(self)); |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 51 | Py_VISIT(self->key); |
| 52 | Py_VISIT(self->data); |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static int |
| 57 | node_clear(pysqlite_Node *self) |
| 58 | { |
| 59 | Py_CLEAR(self->key); |
| 60 | Py_CLEAR(self->data); |
| 61 | return 0; |
| 62 | } |
| 63 | |
Erlend Egeberg Aasland | bf838a6 | 2021-02-21 01:29:19 +0100 | [diff] [blame] | 64 | static void |
| 65 | pysqlite_node_dealloc(pysqlite_Node *self) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 66 | { |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 67 | PyTypeObject *tp = Py_TYPE(self); |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 68 | PyObject_GC_UnTrack(self); |
| 69 | tp->tp_clear((PyObject *)self); |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 70 | tp->tp_free(self); |
| 71 | Py_DECREF(tp); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Erlend Egeberg Aasland | bf838a6 | 2021-02-21 01:29:19 +0100 | [diff] [blame] | 74 | static int |
| 75 | pysqlite_cache_init(pysqlite_Cache *self, PyObject *args, PyObject *kwargs) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 76 | { |
| 77 | PyObject* factory; |
| 78 | int size = 10; |
| 79 | |
| 80 | self->factory = NULL; |
| 81 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 82 | if (!PyArg_ParseTuple(args, "O|i", &factory, &size)) { |
| 83 | return -1; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 86 | /* minimum cache size is 5 entries */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 87 | if (size < 5) { |
| 88 | size = 5; |
| 89 | } |
| 90 | self->size = size; |
| 91 | self->first = NULL; |
| 92 | self->last = NULL; |
| 93 | |
| 94 | self->mapping = PyDict_New(); |
| 95 | if (!self->mapping) { |
| 96 | return -1; |
| 97 | } |
| 98 | |
Erlend Egeberg Aasland | bf64d90 | 2020-12-27 12:05:33 +0100 | [diff] [blame] | 99 | self->factory = Py_NewRef(factory); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 100 | |
| 101 | self->decref_factory = 1; |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 106 | static int |
| 107 | cache_traverse(pysqlite_Cache *self, visitproc visit, void *arg) |
| 108 | { |
Miss Islington (bot) | ff359d7 | 2021-05-31 02:12:27 -0700 | [diff] [blame] | 109 | Py_VISIT(Py_TYPE(self)); |
| 110 | Py_VISIT(self->mapping); |
| 111 | if (self->decref_factory) { |
| 112 | Py_VISIT(self->factory); |
| 113 | } |
| 114 | |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 115 | pysqlite_Node *node = self->first; |
| 116 | while (node) { |
| 117 | Py_VISIT(node); |
| 118 | node = node->next; |
| 119 | } |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static int |
| 124 | cache_clear(pysqlite_Cache *self) |
| 125 | { |
Miss Islington (bot) | ff359d7 | 2021-05-31 02:12:27 -0700 | [diff] [blame] | 126 | Py_CLEAR(self->mapping); |
| 127 | if (self->decref_factory) { |
| 128 | Py_CLEAR(self->factory); |
| 129 | } |
| 130 | |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 131 | /* iterate over all nodes and deallocate them */ |
| 132 | pysqlite_Node *node = self->first; |
| 133 | self->first = NULL; |
| 134 | while (node) { |
| 135 | pysqlite_Node *delete_node = node; |
| 136 | node = node->next; |
| 137 | Py_CLEAR(delete_node); |
| 138 | } |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
Erlend Egeberg Aasland | bf838a6 | 2021-02-21 01:29:19 +0100 | [diff] [blame] | 142 | static void |
| 143 | pysqlite_cache_dealloc(pysqlite_Cache *self) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 144 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 145 | if (!self->factory) { |
| 146 | /* constructor failed, just get out of here */ |
| 147 | return; |
| 148 | } |
| 149 | |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 150 | PyObject_GC_UnTrack(self); |
| 151 | PyTypeObject *tp = Py_TYPE(self); |
| 152 | tp->tp_clear((PyObject *)self); |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 153 | tp->tp_free(self); |
| 154 | Py_DECREF(tp); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Jeroen Demeyer | 196a530 | 2019-07-04 12:31:34 +0200 | [diff] [blame] | 157 | PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* key) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 158 | { |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 159 | pysqlite_Node* node; |
| 160 | pysqlite_Node* ptr; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 161 | PyObject* data; |
| 162 | |
Serhiy Storchaka | fc662ac | 2018-12-10 16:06:08 +0200 | [diff] [blame] | 163 | node = (pysqlite_Node*)PyDict_GetItemWithError(self->mapping, key); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 164 | if (node) { |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 165 | /* an entry for this key already exists in the cache */ |
| 166 | |
| 167 | /* increase usage counter of the node found */ |
| 168 | if (node->count < LONG_MAX) { |
| 169 | node->count++; |
| 170 | } |
| 171 | |
| 172 | /* if necessary, reorder entries in the cache by swapping positions */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 173 | if (node->prev && node->count > node->prev->count) { |
| 174 | ptr = node->prev; |
| 175 | |
| 176 | while (ptr->prev && node->count > ptr->prev->count) { |
| 177 | ptr = ptr->prev; |
| 178 | } |
| 179 | |
| 180 | if (node->next) { |
| 181 | node->next->prev = node->prev; |
| 182 | } else { |
| 183 | self->last = node->prev; |
| 184 | } |
| 185 | if (node->prev) { |
| 186 | node->prev->next = node->next; |
| 187 | } |
| 188 | if (ptr->prev) { |
| 189 | ptr->prev->next = node; |
| 190 | } else { |
| 191 | self->first = node; |
| 192 | } |
| 193 | |
| 194 | node->next = ptr; |
| 195 | node->prev = ptr->prev; |
| 196 | if (!node->prev) { |
| 197 | self->first = node; |
| 198 | } |
| 199 | ptr->prev = node; |
| 200 | } |
Serhiy Storchaka | fc662ac | 2018-12-10 16:06:08 +0200 | [diff] [blame] | 201 | } |
| 202 | else if (PyErr_Occurred()) { |
| 203 | return NULL; |
| 204 | } |
| 205 | else { |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 206 | /* There is no entry for this key in the cache, yet. We'll insert a new |
| 207 | * entry in the cache, and make space if necessary by throwing the |
| 208 | * least used item out of the cache. */ |
| 209 | |
Serhiy Storchaka | 5ab81d7 | 2016-12-16 16:18:57 +0200 | [diff] [blame] | 210 | if (PyDict_GET_SIZE(self->mapping) == self->size) { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 211 | if (self->last) { |
| 212 | node = self->last; |
| 213 | |
| 214 | if (PyDict_DelItem(self->mapping, self->last->key) != 0) { |
| 215 | return NULL; |
| 216 | } |
| 217 | |
| 218 | if (node->prev) { |
| 219 | node->prev->next = NULL; |
| 220 | } |
| 221 | self->last = node->prev; |
| 222 | node->prev = NULL; |
| 223 | |
| 224 | Py_DECREF(node); |
| 225 | } |
| 226 | } |
| 227 | |
Petr Viktorin | ffd9753 | 2020-02-11 17:46:57 +0100 | [diff] [blame] | 228 | /* We cannot replace this by PyObject_CallOneArg() since |
Jeroen Demeyer | 196a530 | 2019-07-04 12:31:34 +0200 | [diff] [blame] | 229 | * PyObject_CallFunction() has a special case when using a |
| 230 | * single tuple as argument. */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 231 | data = PyObject_CallFunction(self->factory, "O", key); |
| 232 | |
| 233 | if (!data) { |
| 234 | return NULL; |
| 235 | } |
| 236 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 237 | node = pysqlite_new_node(key, data); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 238 | if (!node) { |
| 239 | return NULL; |
| 240 | } |
| 241 | node->prev = self->last; |
| 242 | |
| 243 | Py_DECREF(data); |
| 244 | |
| 245 | if (PyDict_SetItem(self->mapping, key, (PyObject*)node) != 0) { |
| 246 | Py_DECREF(node); |
| 247 | return NULL; |
| 248 | } |
| 249 | |
| 250 | if (self->last) { |
| 251 | self->last->next = node; |
| 252 | } else { |
| 253 | self->first = node; |
| 254 | } |
| 255 | self->last = node; |
| 256 | } |
| 257 | |
Erlend Egeberg Aasland | bf64d90 | 2020-12-27 12:05:33 +0100 | [diff] [blame] | 258 | return Py_NewRef(node->data); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Erlend Egeberg Aasland | bf838a6 | 2021-02-21 01:29:19 +0100 | [diff] [blame] | 261 | static PyObject * |
| 262 | pysqlite_cache_display(pysqlite_Cache *self, PyObject *args) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 263 | { |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 264 | pysqlite_Node* ptr; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 265 | PyObject* prevkey; |
| 266 | PyObject* nextkey; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 267 | PyObject* display_str; |
| 268 | |
| 269 | ptr = self->first; |
| 270 | |
| 271 | while (ptr) { |
| 272 | if (ptr->prev) { |
| 273 | prevkey = ptr->prev->key; |
| 274 | } else { |
| 275 | prevkey = Py_None; |
| 276 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 277 | |
| 278 | if (ptr->next) { |
| 279 | nextkey = ptr->next->key; |
| 280 | } else { |
| 281 | nextkey = Py_None; |
| 282 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 283 | |
Amaury Forgeot d'Arc | 864741b | 2011-11-06 15:10:48 +0100 | [diff] [blame] | 284 | display_str = PyUnicode_FromFormat("%S <- %S -> %S\n", |
| 285 | prevkey, ptr->key, nextkey); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 286 | if (!display_str) { |
| 287 | return NULL; |
| 288 | } |
| 289 | PyObject_Print(display_str, stdout, Py_PRINT_RAW); |
| 290 | Py_DECREF(display_str); |
| 291 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 292 | ptr = ptr->next; |
| 293 | } |
| 294 | |
Berker Peksag | fe21de9 | 2016-04-09 07:34:39 +0300 | [diff] [blame] | 295 | Py_RETURN_NONE; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Erlend Egeberg Aasland | 2ffba2a | 2020-11-17 13:52:54 +0100 | [diff] [blame] | 298 | static PyType_Slot node_slots[] = { |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 299 | {Py_tp_dealloc, pysqlite_node_dealloc}, |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 300 | {Py_tp_traverse, node_traverse}, |
| 301 | {Py_tp_clear, node_clear}, |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 302 | {0, NULL}, |
| 303 | }; |
| 304 | |
Erlend Egeberg Aasland | 2ffba2a | 2020-11-17 13:52:54 +0100 | [diff] [blame] | 305 | static PyType_Spec node_spec = { |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 306 | .name = MODULE_NAME ".Node", |
| 307 | .basicsize = sizeof(pysqlite_Node), |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 308 | .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
Erlend Egeberg Aasland | 2ffba2a | 2020-11-17 13:52:54 +0100 | [diff] [blame] | 309 | .slots = node_slots, |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 310 | }; |
| 311 | PyTypeObject *pysqlite_NodeType = NULL; |
| 312 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 313 | static PyMethodDef cache_methods[] = { |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 314 | {"get", (PyCFunction)pysqlite_cache_get, METH_O, |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 315 | PyDoc_STR("Gets an entry from the cache or calls the factory function to produce one.")}, |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 316 | {"display", (PyCFunction)pysqlite_cache_display, METH_NOARGS, |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 317 | PyDoc_STR("For debugging only.")}, |
| 318 | {NULL, NULL} |
| 319 | }; |
| 320 | |
Erlend Egeberg Aasland | 2ffba2a | 2020-11-17 13:52:54 +0100 | [diff] [blame] | 321 | static PyType_Slot cache_slots[] = { |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 322 | {Py_tp_dealloc, pysqlite_cache_dealloc}, |
| 323 | {Py_tp_methods, cache_methods}, |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 324 | {Py_tp_init, pysqlite_cache_init}, |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 325 | {Py_tp_traverse, cache_traverse}, |
| 326 | {Py_tp_clear, cache_clear}, |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 327 | {0, NULL}, |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 328 | }; |
| 329 | |
Erlend Egeberg Aasland | 2ffba2a | 2020-11-17 13:52:54 +0100 | [diff] [blame] | 330 | static PyType_Spec cache_spec = { |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 331 | .name = MODULE_NAME ".Cache", |
| 332 | .basicsize = sizeof(pysqlite_Cache), |
Miss Islington (bot) | e8d9df0 | 2021-05-25 11:08:39 -0700 | [diff] [blame] | 333 | .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
Erlend Egeberg Aasland | 2ffba2a | 2020-11-17 13:52:54 +0100 | [diff] [blame] | 334 | .slots = cache_slots, |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 335 | }; |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 336 | PyTypeObject *pysqlite_CacheType = NULL; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 337 | |
Erlend Egeberg Aasland | 38b6c2a | 2021-02-21 11:07:49 +0100 | [diff] [blame] | 338 | int |
| 339 | pysqlite_cache_setup_types(PyObject *mod) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 340 | { |
Erlend Egeberg Aasland | 2ffba2a | 2020-11-17 13:52:54 +0100 | [diff] [blame] | 341 | pysqlite_NodeType = (PyTypeObject *)PyType_FromModuleAndSpec(mod, &node_spec, NULL); |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 342 | if (pysqlite_NodeType == NULL) { |
| 343 | return -1; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Erlend Egeberg Aasland | 2ffba2a | 2020-11-17 13:52:54 +0100 | [diff] [blame] | 346 | pysqlite_CacheType = (PyTypeObject *)PyType_FromModuleAndSpec(mod, &cache_spec, NULL); |
Erlend Egeberg Aasland | a937ab4 | 2020-09-27 14:14:50 +0200 | [diff] [blame] | 347 | if (pysqlite_CacheType == NULL) { |
| 348 | return -1; |
| 349 | } |
| 350 | return 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 351 | } |