summaryrefslogtreecommitdiff
path: root/source4/lib/tdb
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-12-24 11:02:32 -0600
committerStefan Metzmacher <metze@samba.org>2007-12-26 11:57:03 -0600
commit9faf93c7b0e00edcdc3f535ea69fc2c1bb6eeeb3 (patch)
tree53b0990a32cfb77d988318e9704b8e34833e116a /source4/lib/tdb
parent5e574b2b940bf4d7e040409c6a7ceba14eece798 (diff)
downloadsamba-9faf93c7b0e00edcdc3f535ea69fc2c1bb6eeeb3.tar.gz
samba-9faf93c7b0e00edcdc3f535ea69fc2c1bb6eeeb3.tar.bz2
samba-9faf93c7b0e00edcdc3f535ea69fc2c1bb6eeeb3.zip
r26583: Throw a proper exception in the python code when tdb_open() fails, fix indentation in generated SWIG code from pidl.
(This used to be commit 4ff8f4e370d30bf6b0b2f548bca14a9b7e1317f6)
Diffstat (limited to 'source4/lib/tdb')
-rw-r--r--source4/lib/tdb/python/tests/simple.py6
-rw-r--r--source4/lib/tdb/tdb.i28
-rw-r--r--source4/lib/tdb/tdb_wrap.c19
3 files changed, 25 insertions, 28 deletions
diff --git a/source4/lib/tdb/python/tests/simple.py b/source4/lib/tdb/python/tests/simple.py
index 4600f02f14..0e0ef0251e 100644
--- a/source4/lib/tdb/python/tests/simple.py
+++ b/source4/lib/tdb/python/tests/simple.py
@@ -10,6 +10,12 @@ import tdb
from unittest import TestCase
import os
+
+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()
diff --git a/source4/lib/tdb/tdb.i b/source4/lib/tdb/tdb.i
index 5bb6506d93..41eaf77202 100644
--- a/source4/lib/tdb/tdb.i
+++ b/source4/lib/tdb/tdb.i
@@ -108,7 +108,6 @@ enum TDB_ERROR {
TDB_ERR_RDONLY
};
-%rename(Tdb) tdb;
%rename(lock_all) tdb_context::lockall;
%rename(unlock_all) tdb_context::unlockall;
@@ -135,23 +134,20 @@ enum TDB_ERROR {
$1 = TDB_REPLACE;
}
+%rename(Tdb) tdb;
+%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 {
- tdb(const char *name, int hash_size,
- int tdb_flags,
- int open_flags, mode_t mode)
- {
- tdb *ret = tdb_open(name, hash_size, tdb_flags, open_flags, mode);
-
- /* Throw an IOError exception from errno if tdb_open() returns
- NULL */
- if (ret == NULL) {
- PyErr_SetFromErrno(PyExc_IOError);
- SWIG_fail;
- }
-
-fail:
- return ret;
+ tdb(const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode) {
+ return tdb_open(name, hash_size, tdb_flags, open_flags, mode);
}
enum TDB_ERROR error();
~tdb() { tdb_close($self); }
diff --git a/source4/lib/tdb/tdb_wrap.c b/source4/lib/tdb/tdb_wrap.c
index 1ba7481af0..a58442b521 100644
--- a/source4/lib/tdb/tdb_wrap.c
+++ b/source4/lib/tdb/tdb_wrap.c
@@ -2748,17 +2748,7 @@ SWIG_AsVal_int (PyObject * obj, int *val)
}
SWIGINTERN tdb *new_tdb(char const *name,int hash_size,int tdb_flags,int open_flags,mode_t mode){
- tdb *ret = tdb_open(name, hash_size, tdb_flags, open_flags, mode);
-
- /* Throw an IOError exception from errno if tdb_open() returns
- NULL */
- if (ret == NULL) {
- PyErr_SetFromErrno(PyExc_IOError);
- SWIG_fail;
- }
-
-fail:
- return ret;
+ return tdb_open(name, hash_size, tdb_flags, open_flags, mode);
}
SWIGINTERN void delete_tdb(tdb *self){ tdb_close(self); }
@@ -2870,7 +2860,12 @@ SWIGINTERN PyObject *_wrap_new_Tdb(PyObject *SWIGUNUSEDPARM(self), PyObject *arg
arg5 = (mode_t)(val5);
}
result = (tdb *)new_tdb((char const *)arg1,arg2,arg3,arg4,arg5);
- resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_tdb_context, SWIG_POINTER_OWN | 0 );
+ /* Throw an IOError exception from errno if tdb_open() returns NULL */
+ if (result == NULL) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ SWIG_fail;
+ }
+ resultobj = SWIG_NewPointerObj(result, SWIGTYPE_p_tdb_context, 0);
if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
return resultobj;
fail: