Mercurial > cpython-lru_cache-weakref
diff Modules/_sqlite/module.c @ 37458:d27058c409df legacy-trunk
Update to pysqlite 2.2.0
| author | Anthony Baxter <anthonybaxter@gmail.com> |
|---|---|
| date | Tue, 04 Apr 2006 06:29:05 +0000 |
| parents | e546274d6503 |
| children | d3969aeba777 |
line wrap: on
line diff
--- a/Modules/_sqlite/module.c Tue Apr 04 06:03:50 2006 +0000 +++ b/Modules/_sqlite/module.c Tue Apr 04 06:29:05 2006 +0000 @@ -39,9 +39,6 @@ *OperationalError, *ProgrammingError, *IntegrityError, *DataError, *NotSupportedError, *OptimizedUnicode; -PyObject* time_time; -PyObject* time_sleep; - PyObject* converters; static PyObject* module_connect(PyObject* self, PyObject* args, PyObject* @@ -150,7 +147,9 @@ return NULL; } - PyDict_SetItem(converters, name, callable); + if (PyDict_SetItem(converters, name, callable) != 0) { + return NULL; + } Py_INCREF(Py_None); return Py_None; @@ -159,6 +158,9 @@ void converters_init(PyObject* dict) { converters = PyDict_New(); + if (!converters) { + return; + } PyDict_SetItemString(dict, "converters", converters); } @@ -169,8 +171,8 @@ #ifdef HAVE_SHARED_CACHE {"enable_shared_cache", (PyCFunction)module_enable_shared_cache, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("Enable or disable shared cache mode for the calling thread.")}, #endif - {"register_adapter", (PyCFunction)module_register_adapter, METH_VARARGS, PyDoc_STR("Registers an adapter with pysqlite's adapter registry.")}, - {"register_converter", (PyCFunction)module_register_converter, METH_VARARGS, PyDoc_STR("Registers a converter with pysqlite.")}, + {"register_adapter", (PyCFunction)module_register_adapter, METH_VARARGS, PyDoc_STR("Registers an adapter with sqlite's adapter registry.")}, + {"register_converter", (PyCFunction)module_register_converter, METH_VARARGS, PyDoc_STR("Registers a converter with sqlite.")}, {"adapt", (PyCFunction)psyco_microprotocols_adapt, METH_VARARGS, psyco_microprotocols_adapt_doc}, {NULL, NULL} }; @@ -178,11 +180,11 @@ PyMODINIT_FUNC init_sqlite3(void) { PyObject *module, *dict; - PyObject* time_module; + PyObject *tmp_obj; module = Py_InitModule("_sqlite3", module_methods); - if ( + if (!module || (row_setup_types() < 0) || (cursor_setup_types() < 0) || (connection_setup_types() < 0) || @@ -206,56 +208,93 @@ Py_INCREF(&RowType); PyModule_AddObject(module, "Row", (PyObject*) &RowType); - if (!(dict = PyModule_GetDict(module))) - { + if (!(dict = PyModule_GetDict(module))) { goto error; } /*** Create DB-API Exception hierarchy */ - Error = PyErr_NewException("sqlite3.Error", PyExc_StandardError, NULL); + if (!(Error = PyErr_NewException("sqlite3.Error", PyExc_StandardError, NULL))) { + goto error; + } PyDict_SetItemString(dict, "Error", Error); - Warning = PyErr_NewException("sqlite3.Warning", PyExc_StandardError, NULL); + if (!(Warning = PyErr_NewException("sqlite3.Warning", PyExc_StandardError, NULL))) { + goto error; + } PyDict_SetItemString(dict, "Warning", Warning); /* Error subclasses */ - InterfaceError = PyErr_NewException("sqlite3.InterfaceError", Error, NULL); + if (!(InterfaceError = PyErr_NewException("sqlite3.InterfaceError", Error, NULL))) { + goto error; + } PyDict_SetItemString(dict, "InterfaceError", InterfaceError); - DatabaseError = PyErr_NewException("sqlite3.DatabaseError", Error, NULL); + if (!(DatabaseError = PyErr_NewException("sqlite3.DatabaseError", Error, NULL))) { + goto error; + } PyDict_SetItemString(dict, "DatabaseError", DatabaseError); /* DatabaseError subclasses */ - InternalError = PyErr_NewException("sqlite3.InternalError", DatabaseError, NULL); + if (!(InternalError = PyErr_NewException("sqlite3.InternalError", DatabaseError, NULL))) { + goto error; + } PyDict_SetItemString(dict, "InternalError", InternalError); - OperationalError = PyErr_NewException("sqlite3.OperationalError", DatabaseError, NULL); + if (!(OperationalError = PyErr_NewException("sqlite3.OperationalError", DatabaseError, NULL))) { + goto error; + } PyDict_SetItemString(dict, "OperationalError", OperationalError); - ProgrammingError = PyErr_NewException("sqlite3.ProgrammingError", DatabaseError, NULL); + if (!(ProgrammingError = PyErr_NewException("sqlite3.ProgrammingError", DatabaseError, NULL))) { + goto error; + } PyDict_SetItemString(dict, "ProgrammingError", ProgrammingError); - IntegrityError = PyErr_NewException("sqlite3.IntegrityError", DatabaseError,NULL); + if (!(IntegrityError = PyErr_NewException("sqlite3.IntegrityError", DatabaseError,NULL))) { + goto error; + } PyDict_SetItemString(dict, "IntegrityError", IntegrityError); - DataError = PyErr_NewException("sqlite3.DataError", DatabaseError, NULL); + if (!(DataError = PyErr_NewException("sqlite3.DataError", DatabaseError, NULL))) { + goto error; + } PyDict_SetItemString(dict, "DataError", DataError); - NotSupportedError = PyErr_NewException("sqlite3.NotSupportedError", DatabaseError, NULL); + if (!(NotSupportedError = PyErr_NewException("sqlite3.NotSupportedError", DatabaseError, NULL))) { + goto error; + } PyDict_SetItemString(dict, "NotSupportedError", NotSupportedError); + /* We just need "something" unique for OptimizedUnicode. It does not really + * need to be a string subclass. Just anything that can act as a special + * marker for us. So I pulled PyCell_Type out of my magic hat. + */ Py_INCREF((PyObject*)&PyCell_Type); OptimizedUnicode = (PyObject*)&PyCell_Type; PyDict_SetItemString(dict, "OptimizedUnicode", OptimizedUnicode); - PyDict_SetItemString(dict, "PARSE_DECLTYPES", PyInt_FromLong(PARSE_DECLTYPES)); - PyDict_SetItemString(dict, "PARSE_COLNAMES", PyInt_FromLong(PARSE_COLNAMES)); + if (!(tmp_obj = PyInt_FromLong(PARSE_DECLTYPES))) { + goto error; + } + PyDict_SetItemString(dict, "PARSE_DECLTYPES", tmp_obj); + + if (!(tmp_obj = PyInt_FromLong(PARSE_COLNAMES))) { + goto error; + } + PyDict_SetItemString(dict, "PARSE_COLNAMES", tmp_obj); - PyDict_SetItemString(dict, "version", PyString_FromString(PYSQLITE_VERSION)); - PyDict_SetItemString(dict, "sqlite_version", PyString_FromString(sqlite3_libversion())); + if (!(tmp_obj = PyString_FromString(PYSQLITE_VERSION))) { + goto error; + } + PyDict_SetItemString(dict, "version", tmp_obj); + + if (!(tmp_obj = PyString_FromString(sqlite3_libversion()))) { + goto error; + } + PyDict_SetItemString(dict, "sqlite_version", tmp_obj); /* initialize microprotocols layer */ microprotocols_init(dict); @@ -263,10 +302,6 @@ /* initialize the default converters */ converters_init(dict); - time_module = PyImport_ImportModule("time"); - time_time = PyObject_GetAttrString(time_module, "time"); - time_sleep = PyObject_GetAttrString(time_module, "sleep"); - /* Original comment form _bsddb.c in the Python core. This is also still * needed nowadays for Python 2.3/2.4. *
