talloc: add _pytalloc_get_ptr/_pytalloc_get_mem_ctx helper functions
authorAndrew Bartlett <abartlet@samba.org>
Mon, 22 Feb 2016 01:29:15 +0000 (14:29 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 8 Mar 2016 00:58:26 +0000 (01:58 +0100)
This allows us to check which type is involved, and dereference
that type correctly

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/talloc/pytalloc.h
lib/talloc/pytalloc_util.c
lib/talloc/test_pytalloc.c
lib/talloc/wscript

index 608328e6aca36336b38a5ce6b6a742f1a02facfd..dc237941357919f3b9d57f69eb453a45219ecda9 100644 (file)
@@ -42,8 +42,10 @@ int pytalloc_Check(PyObject *);
  * when talloc_get_type() returns NULL. */
 #define pytalloc_get_type(py_obj, type) (talloc_get_type(pytalloc_get_ptr(py_obj), type))
 
-#define pytalloc_get_ptr(py_obj) (((pytalloc_Object *)py_obj)->ptr)
-#define pytalloc_get_mem_ctx(py_obj)  ((pytalloc_Object *)py_obj)->talloc_ctx
+void *_pytalloc_get_ptr(PyObject *py_obj);
+#define pytalloc_get_ptr(py_obj) _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))
 
 PyObject *pytalloc_steal_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
 PyObject *pytalloc_steal(PyTypeObject *py_type, void *ptr);
index 0af7c054507eab6e6a5ac8311c05d5a0f2d3ac27..484a5266553b459730134ed8e49f8389823eb1f9 100644 (file)
@@ -120,3 +120,13 @@ _PUBLIC_ int pytalloc_Check(PyObject *obj)
 
        return PyObject_TypeCheck(obj, tp);
 }
+
+_PUBLIC_ void *_pytalloc_get_ptr(PyObject *py_obj)
+{
+       return ((pytalloc_Object *)py_obj)->ptr;
+}
+
+_PUBLIC_ TALLOC_CTX *_pytalloc_get_mem_ctx(PyObject *py_obj)
+{
+       return ((pytalloc_Object *)py_obj)->talloc_ctx;
+}
index f66b4e59b524bd04e97ce6ebe511a6d560351e7d..0097cda8cf3282f30161c3b65dea89ee5011e572 100644 (file)
@@ -43,13 +43,13 @@ static PyObject *testpytalloc_get_object_type(PyObject *mod) {
 }
 
 static PyObject *testpytalloc_reference(PyObject *mod, PyObject *args) {
-       pytalloc_Object *source = NULL;
+       PyObject *source = NULL;
        void *ptr;
 
        if (!PyArg_ParseTuple(args, "O!", pytalloc_GetObjectType(), &source))
                return NULL;
 
-       ptr = source->ptr;
+       ptr = pytalloc_get_ptr(source);
        return pytalloc_reference_ex(pytalloc_GetObjectType(), ptr, ptr);
 }
 
index bcce4c5d9ff05617bd70938f56dc17f01c1440df..fe689c794739fb84a53c41f36d885b27b3d8ee9e 100644 (file)
@@ -133,7 +133,7 @@ def build(bld):
                 vnum=VERSION,
                 hide_symbols=True,
                 abi_directory='ABI',
-                abi_match='pytalloc_*',
+                abi_match='pytalloc_* _pytalloc_*',
                 private_library=private_library,
                 public_headers=('' if private_library else 'pytalloc.h'),
                 pc_files='pytalloc-util.pc'