File: | Modules/_sqlite/module.c |
Location: | line 332, column 9 |
Description: | Access to field 'ob_refcnt' results in a dereference of a null pointer (loaded from variable 'module') |
1 | /* module.c - the module itself | ||||
2 | * | ||||
3 | * Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de> | ||||
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 "connection.h" | ||||
25 | #include "statement.h" | ||||
26 | #include "cursor.h" | ||||
27 | #include "cache.h" | ||||
28 | #include "prepare_protocol.h" | ||||
29 | #include "microprotocols.h" | ||||
30 | #include "row.h" | ||||
31 | |||||
32 | #if SQLITE_VERSION_NUMBER3007005 >= 3003003 | ||||
33 | #define HAVE_SHARED_CACHE | ||||
34 | #endif | ||||
35 | |||||
36 | /* static objects at module-level */ | ||||
37 | |||||
38 | PyObject* pysqlite_Error, *pysqlite_Warning, *pysqlite_InterfaceError, *pysqlite_DatabaseError, | ||||
39 | *pysqlite_InternalError, *pysqlite_OperationalError, *pysqlite_ProgrammingError, | ||||
40 | *pysqlite_IntegrityError, *pysqlite_DataError, *pysqlite_NotSupportedError, *pysqlite_OptimizedUnicode; | ||||
41 | |||||
42 | PyObject* converters; | ||||
43 | int _enable_callback_tracebacks; | ||||
44 | int pysqlite_BaseTypeAdapted; | ||||
45 | |||||
46 | static PyObject* module_connect(PyObject* self, PyObject* args, PyObject* | ||||
47 | kwargs) | ||||
48 | { | ||||
49 | /* Python seems to have no way of extracting a single keyword-arg at | ||||
50 | * C-level, so this code is redundant with the one in connection_init in | ||||
51 | * connection.c and must always be copied from there ... */ | ||||
52 | |||||
53 | static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL((void*)0), NULL((void*)0)}; | ||||
54 | char* database; | ||||
55 | int detect_types = 0; | ||||
56 | PyObject* isolation_level; | ||||
57 | PyObject* factory = NULL((void*)0); | ||||
58 | int check_same_thread = 1; | ||||
59 | int cached_statements; | ||||
60 | double timeout = 5.0; | ||||
61 | |||||
62 | PyObject* result; | ||||
63 | |||||
64 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOi", kwlist, | ||||
65 | &database, &timeout, &detect_types, &isolation_level, &check_same_thread, &factory, &cached_statements)) | ||||
66 | { | ||||
67 | return NULL((void*)0); | ||||
68 | } | ||||
69 | |||||
70 | if (factory == NULL((void*)0)) { | ||||
71 | factory = (PyObject*)&pysqlite_ConnectionType; | ||||
72 | } | ||||
73 | |||||
74 | result = PyObject_Call(factory, args, kwargs); | ||||
75 | |||||
76 | return result; | ||||
77 | } | ||||
78 | |||||
79 | PyDoc_STRVAR(module_connect_doc,static char module_connect_doc[] = "connect(database[, timeout, isolation_level, detect_types, factory])\n\nOpens a connection to the SQLite database file *database*. You can use\n\":memory:\" to open a database connection to a database that resides in\nRAM instead of on disk." | ||||
80 | "connect(database[, timeout, isolation_level, detect_types, factory])\n\static char module_connect_doc[] = "connect(database[, timeout, isolation_level, detect_types, factory])\n\nOpens a connection to the SQLite database file *database*. You can use\n\":memory:\" to open a database connection to a database that resides in\nRAM instead of on disk." | ||||
81 | \n\static char module_connect_doc[] = "connect(database[, timeout, isolation_level, detect_types, factory])\n\nOpens a connection to the SQLite database file *database*. You can use\n\":memory:\" to open a database connection to a database that resides in\nRAM instead of on disk." | ||||
82 | Opens a connection to the SQLite database file *database*. You can use\n\static char module_connect_doc[] = "connect(database[, timeout, isolation_level, detect_types, factory])\n\nOpens a connection to the SQLite database file *database*. You can use\n\":memory:\" to open a database connection to a database that resides in\nRAM instead of on disk." | ||||
83 | \":memory:\" to open a database connection to a database that resides in\n\static char module_connect_doc[] = "connect(database[, timeout, isolation_level, detect_types, factory])\n\nOpens a connection to the SQLite database file *database*. You can use\n\":memory:\" to open a database connection to a database that resides in\nRAM instead of on disk." | ||||
84 | RAM instead of on disk.")static char module_connect_doc[] = "connect(database[, timeout, isolation_level, detect_types, factory])\n\nOpens a connection to the SQLite database file *database*. You can use\n\":memory:\" to open a database connection to a database that resides in\nRAM instead of on disk."; | ||||
85 | |||||
86 | static PyObject* module_complete(PyObject* self, PyObject* args, PyObject* | ||||
87 | kwargs) | ||||
88 | { | ||||
89 | static char *kwlist[] = {"statement", NULL((void*)0), NULL((void*)0)}; | ||||
90 | char* statement; | ||||
91 | |||||
92 | PyObject* result; | ||||
93 | |||||
94 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &statement)) | ||||
95 | { | ||||
96 | return NULL((void*)0); | ||||
97 | } | ||||
98 | |||||
99 | if (sqlite3_complete(statement)) { | ||||
100 | result = Py_True((PyObject *) &_Py_TrueStruct); | ||||
101 | } else { | ||||
102 | result = Py_False((PyObject *) &_Py_FalseStruct); | ||||
103 | } | ||||
104 | |||||
105 | Py_INCREF(result)( _Py_RefTotal++ , ((PyObject*)(result))->ob_refcnt++); | ||||
106 | |||||
107 | return result; | ||||
108 | } | ||||
109 | |||||
110 | PyDoc_STRVAR(module_complete_doc,static char module_complete_doc[] = "complete_statement(sql)\n\nChecks if a string contains a complete SQL statement. Non-standard." | ||||
111 | "complete_statement(sql)\n\static char module_complete_doc[] = "complete_statement(sql)\n\nChecks if a string contains a complete SQL statement. Non-standard." | ||||
112 | \n\static char module_complete_doc[] = "complete_statement(sql)\n\nChecks if a string contains a complete SQL statement. Non-standard." | ||||
113 | Checks if a string contains a complete SQL statement. Non-standard.")static char module_complete_doc[] = "complete_statement(sql)\n\nChecks if a string contains a complete SQL statement. Non-standard."; | ||||
114 | |||||
115 | #ifdef HAVE_SHARED_CACHE | ||||
116 | static PyObject* module_enable_shared_cache(PyObject* self, PyObject* args, PyObject* | ||||
117 | kwargs) | ||||
118 | { | ||||
119 | static char *kwlist[] = {"do_enable", NULL((void*)0), NULL((void*)0)}; | ||||
120 | int do_enable; | ||||
121 | int rc; | ||||
122 | |||||
123 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &do_enable)) | ||||
124 | { | ||||
125 | return NULL((void*)0); | ||||
126 | } | ||||
127 | |||||
128 | rc = sqlite3_enable_shared_cache(do_enable); | ||||
129 | |||||
130 | if (rc != SQLITE_OK0) { | ||||
131 | PyErr_SetString(pysqlite_OperationalError, "Changing the shared_cache flag failed"); | ||||
132 | return NULL((void*)0); | ||||
133 | } else { | ||||
134 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); | ||||
135 | return Py_None(&_Py_NoneStruct); | ||||
136 | } | ||||
137 | } | ||||
138 | |||||
139 | PyDoc_STRVAR(module_enable_shared_cache_doc,static char module_enable_shared_cache_doc[] = "enable_shared_cache(do_enable)\n\nEnable or disable shared cache mode for the calling thread.\nExperimental/Non-standard." | ||||
140 | "enable_shared_cache(do_enable)\n\static char module_enable_shared_cache_doc[] = "enable_shared_cache(do_enable)\n\nEnable or disable shared cache mode for the calling thread.\nExperimental/Non-standard." | ||||
141 | \n\static char module_enable_shared_cache_doc[] = "enable_shared_cache(do_enable)\n\nEnable or disable shared cache mode for the calling thread.\nExperimental/Non-standard." | ||||
142 | Enable or disable shared cache mode for the calling thread.\n\static char module_enable_shared_cache_doc[] = "enable_shared_cache(do_enable)\n\nEnable or disable shared cache mode for the calling thread.\nExperimental/Non-standard." | ||||
143 | Experimental/Non-standard.")static char module_enable_shared_cache_doc[] = "enable_shared_cache(do_enable)\n\nEnable or disable shared cache mode for the calling thread.\nExperimental/Non-standard."; | ||||
144 | #endif /* HAVE_SHARED_CACHE */ | ||||
145 | |||||
146 | static PyObject* module_register_adapter(PyObject* self, PyObject* args) | ||||
147 | { | ||||
148 | PyTypeObject* type; | ||||
149 | PyObject* caster; | ||||
150 | int rc; | ||||
151 | |||||
152 | if (!PyArg_ParseTuple(args, "OO", &type, &caster)) { | ||||
153 | return NULL((void*)0); | ||||
154 | } | ||||
155 | |||||
156 | /* a basic type is adapted; there's a performance optimization if that's not the case | ||||
157 | * (99 % of all usages) */ | ||||
158 | if (type == &PyLong_Type || type == &PyFloat_Type | ||||
159 | || type == &PyUnicode_Type || type == &PyByteArray_Type) { | ||||
160 | pysqlite_BaseTypeAdapted = 1; | ||||
161 | } | ||||
162 | |||||
163 | rc = pysqlite_microprotocols_add(type, (PyObject*)&pysqlite_PrepareProtocolType, caster); | ||||
164 | if (rc == -1) | ||||
165 | return NULL((void*)0); | ||||
166 | |||||
167 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); | ||||
168 | return Py_None(&_Py_NoneStruct); | ||||
169 | } | ||||
170 | |||||
171 | PyDoc_STRVAR(module_register_adapter_doc,static char module_register_adapter_doc[] = "register_adapter(type, callable)\n\nRegisters an adapter with pysqlite's adapter registry. Non-standard." | ||||
172 | "register_adapter(type, callable)\n\static char module_register_adapter_doc[] = "register_adapter(type, callable)\n\nRegisters an adapter with pysqlite's adapter registry. Non-standard." | ||||
173 | \n\static char module_register_adapter_doc[] = "register_adapter(type, callable)\n\nRegisters an adapter with pysqlite's adapter registry. Non-standard." | ||||
174 | Registers an adapter with pysqlite's adapter registry. Non-standard.")static char module_register_adapter_doc[] = "register_adapter(type, callable)\n\nRegisters an adapter with pysqlite's adapter registry. Non-standard."; | ||||
175 | |||||
176 | static PyObject* module_register_converter(PyObject* self, PyObject* args) | ||||
177 | { | ||||
178 | PyObject* orig_name; | ||||
179 | PyObject* name = NULL((void*)0); | ||||
180 | PyObject* callable; | ||||
181 | PyObject* retval = NULL((void*)0); | ||||
182 | |||||
183 | if (!PyArg_ParseTuple(args, "UO", &orig_name, &callable)) { | ||||
184 | return NULL((void*)0); | ||||
185 | } | ||||
186 | |||||
187 | /* convert the name to upper case */ | ||||
188 | name = PyObject_CallMethod(orig_name, "upper", ""); | ||||
189 | if (!name) { | ||||
190 | goto error; | ||||
191 | } | ||||
192 | |||||
193 | if (PyDict_SetItem(converters, name, callable) != 0) { | ||||
194 | goto error; | ||||
195 | } | ||||
196 | |||||
197 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); | ||||
198 | retval = Py_None(&_Py_NoneStruct); | ||||
199 | error: | ||||
200 | Py_XDECREF(name)do { if ((name) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(name))->ob_refcnt != 0) { if (((PyObject *)name)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_sqlite/module.c" , 200, (PyObject *)(name)); } else _Py_Dealloc((PyObject *)(name )); } while (0); } while (0); | ||||
201 | return retval; | ||||
202 | } | ||||
203 | |||||
204 | PyDoc_STRVAR(module_register_converter_doc,static char module_register_converter_doc[] = "register_converter(typename, callable)\n\nRegisters a converter with pysqlite. Non-standard." | ||||
205 | "register_converter(typename, callable)\n\static char module_register_converter_doc[] = "register_converter(typename, callable)\n\nRegisters a converter with pysqlite. Non-standard." | ||||
206 | \n\static char module_register_converter_doc[] = "register_converter(typename, callable)\n\nRegisters a converter with pysqlite. Non-standard." | ||||
207 | Registers a converter with pysqlite. Non-standard.")static char module_register_converter_doc[] = "register_converter(typename, callable)\n\nRegisters a converter with pysqlite. Non-standard."; | ||||
208 | |||||
209 | static PyObject* enable_callback_tracebacks(PyObject* self, PyObject* args) | ||||
210 | { | ||||
211 | if (!PyArg_ParseTuple(args, "i", &_enable_callback_tracebacks)) { | ||||
212 | return NULL((void*)0); | ||||
213 | } | ||||
214 | |||||
215 | Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt ++); | ||||
216 | return Py_None(&_Py_NoneStruct); | ||||
217 | } | ||||
218 | |||||
219 | PyDoc_STRVAR(enable_callback_tracebacks_doc,static char enable_callback_tracebacks_doc[] = "enable_callback_tracebacks(flag)\n\nEnable or disable callback functions throwing errors to stderr." | ||||
220 | "enable_callback_tracebacks(flag)\n\static char enable_callback_tracebacks_doc[] = "enable_callback_tracebacks(flag)\n\nEnable or disable callback functions throwing errors to stderr." | ||||
221 | \n\static char enable_callback_tracebacks_doc[] = "enable_callback_tracebacks(flag)\n\nEnable or disable callback functions throwing errors to stderr." | ||||
222 | Enable or disable callback functions throwing errors to stderr.")static char enable_callback_tracebacks_doc[] = "enable_callback_tracebacks(flag)\n\nEnable or disable callback functions throwing errors to stderr."; | ||||
223 | |||||
224 | static void converters_init(PyObject* dict) | ||||
225 | { | ||||
226 | converters = PyDict_New(); | ||||
227 | if (!converters) { | ||||
228 | return; | ||||
229 | } | ||||
230 | |||||
231 | PyDict_SetItemString(dict, "converters", converters); | ||||
232 | } | ||||
233 | |||||
234 | static PyMethodDef module_methods[] = { | ||||
235 | {"connect", (PyCFunction)module_connect, | ||||
236 | METH_VARARGS0x0001 | METH_KEYWORDS0x0002, module_connect_doc}, | ||||
237 | {"complete_statement", (PyCFunction)module_complete, | ||||
238 | METH_VARARGS0x0001 | METH_KEYWORDS0x0002, module_complete_doc}, | ||||
239 | #ifdef HAVE_SHARED_CACHE | ||||
240 | {"enable_shared_cache", (PyCFunction)module_enable_shared_cache, | ||||
241 | METH_VARARGS0x0001 | METH_KEYWORDS0x0002, module_enable_shared_cache_doc}, | ||||
242 | #endif | ||||
243 | {"register_adapter", (PyCFunction)module_register_adapter, | ||||
244 | METH_VARARGS0x0001, module_register_adapter_doc}, | ||||
245 | {"register_converter", (PyCFunction)module_register_converter, | ||||
246 | METH_VARARGS0x0001, module_register_converter_doc}, | ||||
247 | {"adapt", (PyCFunction)pysqlite_adapt, METH_VARARGS0x0001, | ||||
248 | pysqlite_adapt_doc"adapt(obj, protocol, alternate) -> adapt obj to given protocol. Non-standard."}, | ||||
249 | {"enable_callback_tracebacks", (PyCFunction)enable_callback_tracebacks, | ||||
250 | METH_VARARGS0x0001, enable_callback_tracebacks_doc}, | ||||
251 | {NULL((void*)0), NULL((void*)0)} | ||||
252 | }; | ||||
253 | |||||
254 | struct _IntConstantPair { | ||||
255 | char* constant_name; | ||||
256 | int constant_value; | ||||
257 | }; | ||||
258 | |||||
259 | typedef struct _IntConstantPair IntConstantPair; | ||||
260 | |||||
261 | static IntConstantPair _int_constants[] = { | ||||
262 | {"PARSE_DECLTYPES", PARSE_DECLTYPES1}, | ||||
263 | {"PARSE_COLNAMES", PARSE_COLNAMES2}, | ||||
264 | |||||
265 | {"SQLITE_OK", SQLITE_OK0}, | ||||
266 | {"SQLITE_DENY", SQLITE_DENY1}, | ||||
267 | {"SQLITE_IGNORE", SQLITE_IGNORE2}, | ||||
268 | {"SQLITE_CREATE_INDEX", SQLITE_CREATE_INDEX1}, | ||||
269 | {"SQLITE_CREATE_TABLE", SQLITE_CREATE_TABLE2}, | ||||
270 | {"SQLITE_CREATE_TEMP_INDEX", SQLITE_CREATE_TEMP_INDEX3}, | ||||
271 | {"SQLITE_CREATE_TEMP_TABLE", SQLITE_CREATE_TEMP_TABLE4}, | ||||
272 | {"SQLITE_CREATE_TEMP_TRIGGER", SQLITE_CREATE_TEMP_TRIGGER5}, | ||||
273 | {"SQLITE_CREATE_TEMP_VIEW", SQLITE_CREATE_TEMP_VIEW6}, | ||||
274 | {"SQLITE_CREATE_TRIGGER", SQLITE_CREATE_TRIGGER7}, | ||||
275 | {"SQLITE_CREATE_VIEW", SQLITE_CREATE_VIEW8}, | ||||
276 | {"SQLITE_DELETE", SQLITE_DELETE9}, | ||||
277 | {"SQLITE_DROP_INDEX", SQLITE_DROP_INDEX10}, | ||||
278 | {"SQLITE_DROP_TABLE", SQLITE_DROP_TABLE11}, | ||||
279 | {"SQLITE_DROP_TEMP_INDEX", SQLITE_DROP_TEMP_INDEX12}, | ||||
280 | {"SQLITE_DROP_TEMP_TABLE", SQLITE_DROP_TEMP_TABLE13}, | ||||
281 | {"SQLITE_DROP_TEMP_TRIGGER", SQLITE_DROP_TEMP_TRIGGER14}, | ||||
282 | {"SQLITE_DROP_TEMP_VIEW", SQLITE_DROP_TEMP_VIEW15}, | ||||
283 | {"SQLITE_DROP_TRIGGER", SQLITE_DROP_TRIGGER16}, | ||||
284 | {"SQLITE_DROP_VIEW", SQLITE_DROP_VIEW17}, | ||||
285 | {"SQLITE_INSERT", SQLITE_INSERT18}, | ||||
286 | {"SQLITE_PRAGMA", SQLITE_PRAGMA19}, | ||||
287 | {"SQLITE_READ", SQLITE_READ20}, | ||||
288 | {"SQLITE_SELECT", SQLITE_SELECT21}, | ||||
289 | {"SQLITE_TRANSACTION", SQLITE_TRANSACTION22}, | ||||
290 | {"SQLITE_UPDATE", SQLITE_UPDATE23}, | ||||
291 | {"SQLITE_ATTACH", SQLITE_ATTACH24}, | ||||
292 | {"SQLITE_DETACH", SQLITE_DETACH25}, | ||||
293 | #if SQLITE_VERSION_NUMBER3007005 >= 3002001 | ||||
294 | {"SQLITE_ALTER_TABLE", SQLITE_ALTER_TABLE26}, | ||||
295 | {"SQLITE_REINDEX", SQLITE_REINDEX27}, | ||||
296 | #endif | ||||
297 | #if SQLITE_VERSION_NUMBER3007005 >= 3003000 | ||||
298 | {"SQLITE_ANALYZE", SQLITE_ANALYZE28}, | ||||
299 | #endif | ||||
300 | {(char*)NULL((void*)0), 0} | ||||
301 | }; | ||||
302 | |||||
303 | |||||
304 | static struct PyModuleDef _sqlite3module = { | ||||
305 | PyModuleDef_HEAD_INIT{ { 0, 0, 1, ((void*)0) }, ((void*)0), 0, ((void*)0), }, | ||||
306 | "_sqlite3", | ||||
307 | NULL((void*)0), | ||||
308 | -1, | ||||
309 | module_methods, | ||||
310 | NULL((void*)0), | ||||
311 | NULL((void*)0), | ||||
312 | NULL((void*)0), | ||||
313 | NULL((void*)0) | ||||
314 | }; | ||||
315 | |||||
316 | PyMODINIT_FUNCPyObject* PyInit__sqlite3(void) | ||||
317 | { | ||||
318 | PyObject *module, *dict; | ||||
319 | PyObject *tmp_obj; | ||||
320 | int i; | ||||
321 | |||||
322 | module = PyModule_Create(&_sqlite3module)PyModule_Create2TraceRefs(&_sqlite3module, 1013); | ||||
323 | |||||
324 | if (!module || | ||||
| |||||
325 | (pysqlite_row_setup_types() < 0) || | ||||
326 | (pysqlite_cursor_setup_types() < 0) || | ||||
327 | (pysqlite_connection_setup_types() < 0) || | ||||
328 | (pysqlite_cache_setup_types() < 0) || | ||||
329 | (pysqlite_statement_setup_types() < 0) || | ||||
330 | (pysqlite_prepare_protocol_setup_types() < 0) | ||||
331 | ) { | ||||
332 | Py_DECREF(module)do { if (_Py_RefTotal-- , --((PyObject*)(module))->ob_refcnt != 0) { if (((PyObject*)module)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/_sqlite/module.c", 332, (PyObject *)(module)); } else _Py_Dealloc((PyObject *)( module)); } while (0); | ||||
| |||||
333 | return NULL((void*)0); | ||||
334 | } | ||||
335 | |||||
336 | Py_INCREF(&pysqlite_ConnectionType)( _Py_RefTotal++ , ((PyObject*)(&pysqlite_ConnectionType) )->ob_refcnt++); | ||||
337 | PyModule_AddObject(module, "Connection", (PyObject*) &pysqlite_ConnectionType); | ||||
338 | Py_INCREF(&pysqlite_CursorType)( _Py_RefTotal++ , ((PyObject*)(&pysqlite_CursorType))-> ob_refcnt++); | ||||
339 | PyModule_AddObject(module, "Cursor", (PyObject*) &pysqlite_CursorType); | ||||
340 | Py_INCREF(&pysqlite_CacheType)( _Py_RefTotal++ , ((PyObject*)(&pysqlite_CacheType))-> ob_refcnt++); | ||||
341 | PyModule_AddObject(module, "Statement", (PyObject*)&pysqlite_StatementType); | ||||
342 | Py_INCREF(&pysqlite_StatementType)( _Py_RefTotal++ , ((PyObject*)(&pysqlite_StatementType)) ->ob_refcnt++); | ||||
343 | PyModule_AddObject(module, "Cache", (PyObject*) &pysqlite_CacheType); | ||||
344 | Py_INCREF(&pysqlite_PrepareProtocolType)( _Py_RefTotal++ , ((PyObject*)(&pysqlite_PrepareProtocolType ))->ob_refcnt++); | ||||
345 | PyModule_AddObject(module, "PrepareProtocol", (PyObject*) &pysqlite_PrepareProtocolType); | ||||
346 | Py_INCREF(&pysqlite_RowType)( _Py_RefTotal++ , ((PyObject*)(&pysqlite_RowType))->ob_refcnt ++); | ||||
347 | PyModule_AddObject(module, "Row", (PyObject*) &pysqlite_RowType); | ||||
348 | |||||
349 | if (!(dict = PyModule_GetDict(module))) { | ||||
350 | goto error; | ||||
351 | } | ||||
352 | |||||
353 | /*** Create DB-API Exception hierarchy */ | ||||
354 | |||||
355 | if (!(pysqlite_Error = PyErr_NewException(MODULE_NAME"sqlite3" ".Error", PyExc_Exception, NULL((void*)0)))) { | ||||
356 | goto error; | ||||
357 | } | ||||
358 | PyDict_SetItemString(dict, "Error", pysqlite_Error); | ||||
359 | |||||
360 | if (!(pysqlite_Warning = PyErr_NewException(MODULE_NAME"sqlite3" ".Warning", PyExc_Exception, NULL((void*)0)))) { | ||||
361 | goto error; | ||||
362 | } | ||||
363 | PyDict_SetItemString(dict, "Warning", pysqlite_Warning); | ||||
364 | |||||
365 | /* Error subclasses */ | ||||
366 | |||||
367 | if (!(pysqlite_InterfaceError = PyErr_NewException(MODULE_NAME"sqlite3" ".InterfaceError", pysqlite_Error, NULL((void*)0)))) { | ||||
368 | goto error; | ||||
369 | } | ||||
370 | PyDict_SetItemString(dict, "InterfaceError", pysqlite_InterfaceError); | ||||
371 | |||||
372 | if (!(pysqlite_DatabaseError = PyErr_NewException(MODULE_NAME"sqlite3" ".DatabaseError", pysqlite_Error, NULL((void*)0)))) { | ||||
373 | goto error; | ||||
374 | } | ||||
375 | PyDict_SetItemString(dict, "DatabaseError", pysqlite_DatabaseError); | ||||
376 | |||||
377 | /* pysqlite_DatabaseError subclasses */ | ||||
378 | |||||
379 | if (!(pysqlite_InternalError = PyErr_NewException(MODULE_NAME"sqlite3" ".InternalError", pysqlite_DatabaseError, NULL((void*)0)))) { | ||||
380 | goto error; | ||||
381 | } | ||||
382 | PyDict_SetItemString(dict, "InternalError", pysqlite_InternalError); | ||||
383 | |||||
384 | if (!(pysqlite_OperationalError = PyErr_NewException(MODULE_NAME"sqlite3" ".OperationalError", pysqlite_DatabaseError, NULL((void*)0)))) { | ||||
385 | goto error; | ||||
386 | } | ||||
387 | PyDict_SetItemString(dict, "OperationalError", pysqlite_OperationalError); | ||||
388 | |||||
389 | if (!(pysqlite_ProgrammingError = PyErr_NewException(MODULE_NAME"sqlite3" ".ProgrammingError", pysqlite_DatabaseError, NULL((void*)0)))) { | ||||
390 | goto error; | ||||
391 | } | ||||
392 | PyDict_SetItemString(dict, "ProgrammingError", pysqlite_ProgrammingError); | ||||
393 | |||||
394 | if (!(pysqlite_IntegrityError = PyErr_NewException(MODULE_NAME"sqlite3" ".IntegrityError", pysqlite_DatabaseError,NULL((void*)0)))) { | ||||
395 | goto error; | ||||
396 | } | ||||
397 | PyDict_SetItemString(dict, "IntegrityError", pysqlite_IntegrityError); | ||||
398 | |||||
399 | if (!(pysqlite_DataError = PyErr_NewException(MODULE_NAME"sqlite3" ".DataError", pysqlite_DatabaseError, NULL((void*)0)))) { | ||||
400 | goto error; | ||||
401 | } | ||||
402 | PyDict_SetItemString(dict, "DataError", pysqlite_DataError); | ||||
403 | |||||
404 | if (!(pysqlite_NotSupportedError = PyErr_NewException(MODULE_NAME"sqlite3" ".NotSupportedError", pysqlite_DatabaseError, NULL((void*)0)))) { | ||||
405 | goto error; | ||||
406 | } | ||||
407 | PyDict_SetItemString(dict, "NotSupportedError", pysqlite_NotSupportedError); | ||||
408 | |||||
409 | /* We just need "something" unique for pysqlite_OptimizedUnicode. It does not really | ||||
410 | * need to be a string subclass. Just anything that can act as a special | ||||
411 | * marker for us. So I pulled PyCell_Type out of my magic hat. | ||||
412 | */ | ||||
413 | Py_INCREF((PyObject*)&PyCell_Type)( _Py_RefTotal++ , ((PyObject*)((PyObject*)&PyCell_Type)) ->ob_refcnt++); | ||||
414 | pysqlite_OptimizedUnicode = (PyObject*)&PyCell_Type; | ||||
415 | PyDict_SetItemString(dict, "OptimizedUnicode", pysqlite_OptimizedUnicode); | ||||
416 | |||||
417 | /* Set integer constants */ | ||||
418 | for (i = 0; _int_constants[i].constant_name != 0; i++) { | ||||
419 | tmp_obj = PyLong_FromLong(_int_constants[i].constant_value); | ||||
420 | if (!tmp_obj) { | ||||
421 | goto error; | ||||
422 | } | ||||
423 | PyDict_SetItemString(dict, _int_constants[i].constant_name, tmp_obj); | ||||
424 | Py_DECREF(tmp_obj)do { if (_Py_RefTotal-- , --((PyObject*)(tmp_obj))->ob_refcnt != 0) { if (((PyObject*)tmp_obj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/_sqlite/module.c", 424, (PyObject *)(tmp_obj)); } else _Py_Dealloc((PyObject *) (tmp_obj)); } while (0); | ||||
425 | } | ||||
426 | |||||
427 | if (!(tmp_obj = PyUnicode_FromStringPyUnicodeUCS2_FromString(PYSQLITE_VERSION"2.6.0"))) { | ||||
428 | goto error; | ||||
429 | } | ||||
430 | PyDict_SetItemString(dict, "version", tmp_obj); | ||||
431 | Py_DECREF(tmp_obj)do { if (_Py_RefTotal-- , --((PyObject*)(tmp_obj))->ob_refcnt != 0) { if (((PyObject*)tmp_obj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/_sqlite/module.c", 431, (PyObject *)(tmp_obj)); } else _Py_Dealloc((PyObject *) (tmp_obj)); } while (0); | ||||
432 | |||||
433 | if (!(tmp_obj = PyUnicode_FromStringPyUnicodeUCS2_FromString(sqlite3_libversion()))) { | ||||
434 | goto error; | ||||
435 | } | ||||
436 | PyDict_SetItemString(dict, "sqlite_version", tmp_obj); | ||||
437 | Py_DECREF(tmp_obj)do { if (_Py_RefTotal-- , --((PyObject*)(tmp_obj))->ob_refcnt != 0) { if (((PyObject*)tmp_obj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/_sqlite/module.c", 437, (PyObject *)(tmp_obj)); } else _Py_Dealloc((PyObject *) (tmp_obj)); } while (0); | ||||
438 | |||||
439 | /* initialize microprotocols layer */ | ||||
440 | pysqlite_microprotocols_init(dict); | ||||
441 | |||||
442 | /* initialize the default converters */ | ||||
443 | converters_init(dict); | ||||
444 | |||||
445 | _enable_callback_tracebacks = 0; | ||||
446 | |||||
447 | pysqlite_BaseTypeAdapted = 0; | ||||
448 | |||||
449 | /* Original comment from _bsddb.c in the Python core. This is also still | ||||
450 | * needed nowadays for Python 2.3/2.4. | ||||
451 | * | ||||
452 | * PyEval_InitThreads is called here due to a quirk in python 1.5 | ||||
453 | * - 2.2.1 (at least) according to Russell Williamson <merel@wt.net>: | ||||
454 | * The global interpreter lock is not initialized until the first | ||||
455 | * thread is created using thread.start_new_thread() or fork() is | ||||
456 | * called. that would cause the ALLOW_THREADS here to segfault due | ||||
457 | * to a null pointer reference if no threads or child processes | ||||
458 | * have been created. This works around that and is a no-op if | ||||
459 | * threads have already been initialized. | ||||
460 | * (see pybsddb-users mailing list post on 2002-08-07) | ||||
461 | */ | ||||
462 | #ifdef WITH_THREAD1 | ||||
463 | PyEval_InitThreads(); | ||||
464 | #endif | ||||
465 | |||||
466 | error: | ||||
467 | if (PyErr_Occurred()) | ||||
468 | { | ||||
469 | PyErr_SetString(PyExc_ImportError, MODULE_NAME"sqlite3" ": init failed"); | ||||
470 | Py_DECREF(module)do { if (_Py_RefTotal-- , --((PyObject*)(module))->ob_refcnt != 0) { if (((PyObject*)module)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/_sqlite/module.c", 470, (PyObject *)(module)); } else _Py_Dealloc((PyObject *)( module)); } while (0); | ||||
471 | module = NULL((void*)0); | ||||
472 | } | ||||
473 | return module; | ||||
474 | } |