diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/talloc/pytalloc.h | 2 | ||||
-rw-r--r-- | lib/talloc/pytalloc_util.c | 27 |
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); +} |