summaryrefslogtreecommitdiff
path: root/source/lib/tdb
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2008-09-14 19:21:54 +0200
committerStefan Metzmacher <metze@samba.org>2008-09-14 19:23:00 +0200
commitbdb8ed24488fd87cd30dd18744feeef0bd4b2c18 (patch)
treedb6e7604f63c81f193d74d65e328d8b26640dd0d /source/lib/tdb
parent0143c320ccf21c00e1a09b8363cd42724b76faf9 (diff)
downloadsamba-v3-devel.tar.gz
samba-v3-devel.tar.bz2
samba-v3-devel.zip
lib/tdb: sync build system changes and python code from samba4v3-devel
metze
Diffstat (limited to 'source/lib/tdb')
-rw-r--r--source/lib/tdb/Makefile.in99
-rwxr-xr-xsource/lib/tdb/autogen.sh2
-rw-r--r--source/lib/tdb/config.mk37
-rw-r--r--source/lib/tdb/configure.ac18
-rw-r--r--source/lib/tdb/libtdb.m432
-rw-r--r--source/lib/tdb/python.mk10
-rw-r--r--source/lib/tdb/python/tdbdump.py12
-rw-r--r--source/lib/tdb/python/tests/simple.py152
-rw-r--r--source/lib/tdb/rules.mk21
-rw-r--r--source/lib/tdb/swig/Tdb.py115
-rw-r--r--source/lib/tdb/swig/tdb.i167
-rw-r--r--source/lib/tdb/tdb.i323
-rw-r--r--source/lib/tdb/tdb.mk86
-rw-r--r--source/lib/tdb/tdb.pc.in1
-rw-r--r--source/lib/tdb/tdb.py341
-rw-r--r--source/lib/tdb/tdb_wrap.c4307
16 files changed, 5308 insertions, 415 deletions
diff --git a/source/lib/tdb/Makefile.in b/source/lib/tdb/Makefile.in
index fd36ed078e1..090bb6e2dcf 100644
--- a/source/lib/tdb/Makefile.in
+++ b/source/lib/tdb/Makefile.in
@@ -16,97 +16,44 @@ CPPFLAGS = @CPPFLAGS@ -I$(srcdir)/include -Iinclude
CFLAGS = $(CPPFLAGS) @CFLAGS@
LDFLAGS = @LDFLAGS@
EXEEXT = @EXEEXT@
+SHLD = @SHLD@
SHLD_FLAGS = @SHLD_FLAGS@
PACKAGE_VERSION = @PACKAGE_VERSION@
PICFLAG = @PICFLAG@
-SONAMEFLAG = @SONAMEFLAG@
SHLIBEXT = @SHLIBEXT@
-
-.PHONY: test
-
-PROGS = bin/tdbtool$(EXEEXT) bin/tdbdump$(EXEEXT) bin/tdbbackup$(EXEEXT)
-PROGS_NOINSTALL = bin/tdbtest$(EXEEXT) bin/tdbtorture$(EXEEXT)
-ALL_PROGS = $(PROGS) $(PROGS_NOINSTALL)
+SWIG = swig
+PYTHON = @PYTHON@
+PYTHON_CONFIG = @PYTHON_CONFIG@
+PYTHON_BUILD_TARGET = @PYTHON_BUILD_TARGET@
+PYTHON_INSTALL_TARGET = @PYTHON_INSTALL_TARGET@
+PYTHON_CHECK_TARGET = @PYTHON_CHECK_TARGET@
+LIB_PATH_VAR = @LIB_PATH_VAR@
+tdbdir = @tdbdir@
TDB_OBJ = @TDB_OBJ@ @LIBREPLACEOBJ@
-DIRS = bin common tools
-
-SONAME = libtdb.$(SHLIBEXT).1
-SOLIB = libtdb.$(SHLIBEXT).$(PACKAGE_VERSION)
-
-all: showflags dirs $(PROGS) $(SOLIB) libtdb.a
-
-showflags:
- @echo 'tdb will be compiled with flags:'
- @echo ' CFLAGS = $(CFLAGS)'
- @echo ' CPPFLAGS = $(CPPFLAGS)'
- @echo ' LDFLAGS = $(LDFLAGS)'
- @echo ' LIBS = $(LIBS)'
-
-.SUFFIXES: .c .o
-
-.c.o:
- @echo Compiling $*.c
- @mkdir -p `dirname $@`
- @$(CC) $(PICFLAG) $(CFLAGS) -c $< -o $@
-
-dirs:
- @mkdir -p $(DIRS)
-
-install: all
- mkdir -p $(DESTDIR)$(bindir)
- mkdir -p $(DESTDIR)$(includedir)
- mkdir -p $(DESTDIR)$(libdir)
- mkdir -p $(DESTDIR)$(libdir)/pkgconfig
- cp $(PROGS) $(DESTDIR)$(bindir)
- cp $(srcdir)/include/tdb.h $(DESTDIR)$(includedir)
- cp tdb.pc $(DESTDIR)$(libdir)/pkgconfig
- cp libtdb.a $(SOLIB) $(DESTDIR)$(libdir)
-
-libtdb.a: $(TDB_OBJ)
- ar -rv libtdb.a $(TDB_OBJ)
-
-libtdb.(SHLIBEXT): $(SOLIB)
- ln -s $< $@
-
-$(SONAME): $(SOLIB)
- ln -s $< $@
-
-$(SOLIB): $(TDB_OBJ)
- $(CC) $(SHLD_FLAGS) -o $@ $(TDB_OBJ) $(SONAMEFLAG)$(SONAME)
-
-TDB_LIB = libtdb.a
-
-bin/tdbtest$(EXEEXT): tools/tdbtest.o $(TDB_LIB)
- $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtest tools/tdbtest.o -L. -ltdb -lgdbm
-
-bin/tdbtool$(EXEEXT): tools/tdbtool.o $(TDB_LIB)
- $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtool tools/tdbtool.o -L. -ltdb
+default: all
-bin/tdbtorture$(EXEEXT): tools/tdbtorture.o $(TDB_LIB)
- $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtorture tools/tdbtorture.o -L. -ltdb
+include $(tdbdir)/tdb.mk
+include $(tdbdir)/rules.mk
-bin/tdbdump$(EXEEXT): tools/tdbdump.o $(TDB_LIB)
- $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbdump tools/tdbdump.o -L. -ltdb
+all:: showflags dirs $(PROGS) $(TDB_SOLIB) libtdb.a $(PYTHON_BUILD_TARGET)
-bin/tdbbackup$(EXEEXT): tools/tdbbackup.o $(TDB_LIB)
- $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbbackup tools/tdbbackup.o -L. -ltdb
+install:: all
+$(TDB_SOLIB): $(TDB_OBJ)
+ $(SHLD) $(SHLD_FLAGS) -o $@ $(TDB_OBJ) @SONAMEFLAG@$(TDB_SONAME)
-test: bin/tdbtorture$(EXEEXT)
- bin/tdbtorture$(EXEEXT)
+check: test
-installcheck: test install
+test:: $(PYTHON_CHECK_TARGET)
+installcheck:: test install
-clean:
- rm -f $(ALL_PROGS) *.o *.a common/*.o tools/*.o tdb.pc
- rm -f test.db test.tdb torture.tdb test.gdbm
- rm -f $(SONAME) $(SOLIB) libtdb.a
+clean::
+ rm -f *.o *.a */*.o
-distclean: clean
- rm -f *~ */*~
+distclean:: clean
rm -f config.log config.status include/config.h config.cache
rm -f Makefile
-realdistclean: distclean
+realdistclean:: distclean
rm -f configure include/config.h.in
diff --git a/source/lib/tdb/autogen.sh b/source/lib/tdb/autogen.sh
index bf84eeee19a..88ac4cfcf73 100755
--- a/source/lib/tdb/autogen.sh
+++ b/source/lib/tdb/autogen.sh
@@ -9,6 +9,8 @@ autoheader $IPATHS || exit 1
rm -rf autom4te.cache
+swig -O -Wall -python -keyword tdb.i # Ignore errors for now
+
echo "Now run ./configure and then make."
exit 0
diff --git a/source/lib/tdb/config.mk b/source/lib/tdb/config.mk
index 01a23f00de2..b9a8f80dda5 100644
--- a/source/lib/tdb/config.mk
+++ b/source/lib/tdb/config.mk
@@ -1,68 +1,57 @@
################################################
# Start SUBSYSTEM LIBTDB
[LIBRARY::LIBTDB]
-VERSION = 0.0.1
-SO_VERSION = 0
-PC_FILE = tdb.pc
-OBJ_FILES = \
- common/tdb.o common/dump.o common/io.o common/lock.o \
- common/open.o common/traverse.o common/freelist.o \
- common/error.o common/transaction.o
+OUTPUT_TYPE = STATIC_LIBRARY
CFLAGS = -Ilib/tdb/include
-PUBLIC_HEADERS = include/tdb.h
#
# End SUBSYSTEM ldb
################################################
+LIBTDB_OBJ_FILES = $(addprefix lib/tdb/common/, \
+ tdb.o dump.o io.o lock.o \
+ open.o traverse.o freelist.o \
+ error.o transaction.o)
+
################################################
# Start BINARY tdbtool
[BINARY::tdbtool]
INSTALLDIR = BINDIR
-OBJ_FILES= \
- tools/tdbtool.o
PRIVATE_DEPENDENCIES = \
LIBTDB
# End BINARY tdbtool
################################################
+tdbtool_OBJ_FILES = lib/tdb/tools/tdbtool.o
+
################################################
# Start BINARY tdbtorture
[BINARY::tdbtorture]
INSTALLDIR = BINDIR
-OBJ_FILES= \
- tools/tdbtorture.o
PRIVATE_DEPENDENCIES = \
LIBTDB
# End BINARY tdbtorture
################################################
+tdbtorture_OBJ_FILES = lib/tdb/tools/tdbtorture.o
+
################################################
# Start BINARY tdbdump
[BINARY::tdbdump]
INSTALLDIR = BINDIR
-OBJ_FILES= \
- tools/tdbdump.o
PRIVATE_DEPENDENCIES = \
LIBTDB
# End BINARY tdbdump
################################################
+tdbdump_OBJ_FILES = lib/tdb/tools/tdbdump.o
+
################################################
# Start BINARY tdbbackup
[BINARY::tdbbackup]
INSTALLDIR = BINDIR
-OBJ_FILES= \
- tools/tdbbackup.o
PRIVATE_DEPENDENCIES = \
LIBTDB
# End BINARY tdbbackup
################################################
-#######################
-# Start LIBRARY swig_tdb
-[LIBRARY::swig_tdb]
-LIBRARY_REALNAME = swig/_tdb.$(SHLIBEXT)
-OBJ_FILES = swig/tdb_wrap.o
-PUBLIC_DEPENDENCIES = LIBTDB DYNCONFIG
-# End LIBRARY swig_tdb
-#######################
+tdbbackup_OBJ_FILES = lib/tdb/tools/tdbbackup.o
diff --git a/source/lib/tdb/configure.ac b/source/lib/tdb/configure.ac
index 14761bcc1a5..eaf70d30b44 100644
--- a/source/lib/tdb/configure.ac
+++ b/source/lib/tdb/configure.ac
@@ -2,13 +2,29 @@ AC_PREREQ(2.50)
AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""])
AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""])
AC_DEFUN([SMB_ENABLE], [echo -n ""])
-AC_INIT(tdb, 1.1.1)
+AC_INIT(tdb, 1.1.2)
AC_CONFIG_SRCDIR([common/tdb.c])
AC_CONFIG_HEADER(include/config.h)
AC_LIBREPLACE_ALL_CHECKS
AC_LD_SONAMEFLAG
AC_LD_PICFLAG
AC_LD_SHLIBEXT
+AC_LIBREPLACE_SHLD
AC_LIBREPLACE_SHLD_FLAGS
+AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR
m4_include(libtdb.m4)
+AC_PATH_PROGS([PYTHON_CONFIG], [python2.6-config python2.5-config python2.4-config python-config])
+AC_PATH_PROGS([PYTHON], [python2.6 python2.5 python2.4 python])
+
+PYTHON_BUILD_TARGET="build-python"
+PYTHON_INSTALL_TARGET="install-python"
+PYTHON_CHECK_TARGET="check-python"
+AC_SUBST(PYTHON_BUILD_TARGET)
+AC_SUBST(PYTHON_INSTALL_TARGET)
+AC_SUBST(PYTHON_CHECK_TARGET)
+if test -z "$PYTHON_CONFIG"; then
+ PYTHON_BUILD_TARGET=""
+ PYTHON_INSTALL_TARGET=""
+ PYTHON_CHECK_TARGET=""
+fi
AC_OUTPUT(Makefile tdb.pc)
diff --git a/source/lib/tdb/libtdb.m4 b/source/lib/tdb/libtdb.m4
index 7682edada93..1e17a7a4f23 100644
--- a/source/lib/tdb/libtdb.m4
+++ b/source/lib/tdb/libtdb.m4
@@ -28,35 +28,3 @@ AC_CHECK_HEADERS(getopt.h sys/select.h sys/time.h)
AC_HAVE_DECL(pread, [#include <unistd.h>])
AC_HAVE_DECL(pwrite, [#include <unistd.h>])
-
-AC_MSG_CHECKING([for Python])
-
-PYTHON=
-
-AC_ARG_WITH(python,
-[ --with-python=PYTHONNAME build Python libraries],
-[ case "${withval-python}" in
- yes)
- PYTHON=python
- ;;
- no)
- PYTHON=
- ;;
- *)
- PYTHON=${withval-python}
- ;;
- esac ])
-
-if test x"$PYTHON" != "x"; then
- incdir=`python -c 'import sys; print "%s/include/python%d.%d" % (sys.prefix, sys.version_info[[0]], sys.version_info[[1]])'`
- CPPFLAGS="$CPPFLAGS -I $incdir"
-fi
-
-if test x"$PYTHON" != "x"; then
- AC_MSG_RESULT([${withval-python}])
-else
- SMB_ENABLE(swig_tdb, NO)
- AC_MSG_RESULT(no)
-fi
-
-AC_SUBST(PYTHON)
diff --git a/source/lib/tdb/python.mk b/source/lib/tdb/python.mk
new file mode 100644
index 00000000000..12e8217df99
--- /dev/null
+++ b/source/lib/tdb/python.mk
@@ -0,0 +1,10 @@
+[PYTHON::swig_tdb]
+LIBRARY_REALNAME = _tdb.$(SHLIBEXT)
+PUBLIC_DEPENDENCIES = LIBTDB DYNCONFIG
+
+swig_tdb_OBJ_FILES = $(tdbsrcdir)/tdb_wrap.o
+
+$(eval $(call python_py_module_template,tdb.py,$(tdbsrcdir)/tdb.py))
+
+$(swig_tdb_OBJ_FILES): CFLAGS+=$(CFLAG_NO_UNUSED_MACROS) $(CFLAG_NO_CAST_QUAL)
+
diff --git a/source/lib/tdb/python/tdbdump.py b/source/lib/tdb/python/tdbdump.py
new file mode 100644
index 00000000000..d759d771c87
--- /dev/null
+++ b/source/lib/tdb/python/tdbdump.py
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+# Trivial reimplementation of tdbdump in Python
+
+import tdb, sys
+
+if len(sys.argv) < 2:
+ print "Usage: tdbdump.py <tdb-file>"
+ sys.exit(1)
+
+db = tdb.Tdb(sys.argv[1])
+for (k, v) in db.iteritems():
+ print "{\nkey(%d) = %r\ndata(%d) = %r\n}" % (len(k), k, len(v), v)
diff --git a/source/lib/tdb/python/tests/simple.py b/source/lib/tdb/python/tests/simple.py
new file mode 100644
index 00000000000..7147718c91f
--- /dev/null
+++ b/source/lib/tdb/python/tests/simple.py
@@ -0,0 +1,152 @@
+#!/usr/bin/python
+# Some simple tests for the Python bindings for TDB
+# Note that this tests the interface of the Python bindings
+# It does not test tdb itself.
+#
+# Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
+# Published under the GNU LGPLv3 or later
+
+import tdb
+from unittest import TestCase
+import os, tempfile
+
+
+class OpenTdbTests(TestCase):
+ def test_nonexistant_read(self):
+ self.assertRaises(IOError, tdb.Tdb, "/some/nonexistant/file", 0, tdb.DEFAULT, os.O_RDWR)
+
+
+class SimpleTdbTests(TestCase):
+ def setUp(self):
+ super(SimpleTdbTests, self).setUp()
+ self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT, os.O_CREAT|os.O_RDWR)
+ self.assertNotEqual(None, self.tdb)
+
+ def tearDown(self):
+ del self.tdb
+
+ def test_repr(self):
+ self.assertTrue(repr(self.tdb).startswith("Tdb('"))
+
+ def test_lockall(self):
+ self.tdb.lock_all()
+
+ def test_max_dead(self):
+ self.tdb.max_dead = 20
+
+ def test_unlockall(self):
+ self.tdb.lock_all()
+ self.tdb.unlock_all()
+
+ def test_lockall_read(self):
+ self.tdb.read_lock_all()
+ self.tdb.read_unlock_all()
+
+ def test_reopen(self):
+ self.tdb.reopen()
+
+ def test_store(self):
+ self.tdb.store("bar", "bla")
+ self.assertEquals("bla", self.tdb.get("bar"))
+
+ def test_getitem(self):
+ self.tdb["bar"] = "foo"
+ self.tdb.reopen()
+ self.assertEquals("foo", self.tdb["bar"])
+
+ def test_delete(self):
+ self.tdb["bar"] = "foo"
+ del self.tdb["bar"]
+ self.assertRaises(KeyError, lambda: self.tdb["bar"])
+
+ def test_contains(self):
+ self.tdb["bla"] = "bloe"
+ self.assertTrue("bla" in self.tdb)
+
+ def test_keyerror(self):
+ self.assertRaises(KeyError, lambda: self.tdb["bla"])
+
+ def test_hash_size(self):
+ self.tdb.hash_size
+
+ def test_map_size(self):
+ self.tdb.map_size
+
+ def test_name(self):
+ self.tdb.name
+
+ def test_iterator(self):
+ self.tdb["bla"] = "1"
+ self.tdb["brainslug"] = "2"
+ self.assertEquals(["bla", "brainslug"], list(self.tdb))
+
+ def test_items(self):
+ self.tdb["bla"] = "1"
+ self.tdb["brainslug"] = "2"
+ self.assertEquals([("bla", "1"), ("brainslug", "2")], self.tdb.items())
+
+ def test_iteritems(self):
+ self.tdb["bloe"] = "2"
+ self.tdb["bla"] = "25"
+ i = self.tdb.iteritems()
+ self.assertEquals(set([("bla", "25"), ("bloe", "2")]),
+ set([i.next(), i.next()]))
+
+ def test_transaction_cancel(self):
+ self.tdb["bloe"] = "2"
+ self.tdb.transaction_start()
+ self.tdb["bloe"] = "1"
+ self.tdb.transaction_cancel()
+ self.assertEquals("2", self.tdb["bloe"])
+
+ def test_transaction_commit(self):
+ self.tdb["bloe"] = "2"
+ self.tdb.transaction_start()
+ self.tdb["bloe"] = "1"
+ self.tdb.transaction_commit()
+ self.assertEquals("1", self.tdb["bloe"])
+
+ def test_iterator(self):
+ self.tdb["bloe"] = "2"
+ self.tdb["bla"] = "hoi"
+ i = iter(self.tdb)
+ self.assertEquals(set(["bloe", "bla"]), set([i.next(), i.next()]))
+
+ def test_keys(self):
+ self.tdb["bloe"] = "2"
+ self.tdb["bla"] = "25"
+ self.assertEquals(["bla", "bloe"], self.tdb.keys())
+
+ def test_iterkeys(self):
+ self.tdb["bloe"] = "2"
+ self.tdb["bla"] = "25"
+ i = self.tdb.iterkeys()
+ self.assertEquals(set(["bloe", "bla"]), set([i.next(), i.next()]))
+
+ def test_values(self):
+ self.tdb["bloe"] = "2"
+ self.tdb["bla"] = "25"
+ self.assertEquals(["25", "2"], self.tdb.values())
+
+ def test_itervalues(self):
+ self.tdb["bloe"] = "2"
+ self.tdb["bla"] = "25"
+ i = self.tdb.itervalues()
+ self.assertEquals(set(["25", "2"]), set([i.next(), i.next()]))
+
+ def test_clear(self):
+ self.tdb["bloe"] = "2"
+ self.tdb["bla"] = "25"
+ self.assertEquals(2, len(self.tdb))
+ self.tdb.clear()
+ self.assertEquals(0, len(self.tdb))
+
+ def test_len(self):
+ self.assertEquals(0, len(self.tdb))
+ self.tdb["entry"] = "value"
+ self.assertEquals(1, len(self.tdb))
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.TestProgram()
diff --git a/source/lib/tdb/rules.mk b/source/lib/tdb/rules.mk
new file mode 100644
index 00000000000..7b765625dfc
--- /dev/null
+++ b/source/lib/tdb/rules.mk
@@ -0,0 +1,21 @@
+.SUFFIXES: .i _wrap.c
+
+.i_wrap.c:
+ $(SWIG) -O -Wall -python -keyword $<
+
+showflags::
+ @echo 'tdb will be compiled with flags:'
+ @echo ' CFLAGS = $(CFLAGS)'
+ @echo ' CPPFLAGS = $(CPPFLAGS)'
+ @echo ' LDFLAGS = $(LDFLAGS)'
+ @echo ' LIBS = $(LIBS)'
+
+.SUFFIXES: .c .o
+
+.c.o:
+ @echo Compiling $*.c
+ @mkdir -p `dirname $@`
+ @$(CC) $(PICFLAG) $(CFLAGS) -c $< -o $@
+
+distclean::
+ rm -f *~ */*~
diff --git a/source/lib/tdb/swig/Tdb.py b/source/lib/tdb/swig/Tdb.py
deleted file mode 100644
index 529d0753d11..00000000000
--- a/source/lib/tdb/swig/Tdb.py
+++ /dev/null
@@ -1,115 +0,0 @@
-"""Provide a more Pythonic and object-oriented interface to tdb."""
-
-#
-# Swig interface to Samba
-#
-# Copyright (C) Tim Potter 2006
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
-
-import os
-from tdb import *
-
-# Open flags
-
-DEFAULT = TDB_DEFAULT
-CLEAR_IF_FIRST = TDB_CLEAR_IF_FIRST
-INTERNAL = TDB_INTERNAL
-NOLOCK = TDB_NOLOCK
-NOMMAP = TDB_NOMMAP
-
-# Class representing a TDB file
-
-class Tdb:
-
- # Create and destroy Tdb objects
-
- def __init__(self, name, hash_size = 0, flags = TDB_DEFAULT,
- open_flags = os.O_RDWR | os.O_CREAT, mode = 0600):
- self.tdb = tdb_open(name, hash_size, flags, open_flags, mode)
- if self.tdb is None:
- raise IOError, tdb_errorstr(self.tdb)
-
- def __del__(self):
- self.close()
-
- def close(self):
- if hasattr(self, 'tdb') and self.tdb is not None:
- if tdb_close(self.tdb) == -1:
- raise IOError, tdb_errorstr(self.tdb)
- self.tdb = None
-
- # Random access to keys, values
-
- def __getitem__(self, key):
- result = tdb_fetch(self.tdb, key)
- if result is None:
- raise KeyError, '%s: %s' % (key, tdb_errorstr(self.tdb))
- return result
-
- def __setitem__(self, key, item):
- if tdb_store(self.tdb, key, item) == -1:
- raise IOError, tdb_errorstr(self.tdb)
-
- def __delitem__(self, key):
- if not tdb_exists(self.tdb, key):
- raise KeyError, '%s: %s' % (key, tdb_errorstr(self.tdb))
- tdb_delete(self.tdb, key)
-
- def has_key(self, key):
- return tdb_exists(self.tdb, key)
-
- # Tdb iterator
-
- class TdbIterator:
- def __init__(self, tdb):
- self.tdb = tdb
- self.key = None
-
- def __iter__(self):
- return self
-
- def next(self):
- if self.key is None:
- self.key = tdb_firstkey(self.tdb)
- if self.key is None:
- raise StopIteration
- return self.key
- else:
- self.key = tdb_nextkey(self.tdb, self.key)
- if self.key is None:
- raise StopIteration
- return self.key
-
- def __iter__(self):
- return Tdb.TdbIterator(self.tdb)
-
- # Implement other dict functions using TdbIterator
-
- def keys(self):
- return [k for k in iter(self)]
-
- def values(self):
- return [self[k] for k in iter(self)]
-
- def items(self):
- return [(k, self[k]) for k in iter(self)]
-
- def __len__(self):
- return len(self.keys())
-
- def clear(self):
- for k in iter(self):
- del(self[k])
diff --git a/source/lib/tdb/swig/tdb.i b/source/lib/tdb/swig/tdb.i
deleted file mode 100644
index fbb0f29dec1..00000000000
--- a/source/lib/tdb/swig/tdb.i
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- Swig interface to tdb.
-
- Copyright (C) 2004,2005 Tim Potter <tpot@samba.org>
-
- ** NOTE! The following LGPL license applies to the tdb
- ** library. This does NOT imply that all of Samba is released
- ** under the LGPL
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 3 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, see <http://www.gnu.org/licenses/>.
-*/
-
-%module tdb
-
-%{
-
-/* This symbol is used in both includes.h and Python.h which causes an
- annoying compiler warning. */
-
-#ifdef HAVE_FSTAT
-#undef HAVE_FSTAT
-#endif
-
-#if (__GNUC__ >= 3)
-/** Use gcc attribute to check printf fns. a1 is the 1-based index of
- * the parameter containing the format, and a2 the index of the first
- * argument. Note that some gcc 2.x versions don't handle this
- * properly **/
-#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
-#else
-#define PRINTF_ATTRIBUTE(a1, a2)
-#endif
-
-/* Include tdb headers */
-
-#include "lib/tdb/include/tdb.h"
-
-%}
-
-/* The tdb functions will crash if a NULL tdb context is passed */
-
-%include exception.i
-
-%typemap(check) TDB_CONTEXT* {
- if ($1 == NULL)
- SWIG_exception(SWIG_ValueError,
- "tdb context must be non-NULL");
-}
-
-/* In and out typemaps for the TDB_DATA structure. This is converted to
- and from the Python string type which can contain arbitrary binary
- data.. */
-
-%typemap(in) TDB_DATA {
- if (!PyString_Check($input)) {
- PyErr_SetString(PyExc_TypeError, "string arg expected");
- return NULL;
- }
- $1.dsize = PyString_Size($input);
- $1.dptr = PyString_AsString($input);
-}
-
-%typemap(out) TDB_DATA {
- if ($1.dptr == NULL && $1.dsize == 0) {
- $result = Py_None;
- } else {
- $result = PyString_FromStringAndSize($1.dptr, $1.dsize);
- free($1.dptr);
- }
-}
-
-/* Treat a mode_t as an unsigned integer */
-
-typedef int mode_t;
-
-/* flags to tdb_store() */
-
-#define TDB_REPLACE 1
-#define TDB_INSERT 2
-#define TDB_MODIFY 3
-
-/* flags for tdb_open() */
-
-#define TDB_DEFAULT 0 /* just a readability place holder */
-#define TDB_CLEAR_IF_FIRST 1
-#define TDB_INTERNAL 2 /* don't store on disk */
-#define TDB_NOLOCK 4 /* don't do any locking */
-#define TDB_NOMMAP 8 /* don't use mmap */
-#define TDB_CONVERT 16 /* convert endian (internal use) */
-#define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
-
-/* Throw an IOError exception if tdb_open() or tdb_open_ex() returns NULL */
-
-%exception {
- $action
- if (result == NULL) {
- PyErr_SetFromErrno(PyExc_IOError);
- SWIG_fail;
- }
-}
-
-TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags,
- int open_flags, mode_t mode);
-
-TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
- int open_flags, mode_t mode,
- tdb_log_func log_fn,
- tdb_hash_func hash_fn);
-
-%exception;
-
-int tdb_reopen(TDB_CONTEXT *tdb);
-
-int tdb_reopen_all(int parent_longlived);
-
-void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func);
-
-enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb);
-
-const char *tdb_errorstr(TDB_CONTEXT *tdb);
-
-TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
-
-int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
-
-int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag = TDB_REPLACE);
-
-int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf);
-
-int tdb_close(TDB_CONTEXT *tdb);
-
-TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
-
-TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
-
-int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *state);
-
-int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
-
-int tdb_lockall(TDB_CONTEXT *tdb);
-
-void tdb_unlockall(TDB_CONTEXT *tdb);
-
-/* Low level locking functions: use with care */
-
-int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key);
-
-int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key);
-
-/* Debug functions. Not used in production. */
-
-void tdb_dump_all(TDB_CONTEXT *tdb);
-
-int tdb_printfreelist(TDB_CONTEXT *tdb);
diff --git a/source/lib/tdb/tdb.i b/source/lib/tdb/tdb.i
new file mode 100644
index 00000000000..3d8b697732f
--- /dev/null
+++ b/source/lib/tdb/tdb.i
@@ -0,0 +1,323 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Swig interface to tdb.
+
+ Copyright (C) 2004-2006 Tim Potter <tpot@samba.org>
+ Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
+
+ ** NOTE! The following LGPL license applies to the tdb
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+%define DOCSTRING
+"TDB is a simple key-value database similar to GDBM that supports multiple writers."
+%enddef
+
+%module(docstring=DOCSTRING) tdb
+
+%{
+
+/* This symbol is used in both includes.h and Python.h which causes an
+ annoying compiler warning. */
+
+#ifdef HAVE_FSTAT
+#undef HAVE_FSTAT
+#endif
+
+/* Include tdb headers */
+#include <stdint.h>
+#include <signal.h>
+#include <tdb.h>
+#include <fcntl.h>
+
+typedef TDB_CONTEXT tdb;
+%}
+
+/* The tdb functions will crash if a NULL tdb context is passed */
+
+%import exception.i
+%import stdint.i
+
+%typemap(check,noblock=1) TDB_CONTEXT* {
+ if ($1 == NULL)
+ SWIG_exception(SWIG_ValueError,
+ "tdb context must be non-NULL");
+}
+
+/* In and out typemaps for the TDB_DATA structure. This is converted to
+ and from the Python string type which can contain arbitrary binary
+ data.. */
+
+%typemap(in,noblock=1) TDB_DATA {
+ if ($input == Py_None) {
+ $1.dsize = 0;
+ $1.dptr = NULL;
+ } else if (!PyString_Check($input)) {
+ PyErr_SetString(PyExc_TypeError, "string arg expected");
+ return NULL;
+ } else {
+ $1.dsize = PyString_Size($input);
+ $1.dptr = (uint8_t *)PyString_AsString($input);
+ }
+}
+
+%typemap(out,noblock=1) TDB_DATA {
+ if ($1.dptr == NULL && $1.dsize == 0) {
+ $result = Py_None;
+ } else {
+ $result = PyString_FromStringAndSize((const char *)$1.dptr, $1.dsize);
+ free($1.dptr);
+ }
+}
+
+/* Treat a mode_t as an unsigned integer */
+typedef int mode_t;
+
+/* flags to tdb_store() */
+%constant int REPLACE = TDB_REPLACE;
+%constant int INSERT = TDB_INSERT;
+%constant int MODIFY = TDB_MODIFY;
+
+/* flags for tdb_open() */
+%constant int DEFAULT = TDB_DEFAULT;
+%constant int CLEAR_IF_FIRST = TDB_CLEAR_IF_FIRST;
+%constant int INTERNAL = TDB_INTERNAL;
+%constant int NOLOCK = TDB_NOLOCK;
+%constant int NOMMAP = TDB_NOMMAP;
+%constant int CONVERT = TDB_CONVERT;
+%constant int BIGENDIAN = TDB_BIGENDIAN;
+
+enum TDB_ERROR {
+ TDB_SUCCESS=0,
+ TDB_ERR_CORRUPT,
+ TDB_ERR_IO,
+ TDB_ERR_LOCK,
+ TDB_ERR_OOM,
+ TDB_ERR_EXISTS,
+ TDB_ERR_NOLOCK,
+ TDB_ERR_LOCK_TIMEOUT,
+ TDB_ERR_NOEXIST,
+ TDB_ERR_EINVAL,
+ TDB_ERR_RDONLY
+};
+
+%rename(lock_all) tdb_context::lockall;
+%rename(unlock_all) tdb_context::unlockall;
+
+%rename(read_lock_all) tdb_context::lockall_read;
+%rename(read_unlock_all) tdb_context::unlockall_read;
+
+%typemap(default,noblock=1) int tdb_flags {
+ $1 = TDB_DEFAULT;
+}
+
+%typemap(default,noblock=1) int flags {
+ $1 = O_RDWR;
+}
+
+%typemap(default,noblock=1) int hash_size {
+ $1 = 0;
+}
+
+%typemap(default,noblock=1) mode_t mode {
+ $1 = 0600;
+}
+
+%typemap(default,noblock=1) int flag {
+ $1 = TDB_REPLACE;
+}
+
+%rename(Tdb) tdb_context;
+%feature("docstring") tdb_context "A TDB file.";
+%typemap(out,noblock=1) tdb * {
+ /* Throw an IOError exception from errno if tdb_open() returns NULL */
+ if ($1 == NULL) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ SWIG_fail;
+ }
+ $result = SWIG_NewPointerObj($1, $1_descriptor, 0);
+}
+
+typedef struct tdb_context {
+ %extend {
+ %feature("docstring") tdb "S.__init__(name,hash_size=0,tdb_flags=TDB_DEFAULT,flags=O_RDWR,mode=0600)\n"
+ "Open a TDB file.";
+ tdb(const char *name, int hash_size, int tdb_flags, int flags, mode_t mode) {
+ return tdb_open(name, hash_size, tdb_flags, flags, mode);
+ }
+ %feature("docstring") error "S.error() -> int\n"
+ "Find last error number returned by oper