Author: jelmer Date: 2007-12-24 11:02:32 +0000 (Mon, 24 Dec 2007) New Revision: 26583
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26583 Log: Throw a proper exception in the python code when tdb_open() fails, fix indentation in generated SWIG code from pidl. Modified: branches/SAMBA_4_0/ branches/SAMBA_4_0/source/lib/tdb/python/tests/simple.py branches/SAMBA_4_0/source/lib/tdb/tdb.i branches/SAMBA_4_0/source/lib/tdb/tdb_wrap.c branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/SWIG.pm Changeset: Property changes on: branches/SAMBA_4_0 ___________________________________________________________________ Name: bzr:revision-info ...skipped... Name: bzr:revision-id:v3-trunk0 ...skipped... Modified: branches/SAMBA_4_0/source/lib/tdb/python/tests/simple.py =================================================================== --- branches/SAMBA_4_0/source/lib/tdb/python/tests/simple.py 2007-12-24 01:55:09 UTC (rev 26582) +++ branches/SAMBA_4_0/source/lib/tdb/python/tests/simple.py 2007-12-24 11:02:32 UTC (rev 26583) @@ -10,6 +10,12 @@ 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() Modified: branches/SAMBA_4_0/source/lib/tdb/tdb.i =================================================================== --- branches/SAMBA_4_0/source/lib/tdb/tdb.i 2007-12-24 01:55:09 UTC (rev 26582) +++ branches/SAMBA_4_0/source/lib/tdb/tdb.i 2007-12-24 11:02:32 UTC (rev 26583) @@ -108,7 +108,6 @@ TDB_ERR_RDONLY }; -%rename(Tdb) tdb; %rename(lock_all) tdb_context::lockall; %rename(unlock_all) tdb_context::unlockall; @@ -135,23 +134,20 @@ $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); } Modified: branches/SAMBA_4_0/source/lib/tdb/tdb_wrap.c =================================================================== --- branches/SAMBA_4_0/source/lib/tdb/tdb_wrap.c 2007-12-24 01:55:09 UTC (rev 26582) +++ branches/SAMBA_4_0/source/lib/tdb/tdb_wrap.c 2007-12-24 11:02:32 UTC (rev 26583) @@ -2748,17 +2748,7 @@ } 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 @@ 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: Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/SWIG.pm =================================================================== --- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/SWIG.pm 2007-12-24 01:55:09 UTC (rev 26582) +++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/SWIG.pm 2007-12-24 11:02:32 UTC (rev 26583) @@ -105,7 +105,7 @@ 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 */";
