From aa0a06f13c44e0eca0b3f2f0c34f0f7995b87159 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 23 Dec 2007 19:19:41 -0600 Subject: r26570: - Trim size of the swig-generated Python bindings by removing a bunch of {}'s. - Start working on Python equivalents for various EJS tests. - Fix regression in argument order for reg_diff_apply() in EJS bindings. (This used to be commit c550c03372cb260b78f6a6c132e70571bc4cb852) --- source4/lib/ldb/ldb.i | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 1ed1b45eaf..7c8241ba54 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -67,13 +67,13 @@ typedef int ldb_error; /* The ldb functions will crash if a NULL ldb context is passed so catch this before it happens. */ -%typemap(check) struct ldb_context* { +%typemap(check,noblock=1) struct ldb_context* { if ($1 == NULL) SWIG_exception(SWIG_ValueError, "ldb context must be non-NULL"); } -%typemap(check) ldb_msg * { +%typemap(check,noblock=1) ldb_msg * { if ($1 == NULL) SWIG_exception(SWIG_ValueError, "Message can not be None"); @@ -83,7 +83,7 @@ typedef int ldb_error; * Wrap struct ldb_val */ -%typemap(in) struct ldb_val *INPUT (struct ldb_val temp) { +%typemap(in,noblock=1) struct ldb_val *INPUT (struct ldb_val temp) { $1 = &temp; if (!PyString_Check($input)) { PyErr_SetString(PyExc_TypeError, "string arg expected"); @@ -93,7 +93,7 @@ typedef int ldb_error; $1->data = PyString_AsString($input); } -%typemap(out) struct ldb_val { +%typemap(out,noblock=1) struct ldb_val { $result = PyString_FromStringAndSize((const char *)$1.data, $1.length); } @@ -101,7 +101,7 @@ typedef int ldb_error; * Wrap struct ldb_result */ -%typemap(in, numinputs=0) struct ldb_result **OUT (struct ldb_result *temp_ldb_result) { +%typemap(in,noblock=1,numinputs=0) struct ldb_result **OUT (struct ldb_result *temp_ldb_result) { $1 = &temp_ldb_result; } @@ -115,7 +115,7 @@ typedef int ldb_error; } } -%typemap(in, numinputs=1) const char * const *attrs { +%typemap(in,noblock=1,numinputs=1) const char * const *attrs { if ($input == Py_None) { $1 = NULL; } else if (PySequence_Check($input)) { @@ -196,12 +196,16 @@ fail: int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, struct ldb_context *ldb, ldb_dn **dn) { + int ret; + struct ldb_dn *odn; if (ldb != NULL && PyString_Check(object)) { *dn = ldb_dn_new(mem_ctx, ldb, PyString_AsString(object)); return 0; } - return SWIG_ConvertPtr(object, (void **)dn, SWIGTYPE_p_ldb_dn, + ret = SWIG_ConvertPtr(object, (void **)&odn, SWIGTYPE_p_ldb_dn, SWIG_POINTER_EXCEPTION); + *dn = ldb_dn_copy(mem_ctx, odn); + return ret; } ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags, @@ -277,6 +281,15 @@ typedef struct ldb_message_element { ~ldb_msg_element() { talloc_free($self); } int compare(ldb_msg_element *); } + %pythoncode { + def __eq__(self, other): + if (isinstance(other, str) and + len(set(self)) == 1 and + set(self).pop() == other): + return True + return self.__cmp__(other) == 0 + + } } ldb_msg_element; /* ldb_message */ @@ -427,7 +440,7 @@ PyObject *PyExc_LdbError; */ -%typemap(out) ldb_error { +%typemap(out,noblock=1) ldb_error { if ($1 != LDB_SUCCESS) { PyErr_SetObject(PyExc_LdbError, Py_BuildValue("(i,s)", $1, ldb_strerror($1))); SWIG_fail; @@ -436,6 +449,17 @@ PyObject *PyExc_LdbError; }; %rename(Ldb) ldb_context; + +%typemap(in,noblock=1) struct ldb_dn * { + if (ldb_dn_from_pyobject(NULL, $input, arg1, &$1) != 0) { + SWIG_fail; + } +}; + +%typemap(freearg,noblock=1) struct ldb_dn * { + talloc_free($1); +}; + /* Top-level ldb operations */ typedef struct ldb_context { %extend { @@ -554,6 +578,9 @@ fail: } } ldb; +%typemap(in,noblock=1) struct ldb_dn *; +%typemap(freearg,noblock=1) struct ldb_dn *; + %nodefault ldb_message; %nodefault ldb_context; %nodefault Dn; -- cgit