summaryrefslogtreecommitdiff
path: root/lib/talloc
diff options
context:
space:
mode:
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>2019-07-09 08:59:19 +0000
committerAndrew Bartlett <abartlet@samba.org>2019-07-22 22:20:25 +0000
commit4496e073cbd0f78bcaa2cf340336e1a14bd6e8e6 (patch)
tree212a4f16a2d9ef1b09175d9c50de9f8792e623e0 /lib/talloc
parent3383390b4b82e49865792b839af1e8fb798113ca (diff)
downloadsamba-4496e073cbd0f78bcaa2cf340336e1a14bd6e8e6.tar.gz
talloc: add pytalloc_get_name() helper
In several places we go talloc_get_name(pytalloc_get_ptr(py_obj)) which is a certain NULL derefernce if py_obj is not a talloc object. This is a helper function that chooses to say "non-talloc object" rather than crash. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib/talloc')
-rw-r--r--lib/talloc/pytalloc.h4
-rw-r--r--lib/talloc/pytalloc_util.c9
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/talloc/pytalloc.h b/lib/talloc/pytalloc.h
index 7db6c33cf01..8ab1e16fe47 100644
--- a/lib/talloc/pytalloc.h
+++ b/lib/talloc/pytalloc.h
@@ -54,6 +54,10 @@ void *_pytalloc_get_ptr(PyObject *py_obj);
TALLOC_CTX *_pytalloc_get_mem_ctx(PyObject *py_obj);
#define pytalloc_get_mem_ctx(py_obj) _pytalloc_get_mem_ctx((PyObject *)(py_obj))
+const char *_pytalloc_get_name(PyObject *py_obj);
+#define pytalloc_get_name(py_obj) _pytalloc_get_name((PyObject *)(py_obj))
+
+
PyObject *pytalloc_steal_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
PyObject *pytalloc_steal(PyTypeObject *py_type, void *ptr);
PyObject *pytalloc_reference_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
diff --git a/lib/talloc/pytalloc_util.c b/lib/talloc/pytalloc_util.c
index 7a426d6c2a6..82b95e7f144 100644
--- a/lib/talloc/pytalloc_util.c
+++ b/lib/talloc/pytalloc_util.c
@@ -331,3 +331,12 @@ _PUBLIC_ int pytalloc_BaseObject_PyType_Ready(PyTypeObject *type)
return PyType_Ready(type);
}
+
+_PUBLIC_ const char *_pytalloc_get_name(PyObject *obj)
+{
+ void *ptr = pytalloc_get_ptr(obj);
+ if (ptr == NULL) {
+ return "non-talloc object";
+ }
+ return talloc_get_name(ptr);
+}