From 3023afce68684b5c256c1951adb62f255e00c7bc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 Nov 2007 14:26:16 +0100 Subject: r26112: Do proper error checking in __contains__. (This used to be commit b67cc409fa5aa931b0847b7d3bdd2edf72daf88d) --- source4/lib/ldb/ldb.i | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'source4') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index b37082af38..3b7a949fb7 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -29,8 +29,6 @@ %{ -/* Include headers */ - #include #include #include "talloc.h" @@ -80,10 +78,6 @@ typedef int ldb_error; "Message can not be None"); } -/* - * Wrap a small bit of talloc - */ - /* * Wrap struct ldb_val */ @@ -133,7 +127,6 @@ typedef int ldb_error; //talloc_free($1); } - /* * Wrap struct ldb_result */ @@ -413,8 +406,8 @@ static void py_ldb_debug(void *context, enum ldb_debug_level level, const char * %typemap(in,numinputs=1) (void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), void *context) { $1 = py_ldb_debug; - /* FIXME: Should be decreased somewhere as well. Perhaps register a destructor and - tie it to the ldb context ? */ + /* FIXME: Should be decreased somewhere as well. Perhaps register a + destructor and tie it to the ldb context ? */ Py_INCREF($input); $2 = $input; } @@ -518,16 +511,13 @@ fail: ldb_error transaction_cancel(); #ifdef SWIGPYTHON - bool __contains__(ldb_dn *dn) + %typemap(in,numinputs=0) struct ldb_result **result_as_bool (struct ldb_result *tmp) { $1 = &tmp; } + %typemap(argout) struct ldb_result **result_as_bool { $result = ((*$1)->count > 0)?Py_True:Py_False; } + %typemap(freearg) struct ldb_result **result_as_bool { talloc_free(*$1); } + ldb_error __contains__(ldb_dn *dn, struct ldb_result **result_as_bool) { - struct ldb_result *result; - - int ret = ldb_search($self, dn, LDB_SCOPE_BASE, NULL, NULL, - &result); - - /* FIXME: Check ret and set exception if necessary */ - - return result->count > 0; + return ldb_search($self, dn, LDB_SCOPE_BASE, NULL, NULL, + result_as_bool); } PyObject *parse_ldif(const char *s) -- cgit