r26583: Throw a proper exception in the python code when tdb_open() fails, fix indent...
authorJelmer Vernooij <jelmer@samba.org>
Mon, 24 Dec 2007 17:02:32 +0000 (11:02 -0600)
committerStefan Metzmacher <metze@samba.org>
Wed, 26 Dec 2007 17:57:03 +0000 (11:57 -0600)
source/lib/tdb/python/tests/simple.py
source/lib/tdb/tdb.i
source/lib/tdb/tdb_wrap.c
source/pidl/lib/Parse/Pidl/Samba4/SWIG.pm

index 4600f02f1430ce50ce161766abecc7fe88f56ffc..0e0ef0251e1228a68c62d91f9def16e8a6a1eca7 100644 (file)
@@ -10,6 +10,12 @@ import tdb
 from unittest import TestCase
 import os
 
 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()
 class SimpleTdbTests(TestCase):
     def setUp(self):
         super(SimpleTdbTests, self).setUp()
index 5bb6506d93e6233c0c0cba8c6f3e025c863a043a..41eaf772022f79594ec0fea8c52eaf0e43ac7c22 100644 (file)
@@ -108,7 +108,6 @@ enum TDB_ERROR {
      TDB_ERR_RDONLY
 };
 
      TDB_ERR_RDONLY
 };
 
-%rename(Tdb) tdb;
 %rename(lock_all) tdb_context::lockall;
 %rename(unlock_all) tdb_context::unlockall;
 
 %rename(lock_all) tdb_context::lockall;
 %rename(unlock_all) tdb_context::unlockall;
 
@@ -135,23 +134,20 @@ enum TDB_ERROR {
     $1 = TDB_REPLACE;
 }
 
     $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 {
 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); }
         }
         enum TDB_ERROR error();
         ~tdb() { tdb_close($self); }
index 1ba7481af08ab822dedd8c62bc9fe3dd7fab3acb..a58442b521b0cdc7561d163a11e74defcbf1453f 100644 (file)
@@ -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){
 }
 
 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); }
 
         }
 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);
     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:
   if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
   return resultobj;
 fail:
index 58b52df8d373a4a612096db0f620be3083a37143..14424cf26042e68e5d757875c239bff21dcfd09a 100644 (file)
@@ -105,7 +105,7 @@ sub ParseInterface($$)
                pidl "";
                pidl "status = dcerpc_$fn->{NAME}(\$self->pipe, mem_ctx, &r);";
                pidl "if (NT_STATUS_IS_ERR(status)) {";
                pidl "";
                pidl "status = dcerpc_$fn->{NAME}(\$self->pipe, mem_ctx, &r);";
                pidl "if (NT_STATUS_IS_ERR(status)) {";
-               pidl "\treturn status;";
+               indent; pidl "return status;"; deindent;
                pidl "}";
                pidl "";
                pidl "/* Set out arguments */";
                pidl "}";
                pidl "";
                pidl "/* Set out arguments */";