# HG changeset patch # User kylev # Date 1234682796 0 # Node ID 78e810705b3d9f04d7226cce743fc75cf2282e52 # Parent 0da42144a012ea44244fe30cd32e73cf6daf63ec Update some of the constants and declarations to post python-2.0 convenience functions, increase related test coverage. diff -r 0da42144a012 -r 78e810705b3d _mysql.c --- a/_mysql.c Fri Feb 13 08:10:00 2009 +0000 +++ b/_mysql.c Sun Feb 15 07:26:36 2009 +0000 @@ -442,15 +442,16 @@ (as of 3.23) are NOT implemented.\n\ "; -DL_EXPORT(void) +PyMODINIT_FUNC init_mysql(void) { - PyObject *dict, *module, *emod, *edict; + PyObject *dict, *module, *emod, *edict, *version_tuple; module = Py_InitModule3("_mysql", _mysql_methods, _mysql___doc__); if (!module) return; /* this really should never happen */ + /* Populate final object settings */ _mysql_ConnectionObject_Type.ob_type = &PyType_Type; _mysql_ResultObject_Type.ob_type = &PyType_Type; _mysql_FieldObject_Type.ob_type = &PyType_Type; @@ -464,14 +465,22 @@ _mysql_FieldObject_Type.tp_new = PyType_GenericNew; _mysql_FieldObject_Type.tp_free = _PyObject_GC_Del; - if (!(dict = PyModule_GetDict(module))) goto error; - if (PyDict_SetItemString(dict, "version_info", - PyRun_String(QUOTE(version_info), Py_eval_input, - dict, dict))) + if (!(dict = PyModule_GetDict(module))) + goto error; + + /* Module constants */ + version_tuple = PyRun_String(QUOTE(version_info), Py_eval_input, + dict, dict); + if (PyModule_AddObject(module, "version_info", version_tuple) < 0) goto error; - if (PyDict_SetItemString(dict, "__version__", - PyString_FromString(QUOTE(__version__)))) + if (PyModule_AddStringConstant(module, "__version__", + QUOTE(__version__)) < 0) goto error; + if (PyModule_AddStringConstant(module, "NULL", "NULL") < 0) + goto error; + + + /* Register types */ if (PyDict_SetItemString(dict, "connection", (PyObject *)&_mysql_ConnectionObject_Type)) goto error; @@ -484,6 +493,8 @@ (PyObject *)&_mysql_FieldObject_Type)) goto error; Py_INCREF(&_mysql_FieldObject_Type); + + /* Reach into the exceptions module. */ if (!(emod = PyImport_ImportModule("MySQLdb.exceptions"))) goto error; if (!(edict = PyModule_GetDict(emod))) goto error; @@ -523,9 +534,7 @@ if (!(_mysql_error_map = PyDict_GetItemString(edict, "error_map"))) goto error; Py_DECREF(emod); - if (!(_mysql_NULL = PyString_FromString("NULL"))) - goto error; - if (PyDict_SetItemString(dict, "NULL", _mysql_NULL)) goto error; + error: if (PyErr_Occurred()) PyErr_SetString(PyExc_ImportError,