summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-11-30 22:59:51 +0100
committerJelmer Vernooij <jelmer@samba.org>2010-12-01 01:48:24 +0100
commit36bdb3b9af271a8dcde23d40737117d7ce5daef8 (patch)
tree43cf8005d856717b8512643df24414ec4f2de9d1
parentdd0fbc47c798acfb003e37afbee5f0748e30ad1b (diff)
downloadsamba-36bdb3b9af271a8dcde23d40737117d7ce5daef8.tar.gz
samba-36bdb3b9af271a8dcde23d40737117d7ce5daef8.tar.bz2
samba-36bdb3b9af271a8dcde23d40737117d7ce5daef8.zip
pytalloc: Add convenience function for checking if something is a talloc
object.
-rw-r--r--lib/talloc/pytalloc.h2
-rw-r--r--lib/talloc/pytalloc_util.c27
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/talloc/pytalloc.h b/lib/talloc/pytalloc.h
index b17977a46c..be69c4d50c 100644
--- a/lib/talloc/pytalloc.h
+++ b/lib/talloc/pytalloc.h
@@ -32,6 +32,8 @@ typedef struct {
/* Deallocate a py_talloc_Object */
void py_talloc_dealloc(PyObject* self);
+int PyTalloc_Check(PyObject *);
+
/* Retrieve the pointer for a py_talloc_object. Like talloc_get_type()
* but for py_talloc_Objects. */
diff --git a/lib/talloc/pytalloc_util.c b/lib/talloc/pytalloc_util.c
index d5ef919bb2..c485cd1ca3 100644
--- a/lib/talloc/pytalloc_util.c
+++ b/lib/talloc/pytalloc_util.c
@@ -23,6 +23,26 @@
#include "pytalloc.h"
#include <assert.h>
+static PyTypeObject *Get_TallocType(void)
+{
+ static PyTypeObject *type = NULL;
+ PyObject *mod;
+
+ if (type != NULL) {
+ return type;
+ }
+
+ mod = PyImport_ImportModule("talloc");
+ if (mod == NULL) {
+ return NULL;
+ }
+
+ type = (PyTypeObject *)PyObject_GetAttrString(mod, "Object");
+ Py_DECREF(mod);
+
+ return type;
+}
+
/**
* Simple dealloc for talloc-wrapping PyObjects
*/
@@ -133,3 +153,10 @@ PyObject *PyString_FromString_check_null(const char *ptr)
}
return PyString_FromString(ptr);
}
+
+int PyTalloc_Check(PyObject *obj)
+{
+ PyTypeObject *tp = Get_TallocType();
+
+ return PyObject_TypeCheck(obj, tp);
+}