]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pyldb: add pyldb_check_type()
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 3 May 2018 00:10:21 +0000 (12:10 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Wed, 10 Jul 2019 04:32:13 +0000 (04:32 +0000)
This will be used by pyldb_Ldb_AsLdbContext().

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
lib/ldb/pyldb.h
lib/ldb/pyldb_util.c

index 4fc89ec48142ee13941fedd66004bf4fa35533f6..dbe1d0fdb9e26cc05edf26eb6e72f1f6590b2946 100644 (file)
@@ -46,6 +46,8 @@ PyObject *pyldb_Dn_FromDn(struct ldb_dn *);
 bool pyldb_Object_AsDn(TALLOC_CTX *mem_ctx, PyObject *object, struct ldb_context *ldb_ctx, struct ldb_dn **dn);
 #define pyldb_Dn_AsDn(pyobj) ((PyLdbDnObject *)pyobj)->dn
 
+bool pyldb_check_type(PyObject *obj, const char *type_name);
+
 typedef struct {
        PyObject_HEAD
        TALLOC_CTX *mem_ctx;
index f8d0664f1e70415629cc6361d042341ce4d4ed24..a1e3233e6ba408c0d3d7dba762cd06dd0b9da71e 100644 (file)
@@ -48,6 +48,17 @@ static PyTypeObject * PyLdb_GetPyType(const char *typename)
        return (PyTypeObject*)py_obj;
 }
 
+bool pyldb_check_type(PyObject *obj, const char *typename)
+{
+       bool ok = false;
+       PyTypeObject *type = PyLdb_GetPyType(typename);
+       if (type != NULL) {
+               ok = PyObject_TypeCheck(obj, type);
+               Py_DECREF(type);
+       }
+       return ok;
+}
+
 /**
  * Obtain a ldb DN from a Python object.
  *