pytdb: Add __version__ attribute.
[metze/ctdb/wip.git] / lib / tdb / pytdb.c
index 402fa5d9d3a0f674cb65ad6762b6661d3fd338c5..b857438e16ec0ef6185be78f0a28275be512f6a1 100644 (file)
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <Python.h>
 #include "replace.h"
 #include "system/filesys.h"
 
-#include <Python.h>
 #ifndef Py_RETURN_NONE
 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
 #endif
@@ -97,6 +97,11 @@ static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwarg
        }
 
        ret = PyObject_New(PyTdbObject, &PyTdb);
+       if (!ret) {
+               tdb_close(ctx);
+               return NULL;
+       }
+
        ret->ctx = ctx;
        ret->closed = false;
        return (PyObject *)ret;
@@ -330,6 +335,8 @@ static PyObject *tdb_object_iter(PyTdbObject *self)
        PyTdbIteratorObject *ret;       
 
        ret = PyObject_New(PyTdbIteratorObject, &PyTdbIterator);
+       if (!ret)
+               return NULL;
        ret->current = tdb_firstkey(self->ctx);
        ret->iteratee = self;
        Py_INCREF(self);
@@ -585,6 +592,8 @@ void inittdb(void)
 
        PyModule_AddObject(m, "__docformat__", PyString_FromString("restructuredText"));
 
+       PyModule_AddObject(m, "__version__", PyString_FromString(PACKAGE_VERSION));
+
        Py_INCREF(&PyTdb);
        PyModule_AddObject(m, "Tdb", (PyObject *)&PyTdb);